New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Starred by 2 users

Issue metadata

Status: WontFix
Owner:
Closed: May 23
Cc:
HW: ----
NextAction: ----
OS: Windows
Priority: ----
Type: ----



Sign in to add a comment

Getting object keys of an unevaluated module namespace throws a ReferenceError

Reported by mic.bes...@gmail.com, May 22

Issue description

Version: 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.
 
Labels: OS-Windows
Owner: neis@chromium.org
Status: WontFix (was: Untriaged)
This is the specified behavior. Object.keys does [[GetOwnProperty]], which throws for properties representing uninitialized variables.
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.
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.
I don't think you need to throw on [[GetOwnProperty]] though. I can't find
anything in the spec suggesting that you do.
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