Open
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
122a87e to
861020c
Compare
9dfd653 to
457e3e1
Compare
|
The generated output of |
457e3e1 to
19e3f04
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New module registry: evaluation correctness, require() semantics, and import attributes
Fixes several correctness issues in the new module registry's evaluation, error propagation, and resolution paths. Adds
require()return value semantics matching Node.js, and implements support for import attributes (with { type: 'json' }).Synthetic module evaluation correctness
SyntheticModule::evaluate()previously calledactuallyEvaluate()directly, bypassing V8's module status machine. This meant synthetic modules never transitioned tokEvaluatedorkErrored— they stayed atkLinkedforever. This caused:require()status checks (kEvaluated,kErrored) never matching for synthetic modulesEvaluateOnceguard in CJS handlers being necessary as a workaround (and breaking cross-isolate sharing — the second isolate to evaluate got empty exports)The fix:
evaluate()now callsmodule->Evaluate()to enter V8's status machine. V8 calls back intoevaluationSteps, which callsactuallyEvaluate()directly (avoiding reentry). V8 manages all status transitions.EvaluateOnceis removed.Error propagation for errored dependencies
V8's
InnerModuleEvaluationskipskErroredchecks forSyntheticModuledependencies and skips recursive evaluation for modules atkEvaluating. Two new checks inresolveModuleCallbackaddress this:kErrored: If a resolved module is already errored (e.g., a JSON module that failed to parse), the cached exception is rethrown during instantiation instead of letting V8 link against stale export cells.kEvaluating: If a resolved module is mid-evaluation (ESM → CJS →require(ESM)→ static import back to CJS), a "Circular dependency" error is thrown instead of hitting a V8CHECKcrash.Both checks are also applied on the process redirect path for consistency.
Defensive
ensureInstantiatederror handlingBoth
EsModule::evaluate()andSyntheticModule::evaluate()now schedule aThrowErrorwhenensureInstantiatedfails and no exception is already pending. Previously, returning an emptyMaybeLocalwithout a pending exception could cause V8 to read garbage from the exception slot.require()return value semantics (UNWRAP_DEFAULT)Added
UNWRAP_DEFAULTrequire option (usingWD_STRONG_BOOL(UnwrapDefault)) that controls whatrequire()returns:require(esm). If the module exports__cjsUnwrapDefault = true(esbuild/bundler convention), returns the default export instead.node:assert,node:buffer, etc.): returns the default export, because workerd builtins are ESM that wrap CJS-style APIs in a default export.createRequireandCommonJsModuleContext::requireboth use this option.Import attributes
Replaced the blanket rejection of all import attributes with parsing and validation:
with { type: 'json' }— validates the resolved module hasContentType::JSON. ThrowsTypeErroron mismatch.with { type: 'text' }— recognized but rejected with "not yet supported" (pending TC39 Stage 4).with { type: 'bytes' }— recognized but rejected with "not yet supported" (pending immutable ArrayBuffer).TypeError.Added
Module::ContentTypeenum (NONE,JSON,TEXT,DATA,WASM) threaded through module construction. All data/text/json/wasm modules are tagged at registration time inworker-modules.h.Source phase import error handling
resolveModuleCallbacksource phase path to propagate pending exceptions from WASM compilation failures instead of masking them with a generic "Source phase import not available" message.dynamicResolvesource phase path: replacedKJ_FAIL_REQUIRE(v8::Exception::SyntaxError, ...)(which produced garbled error messages) with properjs.throwException.Reference documentation
docs/reference/detail/new-module-registry.mdwith evaluation flow changes,UNWRAP_DEFAULTsemantics, import attributes, andContentTypedocumentation.Tests
require(ESM)→ static import CJS (prevents V8 CHECK crash)UNWRAP_DEFAULT: bundle ESM returns namespace,__cjsUnwrapDefaultreturns default, JSON/Text return defaulttype:jsonsucceeds for JSON, fails for non-JSON, unsupported attributes rejected