Bug 205516 - [Bindings] Add @@toStringTag to our iterator prototype object
Summary: [Bindings] Add @@toStringTag to our iterator prototype object
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Bindings (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://heycam.github.io/webidl/#es-i...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-12-20 13:28 PST by Chris Dumez
Modified: 2020-04-25 05:36 PDT (History)
8 users (show)

See Also:


Attachments
Patch (4.33 KB, patch)
2019-12-20 13:30 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.50 KB, patch)
2019-12-20 14:00 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.45 KB, patch)
2019-12-20 14:42 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2019-12-20 13:28:45 PST
Add @@ toStringTag to our iterator prototype object, as per:
- https://heycam.github.io/webidl/#es-iterator-prototype-object
Comment 1 Chris Dumez 2019-12-20 13:30:46 PST
Created attachment 386245 [details]
Patch
Comment 2 Darin Adler 2019-12-20 13:48:14 PST
Comment on attachment 386245 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=386245&action=review

> Source/WebCore/bindings/js/JSDOMIterator.h:267
> +    putDirectWithoutTransition(vm, vm.propertyNames->toStringTagSymbol, jsString(vm, info()->className), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);

I guess this is the same pattern that prototypes in the JavaScript runtime follow, so I guess it’s appropriately efficient.

Do we want to expose the actual values from className? No need to be indirect or hide that as an implementation detail?
Comment 3 Chris Dumez 2019-12-20 13:52:09 PST
(In reply to Darin Adler from comment #2)
> Comment on attachment 386245 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=386245&action=review
> 
> > Source/WebCore/bindings/js/JSDOMIterator.h:267
> > +    putDirectWithoutTransition(vm, vm.propertyNames->toStringTagSymbol, jsString(vm, info()->className), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
> 
> I guess this is the same pattern that prototypes in the JavaScript runtime
> follow, so I guess it’s appropriately efficient.
> 
> Do we want to expose the actual values from className? No need to be
> indirect or hide that as an implementation detail?

Using info()->className here is important to pass the tests. info()->className looks like "URLSearchParams Iterator" and is set in our generated bindings.

The spec says:
"""
The class string of an iterator prototype object for a given interface is the result of concatenating the identifier of the interface and the string " Iterator".
"""
Comment 4 Chris Dumez 2019-12-20 14:00:14 PST
Created attachment 386249 [details]
Patch
Comment 5 Darin Adler 2019-12-20 14:39:50 PST
Comment on attachment 386249 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=386249&action=review

> Source/WebCore/bindings/js/JSDOMIterator.h:268
> +    putDirectWithoutTransition(vm, vm.propertyNames->toStringTagSymbol, jsString(vm, info()->className), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);

JSC::PropertyAttribute perhaps?
Comment 6 Chris Dumez 2019-12-20 14:42:12 PST
Created attachment 386259 [details]
Patch
Comment 7 Darin Adler 2019-12-20 14:54:30 PST
Comment on attachment 386259 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=386259&action=review

> Source/WebCore/bindings/js/JSDOMIterator.h:268
> +    putDirectWithoutTransition(vm, vm.propertyNames->toStringTagSymbol, jsString(vm, info()->className), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly);

Might also have to be JSC::jsString -- not really sure.
Comment 8 WebKit Commit Bot 2019-12-20 17:04:35 PST
Comment on attachment 386259 [details]
Patch

Clearing flags on attachment: 386259

Committed r253855: <https://trac.webkit.org/changeset/253855>
Comment 9 WebKit Commit Bot 2019-12-20 17:04:37 PST
All reviewed patches have been landed.  Closing bug.
Comment 10 Radar WebKit Bug Importer 2019-12-20 17:05:30 PST
<rdar://problem/58129948>
Comment 11 Darin Adler 2019-12-21 17:11:21 PST
Comment on attachment 386259 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=386259&action=review

>> Source/WebCore/bindings/js/JSDOMIterator.h:268
>> +    putDirectWithoutTransition(vm, vm.propertyNames->toStringTagSymbol, jsString(vm, info()->className), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly);
> 
> Might also have to be JSC::jsString -- not really sure.

I figured out why it does not. The type of the first argument is JSC::VM&, and so argument-dependent lookup kicks in to search the JSC namespace for the function name.
Comment 12 Darin Adler 2019-12-21 17:17:59 PST
(In reply to Chris Dumez from comment #3)
> (In reply to Darin Adler from comment #2)
> > > Source/WebCore/bindings/js/JSDOMIterator.h:267
> > > +    putDirectWithoutTransition(vm, vm.propertyNames->toStringTagSymbol, jsString(vm, info()->className), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
> > 
> > I guess this is the same pattern that prototypes in the JavaScript runtime
> > follow, so I guess it’s appropriately efficient.
> > 
> > Do we want to expose the actual values from className? No need to be
> > indirect or hide that as an implementation detail?
> 
> Using info()->className here is important to pass the tests.
> info()->className looks like "URLSearchParams Iterator" and is set in our
> generated bindings.
> 
> The spec says:
> """
> The class string of an iterator prototype object for a given interface is
> the result of concatenating the identifier of the interface and the string "
> Iterator".
> """

Yes, I understand we need that name. What I wondered is whether it was OK to require that it be exactly equal to the className value from the info structure.

The four examples I found that have a className that is different from the toStringTagSymbol value are:

    AsyncGeneratorFunctionPrototype: className="AsyncGenerator", toStringTag="AsyncGeneratorFunction"
    JSDataViewPrototype: className="DataViewPrototype", toStringTag="DataView"
    JSModuleNamespaceObject: className="ModuleNamespaceObject", toStringTag="Module"
    JSPromisePrototype: className="PromisePrototype", toStringTag="Promise"

I was just wondering why this happens sometimes and why it shouldn't happen here. Maybe all four of those are just bugs.