MCPcopy
hub / github.com/jestjs/jest / importWasmModule

Method importWasmModule

packages/jest-runtime/src/internals/EsmLoader.ts:1325–1357  ·  view source on GitHub ↗
(
    source: BufferSource,
    identifier: string,
    context: VMContext,
  )

Source from the content-addressed store, hash-verified

1323 }
1324
1325 private async importWasmModule(
1326 source: BufferSource,
1327 identifier: string,
1328 context: VMContext,
1329 ): Promise<SyntheticModule> {
1330 // Use async `WebAssembly.compile` (rather than the sync constructor used
1331 // by the v24.9+ sync core) to avoid blocking the event loop on large wasm
1332 // modules in the legacy async path.
1333 const wasmModule = await WebAssembly.compile(source);
1334 const moduleLookup: Record<string, VMModule> = {};
1335 for (const {module} of WebAssembly.Module.imports(wasmModule)) {
1336 if (moduleLookup[module] === undefined) {
1337 const resolvedModule = await this.resolveModule<VMModule>(
1338 module,
1339 identifier,
1340 context,
1341 );
1342 // Do NOT call linkAndEvaluateModule here: we are executing inside the
1343 // linker callback for the parent module, so Node's cascade may already
1344 // be linking resolvedModule. Calling linkAndEvaluateModule would
1345 // spin-wait via setImmediate, but the cascade can't finish until this
1346 // linker returns - deadlock. The SyntheticModule's body runs only
1347 // after Node has fully evaluated all deps in topological order.
1348 moduleLookup[module] = resolvedModule;
1349 }
1350 }
1351 return buildWasmSyntheticModule(
1352 wasmModule,
1353 identifier,
1354 context,
1355 depSpec => moduleLookup[depSpec].namespace as Record<string, unknown>,
1356 );
1357 }
1358
1359 // Shared async dynamic-import callback installed on every SourceTextModule
1360 // we construct. Goes through the legacy async path; revisit when min-Node

Callers 2

loadEsmModuleMethod · 0.95
resolveModuleMethod · 0.95

Calls 2

buildWasmSyntheticModuleFunction · 0.90
compileMethod · 0.80

Tested by

no test coverage detected