-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Found in Node here and filed as a V8 bug here. It looks like Object.keys will throw an error when provided an uninitialized module namespace object while Object.getOwnPropertyNames won't.
Comments from the V8 issue:
so i was talking with ljharb about this and we came to a different conclusion about this behaviour.
Since Object.keys (and Reflect.ownKeys, for..in, all the things broken by this upgrade) don't actually expose the value, they shouldn't throw. basically everything that doesn't expose the value, or a getter/setter, should work. anything that's static and won't change after evaluation should be always accessible.
And
See https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects.
[[GetOwnProperty]] throws because [[Get]] throws:
Let value be ? O.[[Get]](P, O).
[[Get]] throws because GetBindingValue throws:
Return ? targetEnvRec.GetBindingValue(binding.[[BindingName]], true).
GetBindingValue throws because the binding, which exists, is still uninitialized:
https://tc39.github.io/ecma262/#sec-module-environment-records-getbindingvalue-n-s
The bug is that Object.keys should not error just as Object.getOwnPropertyNames does not error.
\cc @ljharb