Getting object keys of an unevaluated module namespace throws a ReferenceError
Reported by
mic.bes...@gmail.com,
May 22
|
|
Issue descriptionVersion: 6.7, lkgr OS: Linux Architecture: x64 GitHub issue: https://github.com/nodejs/node/pull/19989#issuecomment-390900810 What steps will reproduce the problem? 1. Clone and build Node with V8 6.7: https://github.com/targos/node/tree/v8-6.7 2. Execute the following script: ``` const { Module } = require('vm'); (async () => { const m = new Module('export const a = 1; export var b = 2'); await m.link(() => 0); m.instantiate(); console.log(Object.keys(m.namespace)); // throws ReferenceError })(); ``` What is the expected output? It should log: [ 'a', 'b' ] What do you see instead? Object.keys(m.namespace) throws "ReferenceError: a is not defined" Please use labels and text to provide additional information. This issue is not present in V8 6.6.
,
May 24
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.
,
May 24
That sounds like a reasonable semantics to me but it's not what ECMAScript currently specifies. Like I said, Object.keys does [[GetOwnProperty]] (via EnumerableOwnPropertyNames) for each key. I suggest to file an issue in the ECMAScript github.
,
May 24
I don't think you need to throw on [[GetOwnProperty]] though. I can't find anything in the spec suggesting that you do.
,
May 24
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 |
|
►
Sign in to add a comment |
|
Comment 1 by neis@chromium.org
, May 23Owner: neis@chromium.org
Status: WontFix (was: Untriaged)