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

Rethink enumerability hack for symbols #7

Open
medikoo opened this issue Mar 24, 2015 · 4 comments
Open

Rethink enumerability hack for symbols #7

medikoo opened this issue Mar 24, 2015 · 4 comments
Assignees
Milestone

Comments

@medikoo
Copy link
Owner

medikoo commented Mar 24, 2015

Currently naturally set symbol properties (via e.g. x[symbol] = 'foo') are defined under the hood as not enumerable, so they're hidden from Object.keys and for in iterations.

This however has side effect of symbols not being copied as expected via Object.assign and incorrect value being returned for obj.propertyIsEnumerable(symbol).

Fix would be, to make them naturally enumerable (resign from Object.prototype hack), but update Object.keys shim within es5-ext project so it will filter eventual symbols created by polyfill. Additionally for .. in counterpart can be provided as well.

@medikoo medikoo self-assigned this Mar 24, 2015
@medikoo medikoo added this to the v2 milestone Mar 24, 2015
@medikoo medikoo changed the title Rethink enumerability hack of symbols Rethink enumerability hack for symbols Mar 24, 2015
@WebReflection
Copy link

FYI I've solved this in https://github.com/WebReflection/get-own-property-symbols

@WebReflection
Copy link

early comment, sorry.

You cannot make them enumerable because for/in will show them. symbols in ES5 make sense only if assigned as non enumerable, but other methods that deal with descriptors should be aware of the poly.

I've patched propertyIsEnumerable together with defineProperty and defineProperties and now my polyfill works well with Object.assign native or polyfilled.

You can still set non enumerable Symbols when you use defineProperty/ies

@medikoo
Copy link
Owner Author

medikoo commented Apr 21, 2015

@WebReflection thanks for comment.

Yes as for/in can't be patched, the way you propose, is the only way to get it right

@WebReflection
Copy link

forgot to mention that I obviously had to patch Object.getOwnPropertyDescriptor which will return true by default, unless the Symbol hasn't been assigned via defineProperty/ies as non enumerable.

It's a mess but it works :D

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

2 participants