After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 778718 - Lang.Class should include symbol properties
Lang.Class should include symbol properties
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
1.47.x
Other Linux
: Normal normal
: ---
Assigned To: Philip Chimento
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2017-02-15 21:44 UTC by Philip Chimento
Modified: 2017-02-26 21:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
lang: Copy symbol properties into class prototype (3.91 KB, patch)
2017-02-25 20:52 UTC, Philip Chimento
committed Details | Review

Description Philip Chimento 2017-02-15 21:44:07 UTC
I'm pretty sure the following should work:

    const Klass = new Lang.Class({
        Name: 'Klass',
        *[Symbol.iterator]() {
            yield* [1, 2, 3];
        },
    });
    let instance = new Klass();
    print([...instance]);

But instead, "TypeError: instance[Symbol.iterator] is not a function"

I think this is because Lang.copyProperties() does not copy symbol properties by default.
Comment 1 Philip Chimento 2017-02-25 20:52:26 UTC
Created attachment 346718 [details] [review]
lang: Copy symbol properties into class prototype

Now that our JS engine supports symbols, we need to make sure that our
class framework supports properties with symbol keys. Previously we
would copy properties from the object passed to Lang.Class (the "params
object") onto the class's prototype using Object.getOwnPropertyNames().
Now we need to use Object.getOwnPropertySymbols() as well, so that
properties and methods with symbol keys are copied.

One common use case might be making an object iterable by giving it a
Symbol.iterator method.
Comment 2 Cosimo Cecchi 2017-02-26 02:36:39 UTC
Review of attachment 346718 [details] [review]:

Thanks, looks good.
Comment 3 Philip Chimento 2017-02-26 21:54:42 UTC
Attachment 346718 [details] pushed as 74bf3bd - lang: Copy symbol properties into class prototype