Skip to content

Cannot redefine a property on vm's globalThis #47799

Closed
@domenic

Description

@domenic

Version

v20.0.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

vm

What steps will reproduce the bug?

const vm = require("vm");
const context = vm.createContext();

const window = vm.runInContext("this", context);

Object.defineProperty(window, "x", { value: "1", configurable: true });
Object.defineProperty(window, "x", { value: "2", configurable: true });

console.log(window.x);

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

Always

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

Outputs "2"

What do you see instead?

Outputs "1"

Additional information

This reproduces in every version I've tested back to v16.20.0.

This does not reproduce if you replace window in the above with context, i.e. it's specific to what happens when you pull out the inner globalThis value. (However, pulling out that value is crucial for jsdom's use cases.)

Metadata

Metadata

Assignees

Labels

vmIssues and PRs related to the vm subsystem.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions