Skip to content

[JSC] getModuleNamespace() accepts a module that is not linked yet (tc39/ecma262#3114) - #846

Open
robobun wants to merge 2 commits into
mainfrom
robobun/0655b91f/get-module-namespace-assert
Open

robobun wants to merge 2 commits into
mainfrom
robobun/0655b91f/get-module-namespace-assert

Conversation

@robobun

@robobun robobun commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • A build with assertions aborts on a plain ES module graph: ASSERTION FAILED: cyclic->status() != CyclicModuleRecord::Status::New && cyclic->status() != CyclicModuleRecord::Status::Unlinked at runtime/AbstractModuleRecord.cpp(1204), in JSC::AbstractModuleRecord::getModuleNamespace. A build without assertions runs the graph.
  • In the graph, a.js and b.js import each other. a.js imports ns from b.js, and b.js has export * as ns from "./c.js". InitializeEnvironment of a.js asks for the namespace object of c.js before InnerModuleLinking visits c.js.

Fix

  • The assertion excludes only NEW. GetExportedNames and ResolveExport work for a module that is not linked, so the namespace object is correct.
  • ECMA-262 has the same assertion. Incorrect assert in GetModuleNamespace() tc39/ecma262#3114 tracks it as a bug of the specification, with the same graph.
  • Verified: JSTests/modules/namespace-export-of-module-not-linked-yet.js. The debug jsc of main aborts on it with exit code 134, and passes the other 149 files of JSTests/modules. With the change, 150 of 150 pass.

Background

Downsides

  • None found. The change is one ASSERT, so a build without assertions has the same code. Checked: JSTests/modules on a debug build with ASAN.
Notes

The graph (JSTests/modules/namespace-export-of-module-not-linked-yet*):

// main
import "./b.js";
import { read } from "./a.js";
// a.js
import { ns } from "./b.js";
export function read() { return Object.keys(ns) + ": " + ns.v; }
// b.js
import "./a.js";
export * as ns from "./c.js";
// c.js
export let v = "c";

read() returns v: c.

Who reaches it. A debug build of Bun aborts on this graph, and on a vm.SourceTextModule graph of the same shape. Release builds are not affected.

The specification. In tc39/ecma262#3114 a maintainer of the specification answers that the assertion can be relaxed, because GetExportedNames and ResolveExport support a module that is not linked.

A module can get the namespace object of a module that InnerModuleLinking
has not visited yet. One member of an import cycle imports `ns`. Another
member has `export * as ns from "./c.js"`. InitializeEnvironment of the
first member then calls GetModuleNamespace for c.js while c.js is UNLINKED.
The assertion at the start of getModuleNamespace() aborts a build with
assertions for that graph. A build without assertions runs it.

ECMA-262 has the same assertion. It is a known bug of the specification:
tc39/ecma262#3114. GetExportedNames and
ResolveExport work for a module that is not linked, so the assertion now
excludes only NEW.

@claude claude 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.

I reviewed this PR and didn't find any bugs. The change is a single debug-only ASSERT relaxation in the module linker, and since Source/JavaScriptCore is a CODEOWNERS path, a human look is still worthwhile.

What was reviewed:

  • The relaxed assertion in AbstractModuleRecord::getModuleNamespace() and the paths after it: both the prelinked fast path and the star-export walk only consult exportEntries()/starExportEntries(), which exist after parsing, so an Unlinked record is fine there.
  • JSModuleNamespaceObject construction only stores (localName, moduleRecord) resolutions and never touches moduleEnvironment(), so building the namespace before c.js is linked is safe; reads go through the environment lazily, and in the test graph c.js is linked and evaluated before read() runs.
  • The "host asks for a namespace before linking" and "null hostResolveImportedModule in the star walk" concerns were ruled out as unchanged release behavior: the diff alters no non-assert code.
  • The new test is picked up by modules.yaml (top-level modules/*.js) and follows the existing subdirectory-fixture pattern; no BUN-TEST-DIFFERENCES.md entry is needed since no upstream test is edited.
Extended reasoning...

The diff touches one ASSERT_ENABLED block in Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp, dropping the Unlinked-status half of the assertion at the top of getModuleNamespace(), plus a four-file regression test under JSTests/modules/ reproducing the import-cycle plus export * as ns from graph. It touches no security-sensitive surface and has no release-build behavioral change. The code after the assertion (prelinked resolution collection, star-export walk, JSModuleNamespaceObject constructor) was checked and does not depend on the module environment or link status. Not approved only because the changed file falls under the repository's CODEOWNERS entry for /Source/JavaScriptCore; the bug hunt exited on dry_streak with no findings.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Preview build of 91611e2: autobuild-preview-pr-846-91611e23

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ade15949-2a5d-4c29-89f7-e98e587c0c13
📥 Commits

Reviewing files that changed from the base of the PR and between 87ee10d and d096bb0.

📒 Files selected for processing: 5
  • JSTests/modules/namespace-export-of-module-not-linked-yet.js
  • JSTests/modules/namespace-export-of-module-not-linked-yet/a.js
  • JSTests/modules/namespace-export-of-module-not-linked-yet/b.js
  • JSTests/modules/namespace-export-of-module-not-linked-yet/c.js
  • Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp

Walkthrough

The runtime change allows getModuleNamespace to proceed when a cyclic module is Unlinked, while retaining the check against New. A new module test covers circular imports and checks that read() returns "v: c".

Changes

Cyclic Module Namespace Lookup

Layer / File(s) Summary
Circular-import regression test
JSTests/modules/namespace-export-of-module-not-linked-yet.js, JSTests/modules/namespace-export-of-module-not-linked-yet/*
The test builds a circular import graph, exports c.js as a namespace, and checks that read() returns "v: c".
Namespace lookup for unlinked cyclic modules
Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp
getModuleNamespace no longer asserts that the cyclic module status is not Unlinked. It still asserts that the status is not New.

Priority: Normal

Merge Risk: Minimal · up to d096b

The change is intended to support namespace lookup during cyclic module linking, and the supplied context identifies no concrete user-facing or runtime failure. No evidenced merge blocker remains.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the main change: allowing getModuleNamespace() to accept a module that is not linked yet.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description clearly explains the problem, fix, affected module graph, testing, and scope. It does not follow the repository template exactly because it lacks a standalone bug title, an associated …
Full details: Description check

Explanation

The description clearly explains the problem, fix, affected module graph, testing, and scope. It does not follow the repository template exactly because it lacks a standalone bug title, an associated Bugzilla URL, the “Reviewed by NOBODY” line, and a formal changed-file list. These omissions do not prevent understanding the change.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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