Closed
Bug 1110332
Opened 10 years ago
Closed 10 years ago
Object.keys no longer seem to work with proxies properly
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: irakli, Unassigned)
Details
Here is a reproducible scenirio var proxy = new Proxy({}, { ownKeys() { return ["a", "b"] } }) Object.keys(proxy) // => [] Object.getOwnPropertyNames(proxy) // => ["a", "b"] I would expert `Object.keys` to return ["a", "b"] instead.
Comment 1•10 years ago
|
||
Welcome to the confusion engendered by "keys" having different meanings in different places in the ES spec. :( In the proxy trap and various other places it means "names of own properties" while in the legacy-ish Object.keys API it means "names of enumerable own properties". So per spec, Object.keys returns the result of doing EnumerableOwnNames() on the object. EnumerableOwnNames <http://people.mozilla.org/~jorendorff/es6-draft.html#sec-enumerableownnames> calls the object's [[OwnPropertyKeys]], which will invoke your "ownKeys" trap. Then it walks the resulting list and for each element calls [[GetOwnProperty]] and only returns things for which this returned something other than "undefined" and desc.[[Enumerable]] was true. Since you're not providing a "getOwnPropertyDescriptor" trap, your [[GetOwnProperty]] goes through to the target object, which doesn't have those properties, so [[GetOwnProperty]] returns undefined and the props are not added to the list returned by EnumerableOwnNames().
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•