aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-07-22 04:31:58 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-22 04:31:58 -0700
commitc6a3467625fede0fe9901ab53b0aabd651866b64 (patch)
tree6cdd9bfd79756e97081b45de5323a7bbde62ceff /src/js
parent636cec03e10ab487b1df3057aaab60b4d2b02c99 (diff)
downloadbun-c6a3467625fede0fe9901ab53b0aabd651866b64.tar.gz
bun-c6a3467625fede0fe9901ab53b0aabd651866b64.tar.zst
bun-c6a3467625fede0fe9901ab53b0aabd651866b64.zip
Unified event loop (#3741)
* Unified event loop * Update WebKit, add test for es-module-lexer * Update README.md * Use async wasm * Explicitly set whether concurrenttask should be deinit'd * Update package.json --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/js')
-rw-r--r--src/js/bun/wasi-runner.js15
-rw-r--r--src/js/out/modules/bun/wasi-runner.js11
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);