Skip to content

vm: Object.defineProperty doesn't work properly for globalThis #64008

@fabon-f

Description

@fabon-f

Version

26.3.0

Platform

Darwin hostname 25.5.0 Darwin Kernel Version 25.5.0: Mon Apr 27 20:38:00 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T8103 arm64

Subsystem

No response

What steps will reproduce the bug?

Run a script below

import { createContext, Script } from "node:vm";

const context = {};
createContext(context);
new Script(
    `globalThis.foo = 0; Object.defineProperty(globalThis, "foo", { enumerable: false });`,
).runInContext(context);

console.log(context.foo);

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

always

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

the script should print "0", because Object.defineProperty without value option should keep the original value:

globalThis.foo = 0;
Object.defineProperty(globalThis, "foo", { enumerable: false });
console.log(globalThis.foo); // 0

What do you see instead?

the script prints "undefined"

Additional information

The script works as intended in v26.2.0.

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