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

Inconsistent Object.keys behaviour with EXTEND_PROTOTYPES=false #12482

Closed
xcambar opened this issue Oct 14, 2015 · 2 comments
Closed

Inconsistent Object.keys behaviour with EXTEND_PROTOTYPES=false #12482

xcambar opened this issue Oct 14, 2015 · 2 comments

Comments

@xcambar
Copy link
Contributor

xcambar commented Oct 14, 2015

Note: This behaviour only appears when prototype extension is disabled.

Object.keys([]) and Object.keys(Ember.A()) return different arrays.

  • Object.keys([]) returns an empty array
  • Object.keys(Ember.A()) returns a non empty array.

This is due to the Ember mixins being injected in the native array.
It looks like the keys added to the array are not declared non-enumerable.

Here's a jsbin: https://output.jsbin.com/futequ

When prototype extensions are enabled, in both cases, an empty array is returned.

@stefanpenner
Copy link
Member

this is currently expected behavior.

  1. Object.defineProperty (used to marks as non-enumerable) is extremely slow compared to a property
  2. Arrays can't be subclassed so in EXTEND_PROTOTYPES=false we currently must apply the custom methods to each and every array, not just a shared prototype. This and 1. result in it be prohibitively slow

Planned work to improve this situation, is #10899 but its quite a bit of work. Will eventually finish it up.

Although not ideal this isn't considered a bug. As such Im going to close this.

@xcambar
Copy link
Contributor Author

xcambar commented Oct 14, 2015

Thanks and good luck.

FWIW and for future readers, your comment led me to a good read on the methods (and respective caveats) of (trying to) extend Array.prototype:
http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/#dean_edwards_solution by @kangax.

tl;dr; hidden [[Class]] property (concat, etc... fail). Using __proto__ works but it's non-standard.

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