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

Function createWasm

mkbitmap/mkbitmap.js:858–928  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

856// Create the wasm instance.
857// Receives the wasm imports, returns the exports.
858function createWasm() {
859 // prepare imports
860 var info = {
861 'env': wasmImports,
862 'wasi_snapshot_preview1': wasmImports,
863 };
864 // Load the wasm module and create an instance of using native support in the JS engine.
865 // handle a generated wasm instance, receiving its exports and
866 // performing other necessary setup
867 /** @param {WebAssembly.Module=} module*/
868 function receiveInstance(instance, module) {
869 var exports = instance.exports;
870
871 Module['asm'] = exports;
872
873 wasmMemory = Module['asm']['memory'];
874 assert(wasmMemory, "memory not found in wasm exports");
875 // This assertion doesn't hold when emscripten is run in --post-link
876 // mode.
877 // TODO(sbc): Read INITIAL_MEMORY out of the wasm file in post-link mode.
878 //assert(wasmMemory.buffer.byteLength === 16777216);
879 updateMemoryViews();
880
881 wasmTable = Module['asm']['__indirect_function_table'];
882 assert(wasmTable, "table not found in wasm exports");
883
884 addOnInit(Module['asm']['__wasm_call_ctors']);
885
886 removeRunDependency('wasm-instantiate');
887
888 return exports;
889 }
890 // wait for the pthread pool (if any)
891 addRunDependency('wasm-instantiate');
892
893 // Prefer streaming instantiation if available.
894 // Async compilation can be confusing when an error on the page overwrites Module
895 // (for example, if the order of elements is wrong, and the one defining Module is
896 // later), so we save Module and check it later.
897 var trueModule = Module;
898 function receiveInstantiationResult(result) {
899 // 'result' is a ResultObject object which has both the module and instance.
900 // receiveInstance() will swap in the exports (to Module.asm) so they can be called
901 assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
902 trueModule = null;
903 // 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.
904 // When the regression is fixed, can restore the above PTHREADS-enabled path.
905 receiveInstance(result['instance']);
906 }
907
908 // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
909 // to manually instantiate the Wasm module themselves. This allows pages to
910 // run the instantiation parallel to any other async startup actions they are
911 // performing.
912 // Also pthreads and wasm workers initialize the wasm instance through this
913 // path.
914 if (Module['instantiateWasm']) {
915

Callers

nothing calls this directly

Calls 2

addRunDependencyFunction · 0.70
instantiateAsyncFunction · 0.70

Tested by

no test coverage detected