-
-
Save mit-mit/0fcb1247a9444b0cadf611aa5fc6f32e to your computer and use it in GitHub Desktop.
Dart web Wasm bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function () { | |
let dart2wasm_runtime; | |
let moduleInstance; | |
try { | |
const dartModulePromise = WebAssembly.compileStreaming(fetch('main.wasm')); | |
const imports = {}; | |
dart2wasm_runtime = await import('./main.mjs'); | |
moduleInstance = await dart2wasm_runtime.instantiate(dartModulePromise, imports); | |
} catch (exception) { | |
console.error(`Failed to fetch and instantiate wasm module: ${exception}`); | |
console.error('See https://dart.dev/web/wasm for more information.'); | |
} | |
if (moduleInstance) { | |
try { | |
await dart2wasm_runtime.invoke(moduleInstance); | |
} catch (exception) { | |
console.error(`Exception while invoking test: ${exception}`); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code is a bit simpler/different in Dart 3.6: dart-lang/sdk@56178c2