diff options
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/bun/wasi-runner.js | 15 | ||||
-rw-r--r-- | src/js/out/modules/bun/wasi-runner.js | 11 |
2 files changed, 19 insertions, 7 deletions
diff --git a/src/js/bun/wasi-runner.js b/src/js/bun/wasi-runner.js index a292c6380..9f7b469e1 100644 --- a/src/js/bun/wasi-runner.js +++ b/src/js/bun/wasi-runner.js @@ -11,7 +11,12 @@ if (!filePath) { // The module specifier is the resolved path to the wasm file -var { WASM_CWD = process.cwd(), WASM_ROOT_DIR = "/", WASM_ENV_STR = undefined, WASM_USE_ASYNC_INIT = "" } = process.env; +var { + WASM_CWD = process.cwd(), + WASM_ROOT_DIR = "/", + WASM_ENV_STR = undefined, + WASM_USE_ASYNC_INIT = "1", +} = process.env; var env = process.env; if (WASM_ENV_STR?.length) { @@ -34,10 +39,12 @@ if (!source) { source = fs.readFileSync(file); } -const wasm = new WebAssembly.Module(source); -const instance = !WASM_USE_ASYNC_INIT +const wasm = await WebAssembly.compile(source); + +const instance = !Number(WASM_USE_ASYNC_INIT) ? new WebAssembly.Instance(wasm, wasi.getImports(wasm)) : await WebAssembly.instantiate(wasm, wasi.getImports(wasm)); + wasi.start(instance); -process.exit(0); +process.reallyExit(0); diff --git a/src/js/out/modules/bun/wasi-runner.js b/src/js/out/modules/bun/wasi-runner.js index 9dfd27b23..47c5ade3c 100644 --- a/src/js/out/modules/bun/wasi-runner.js +++ b/src/js/out/modules/bun/wasi-runner.js @@ -1,7 +1,12 @@ var filePath = process.argv.at(1); if (!filePath) throw err = new Error("To run a wasm file with Bun, the first argument must be a path to a .wasm file"), err.name = "WasmFileNotFound", err; -var err, { WASM_CWD = process.cwd(), WASM_ROOT_DIR = "/", WASM_ENV_STR = void 0, WASM_USE_ASYNC_INIT = "" } = process.env, env = process.env; +var err, { + WASM_CWD = process.cwd(), + WASM_ROOT_DIR = "/", + WASM_ENV_STR = void 0, + WASM_USE_ASYNC_INIT = "1" +} = process.env, env = process.env; if (WASM_ENV_STR?.length) env = JSON.parse(WASM_ENV_STR); var wasi = new WASI({ @@ -16,6 +21,6 @@ if (!source) { const fs = Bun.fs(), file = import.meta.path; source = fs.readFileSync(file); } -var wasm = new WebAssembly.Module(source), instance = !WASM_USE_ASYNC_INIT ? new WebAssembly.Instance(wasm, wasi.getImports(wasm)) : await WebAssembly.instantiate(wasm, wasi.getImports(wasm)); +var wasm = await WebAssembly.compile(source), instance = !Number(WASM_USE_ASYNC_INIT) ? new WebAssembly.Instance(wasm, wasi.getImports(wasm)) : await WebAssembly.instantiate(wasm, wasi.getImports(wasm)); wasi.start(instance); -process.exit(0); +process.reallyExit(0); |