MCPcopy Create free account
hub / github.com/GoogleChrome/samples / createWasm

Function createWasm

sqlite-wasm-cos/sqlite3-node.mjs:492–534  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

490// Create the wasm instance.
491// Receives the wasm imports, returns the exports.
492async function createWasm() {
493 // Load the wasm module and create an instance of using native support in the JS engine.
494 // handle a generated wasm instance, receiving its exports and
495 // performing other necessary setup
496 /** @param {WebAssembly.Module=} module*/
497 function receiveInstance(instance, module) {
498 wasmExports = instance.exports;
499
500 assignWasmExports(wasmExports);
501
502 return wasmExports;
503 }
504
505 // Prefer streaming instantiation if available.
506 function receiveInstantiationResult(result) {
507 // 'result' is a ResultObject object which has both the module and instance.
508 // receiveInstance() will swap in the exports (to Module.asm) so they can be called
509 // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
510 // When the regression is fixed, can restore the above PTHREADS-enabled path.
511 return receiveInstance(result['instance']);
512 }
513
514 var info = getWasmImports();
515
516 // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
517 // to manually instantiate the Wasm module themselves. This allows pages to
518 // run the instantiation parallel to any other async startup actions they are
519 // performing.
520 // Also pthreads and wasm workers initialize the wasm instance through this
521 // path.
522 if (Module['instantiateWasm']) {
523 return new Promise((resolve, reject) => {
524 Module['instantiateWasm'](info, (inst, mod) => {
525 resolve(receiveInstance(inst, mod));
526 });
527 });
528 }
529
530 wasmBinaryFile ??= findWasmBinary();
531 var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
532 var exports = receiveInstantiationResult(result);
533 return exports;
534}
535
536// end include: preamble.js
537

Callers 1

sqlite3InitModuleFunction · 0.70

Calls 6

resolveFunction · 0.85
getWasmImportsFunction · 0.70
receiveInstanceFunction · 0.70
findWasmBinaryFunction · 0.70
instantiateAsyncFunction · 0.70

Tested by

no test coverage detected