tvcutsem / harmony-reflect

ES5 shim for ES6 Reflect and Proxy objects
http://www.ecma-international.org/ecma-262/6.0/#sec-reflection
Other
478 stars 48 forks source link

Warning instead of throwing a TypeError for getOwnPropertyNames deprecated trap #48

Closed ognjenb closed 9 years ago

ognjenb commented 9 years ago

Hello,

Currently lots of libs and browsers with Proxy object still call the getOwnPropertyNames method. It would be good for the shim to show a warning and call ownKeys instead of throwing an error, as currently it stops execution.

What do you think?

Thank you!

tvcutsem commented 9 years ago

Sounds reasonable, and should be backward-compat. I should be able to fix that in one of the coming days. Watch this space :)

ognjenb commented 9 years ago

Thank you! Temporary I created a fork for my package.json.

tvcutsem commented 9 years ago

I've been thinking more about this and I'm wondering how exactly it is that this trap can still be invoked when using this shim. Normally the only method that calls the getOwnPropertyNames trap would be Object.getOwnPropertyNames, but my shim patches that method to call ownKeys instead.

Can you provide an example scenario where you still run into this trap being called even when the harmony-reflect library is loaded?

ognjenb commented 9 years ago

Ok. So in my case, I am proxifying a simple object and then at some point persisting that proxy wrapped object using PouchDB's put method, which calls internally Object. getOwnPropertyNames as I see.

I created a simple example here: https://github.com/ognjenb/proxyPersistWithPouch

tvcutsem commented 9 years ago

I see. Thanks for providing the isolated test case. The issue is that external libraries, who are not using this shim, are using the unpatched versions of the Object.* methods and thus still using the old API.

Since the fix is easy enough and doesn't disrupt anything else, I'll just add the deprecation warning and fallback to ownKeys.

tvcutsem commented 9 years ago

Fixed in v1.2.1!

ognjenb commented 9 years ago

Thank you!