Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get handler with Symbol #57

Open
soubok opened this issue Jul 17, 2015 · 6 comments
Open

get handler with Symbol #57

soubok opened this issue Jul 17, 2015 · 6 comments

Comments

@soubok
Copy link

soubok commented Jul 17, 2015

I fail to use the Proxy get handler with a ES6 Symbol as property name:

var Reflect = require('harmony-reflect');

var p = new Proxy(Object.create(null), {

    get: function(target, property) {

        return 'bar';
    }
});


console.log( p['foo'] );
console.log( p[Symbol('fooSym')] );
@tvcutsem
Copy link
Owner

Symbols are not supported by this shim, as they are not available in ES5.

Can you provide a little more info about your environment? Are you using a tool like babeljs to compile to ES5 or a runtime that already provides support for Symbols?

@soubok
Copy link
Author

soubok commented Jul 17, 2015

I am using iojs v2.3.4 (--harmony --harmony_arrow_functions --harmony_proxies) and I haven't tried babeljs yet but I don't see any information about proxies support on their web site.

@tvcutsem
Copy link
Owner

I'll try to replicate and see what the behavior is. If v8's Symbol implementation is incompatible with its Proxy implementation, there is little this shim can do. But perhaps the issue lies in my library code and can be fixed.

Babeljs indeed does not support proxies, but it does support Symbols. It could have been the case that you were using Babeljs Symbols, compiled down to ES5 and then using node or iojs --harmony_proxies to run that code. I'm not sure how Babeljs compiles symbols to ES5 but I suspect it would not lead to the desired semantics.

@zloirock
Copy link

I'm not sure how Babeljs compiles symbols to ES5

Babel uses core-js - setters in Object.prototype and wrappers for some methods.

@tvcutsem
Copy link
Owner

As I had expected, it seems V8's Symbols and built-in Proxies don't play well together:

I tested the following using iojs --harmony_proxies (iojs v2.3.0)

var p = Proxy.create({
  get: function(receiver, name) {
    console.log(typeof name);
    return name;
  },
  set: function(receiver, name, val) {
    console.log(typeof name);
  }
});

var s = Symbol("x");
p[s] = 42;
console.log(p[s]);

Note that this code doesn't even use this library but just uses the old pre-ES6 Proxy API directly.

The above code doesn't even trigger the Proxy get/set traps, and the last line just logs undefined. Seems like this is a V8 bug.

I'm not sure to what extent my shim can add support for Symbols if built-in Proxies don't work with them. For now, I'll note the incompatibility in the README.

Thanks for reporting.

@deian
Copy link

deian commented Nov 6, 2015

Not sure if folks are still interested in this, but I filed a v8 bug on this (https://code.google.com/p/v8/issues/detail?id=4537&thanks=4537&ts=1446787325)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants