Repository navigation
Conversation
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.
There was a problem hiding this comment.
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.
|
Preview build of 91611e2: |
|
No actionable comments were generated in the recent review. ℹ️ Recent review info
WalkthroughThe runtime change allows ChangesCyclic Module Namespace Lookup
Priority: Merge Risk:
|
…module-namespace-assert
Problem
ASSERTION FAILED: cyclic->status() != CyclicModuleRecord::Status::New && cyclic->status() != CyclicModuleRecord::Status::Unlinkedatruntime/AbstractModuleRecord.cpp(1204), inJSC::AbstractModuleRecord::getModuleNamespace. A build without assertions runs the graph.a.jsandb.jsimport each other.a.jsimportsnsfromb.js, andb.jshasexport * as ns from "./c.js".InitializeEnvironmentofa.jsasks for the namespace object ofc.jsbeforeInnerModuleLinkingvisitsc.js.Fix
GetExportedNamesandResolveExportwork for a module that is not linked, so the namespace object is correct.JSTests/modules/namespace-export-of-module-not-linked-yet.js. The debugjscofmainaborts on it with exit code 134, and passes the other 149 files ofJSTests/modules. With the change, 150 of 150 pass.Background
InnerModuleLinkingwalks the graph depth first. A member of a cycle runsInitializeEnvironmentwhile its importer has requests that the walk did not visit yet.mainhas it atAbstractModuleRecord.cpp:802. This commit has noUSE(BUN_JSC_ADDITIONS), so it can go upstream as it is.Downsides
ASSERT, so a build without assertions has the same code. Checked:JSTests/moduleson a debug build with ASAN.Notes
The graph (
JSTests/modules/namespace-export-of-module-not-linked-yet*):read()returnsv: c.Who reaches it. A debug build of Bun aborts on this graph, and on a
vm.SourceTextModulegraph 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
GetExportedNamesandResolveExportsupport a module that is not linked.