made onyx-js work for non-multithreaded programs again
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 17 Oct 2021 23:42:07 +0000 (18:42 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 17 Oct 2021 23:42:07 +0000 (18:42 -0500)
bin/onyx-js

index 36668b58094c30226d2eff84d500036c90c0fc9c..cf631947af9413e7a28fc5702700c2ea9ab5e1bb 100755 (executable)
@@ -46,13 +46,23 @@ const ENV = {
 if (isMainThread) {
     wasm_bytes = fs.readFileSync(process.argv[2]);
 
+    let multi_threaded = false;
+    if (process.argv.length >= 3 && process.argv[3] == "multi") {
+        multi_threaded = true;
+    }
+
     // main thread
-    wasm_memory = new WebAssembly.Memory({ initial: 1024, maximum: 65536, shared: true });
-    ENV.onyx.memory = wasm_memory;
+    if (multi_threaded) {
+        wasm_memory = new WebAssembly.Memory({ initial: 1024, maximum: 65536, shared: true });
+        ENV.onyx.memory = wasm_memory;
+    }
 
     WebAssembly.instantiate(new Uint8Array(wasm_bytes), ENV)
         .then(res => {
             wasm_instance = res.instance;
+            if (!multi_threaded) {
+                wasm_memory = wasm_instance.exports.memory;
+            }
 
             const lib = res.instance.exports;
             lib._start();