Object.keys no longer seem to work with proxies properly

RESOLVED INVALID

Status

()

Core
JavaScript Engine
RESOLVED INVALID
3 years ago
3 years ago

People

(Reporter: irakli, Unassigned)

Tracking

Trunk
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

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.
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
Last Resolved: 3 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.