Skip to content

vm: let declaration no longer throws SyntaxError for non-configurable global property in vm context (regression in v26) #63715

@hai-x

Description

@hai-x

Version

v26.3.0

Platform

Darwin 24.6.0 Darwin Kernel Version 24.6.0: xnu-11417.140.69.705.2~1/RELEASE_ARM64_T6041 arm64 (macOS, Apple Silicon)

Subsystem

vm

What steps will reproduce the bug?

A let declaration that collides with a non-configurable property on a vm context's global object is no longer rejected with a SyntaxError. Save as repro.js and run with node repro.js:

const vm = require('vm');
const context = vm.createContext({});

// Define a non-configurable ("restricted") property on the context global.
vm.runInContext(
  "Object.defineProperty(this, 'foo', { value: 1, configurable: false });",
  context
);

// Per ECMA-262 GlobalDeclarationInstantiation step 3.d, a lexical
// declaration colliding with a restricted global property must throw.
try {
  vm.runInContext('let foo;', context);
  console.log('NO ERROR (let foo; was accepted)');
} catch (e) {
  console.log('THREW:', e.constructor.name, '-', e.message);
}

How often does it reproduce? Is there a required condition?

100% reproducible.

What is the expected behavior? Why is that the expected behavior?

let foo; should throw a SyntaxError, because foo is a non-configurable own property of the global object. v24.12.0 behaves correctly: THREW: SyntaxError - Identifier 'foo' has already been declared

What do you see instead?

On v26.3.0 the declaration is silently accepted: NO ERROR (let foo; was accepted)

Additional information

Found via the test262 language/global-code/script-decl-lex-restricted-global.js case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    vmIssues and PRs related to the vm subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions