Expand description
The V8 module-namespace patch — a first-class, tested, public part of the build contract.
Each page’s wasm-bindgen-emitted JS imports * as import1 from the shared
islands-core URL and passes that namespace directly to
WebAssembly.instantiate as the importObject value. V8 rejects
module-namespace objects there with Import #N "<url>": module is not an object or function. We patch the emitted JS so the namespace is spread into a
plain prototype-less object — same shape, V8 accepts it. Skipping this is
fatal: the page WASM does not load.
Under a content-hashing build, the hashing pass rewrites basenames inside every
JS file (e.g. islands_core.js → islands_core.a1b2c3d4.js); the patch token
PATCH_TOKEN MUST survive that rewrite, and the importObject key for the
runtime is surgically restored to its unhashed form (see
rewrite_basenames_in_js) so it matches the WASM’s compiled import-module
name.
Constants§
- PATCH_
TOKEN - Literal substring present in every patched page JS. Build verification and the content-hash pass both assert this token is present (and survives hashing).
- RUNTIME_
IMPORT_ URL - The runtime’s fixed, never-hashed import URL — baked into every page WASM’s
import section by wasm-bindgen’s
raw_module = "...".
Functions§
- assert_
patched - Loud guard against wasm-bindgen output-shape drift: assert a freshly emitted
page JS actually carries the patch. If neither the patched token nor the raw
needle is present, wasm-bindgen changed its emitted shape and [
NEEDLE] must be updated — fail with a clear message instead of shipping a bundle V8 will reject at runtime. - patch_
page_ js - Apply the V8 namespace patch to a page’s emitted JS file, in place.
- patch_
page_ source - In-memory analogue of
patch_page_jsfor unit tests. - patch_
runtime_ snippets - Apply the snippet-namespace patch to the runtime’s own JS, in place.
- rewrite_
basenames_ in_ js - In-memory analogue of a content-hashing build’s basename rewrite: replace every
original → hashedbasename, then surgically restore the importObject KEY for the runtime to its unhashed form (so the WASM’s two-level import still resolves). Mirrorscrate::hashing’s rewrite step. - wrap_
snippet_ namespace_ imports - In-memory analogue of
patch_runtime_snippets: wrap every snippet importObject value line. Idempotent; returns the source unchanged when there are no snippet imports (noinline_js, or already patched).