MCPcopy
hub / github.com/webpack/webpack / createModule

Function createModule

examples/wasm-emscripten/emscripten-module.js:5–32  ·  view source on GitHub ↗
(moduleArg = {})

Source from the content-addressed store, hash-verified

3// contract a bundler must satisfy is small: a default-exported factory that
4// owns wasm instantiation and honors the `instantiateWasm` escape hatch.
5export default function createModule(moduleArg = {}) {
6 const Module = moduleArg;
7
8 // The import object the wasm needs. Only the glue knows how to build it,
9 // which is why webpack cannot instantiate the module itself.
10 const imports = {
11 env: {
12 log(value) {
13 if (Module.onLog) Module.onLog(value);
14 }
15 }
16 };
17
18 return new Promise((resolve, reject) => {
19 const receiveInstance = (instance) => {
20 Module.run = (n) => instance.exports.run(n);
21 resolve(Module);
22 };
23
24 // Emscripten's official hook: hand instantiation to the embedder.
25 if (Module.instantiateWasm) {
26 Module.instantiateWasm(imports, receiveInstance);
27 return;
28 }
29
30 reject(new Error("This minimal glue requires an instantiateWasm hook"));
31 });
32}

Callers 1

example.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected