Skip to content

fix(vm): preserve DONT_CONTEXTIFY global receiver identity - #176

Merged
steipete merged 1 commit into
mainfrom
fix/vm-dont-contextify-receiver
Oct 16, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/vm-dont-contextify-receiver

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown

What does this PR do?

Ports the DONT_CONTEXTIFY global fix from oven-sh#34623. Creating a VM context in this mode currently returns a wrapper, while top-level this uses the realm's global proxy. This breaks private-field branding used by jsdom: a field stamped on the returned context cannot be read through window.

Return the existing global proxy without attaching a sandbox, remove the wrapper, preserve that global during script evaluation, and accept it as a compileFunction parsing context. Reuse it in runInNewContext while retaining code-generation options. Ordinary contextified globals keep their sandbox behavior. The private compilation cache and its keys are unchanged; scripts continue linking against the target global on each evaluation.

Adds option-validation and forced private-cache hit tests, plus Node-oracle regression coverage for strict/sloppy scripts, indirect eval, Function, compileFunction, private fields, and shared scripts across contexts.

Related upstream work: oven-sh#34623, oven-sh#38316, oven-sh#45284, and oven-sh#45102. Thanks robobun for the original implementation.

How did you verify your code works?

  • Node 24 passes all five identity regression cases.
  • Stock Bun 1.4.3 fails all five identity cases and the standalone private-field reproducer.
  • Native Linux x64 release build: all eight new regression cases fail on the unpatched base; the patched VM/module suites pass 1,019, fail 0, with 9 existing skips and 61 TODOs across 17 files.
  • Forced private-cache identity matrix: passes with 16 cache hits; contexts retain distinct receivers and values.
  • Changed C++ files pass clang-format 23; the JavaScript module passes the repository lint rules. Two independent P2 reviews are scoped-clean.
  • macOS arm64: the verified PR CI artifact passes the standalone reproducer and the strict/sloppy identity/cache matrix locally, including 16 private-cache hits. Node 24 passes; stock Bun 1.4.3 and canary reproduce the original failure.
  • A fresh Linux release build of upstream main at f2405c382d43b89d91a2e7c90d9c5f53505a1e71 also reproduces the original failure.
  • The affected downstream extensions/team-reports/src/render/theme.test.ts changes from 6 failures to 6 passes on the same source checkout.
  • Linux x64 and Darwin arm64 build/test CI, formatting, linting, and security checks pass. The issue-finder workflow has its known missing-credential failure.

Port the real-global implementation from oven-sh#34623, originally by
robobun. Remove the wrapper that separated top-level this from the returned
context, and preserve parsing-context and code-generation behavior.

Cover private-field branding, strict/sloppy receivers, indirect eval,
Function, and compilation-cache reuse across distinct contexts.
@steipete
steipete marked this pull request as ready for review October 16, 2026 01:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T02:01:15.349147Z 5dfb1b4 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete merged commit 8abc03f into main Oct 16, 2026
9 of 10 checks passed
@steipete
steipete deleted the fix/vm-dont-contextify-receiver branch October 16, 2026 01:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dfb1b466b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/js/node/vm.ts
if (name !== undefined) validateString(name, "options.contextName");
if (origin !== undefined) validateString(origin, "options.contextOrigin");
let codeGeneration;
const contextCodeGeneration = options.contextCodeGeneration;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Node's repeated context-option getter reads

When options uses accessors or a Proxy, caching contextCodeGeneration here—and microtaskMode above—changes observable behavior. Node 24's getContextOptions rereads contextCodeGeneration for the presence check, validation, and destructuring; for example, a getter returning {}, {}, then { strings: false } makes Node disable eval, whereas this implementation configures the context from the first object and permits it. Read and validate these properties in Node's order rather than memoizing them.

AGENTS.md reference: AGENTS.md:L187-L191

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant