chiark / gitweb /
jstest: wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 7 Jul 2021 22:58:00 +0000 (23:58 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 8 Jul 2021 12:09:51 +0000 (13:09 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
wasmtest.nodejs [new file with mode: 0644]

diff --git a/wasmtest.nodejs b/wasmtest.nodejs
new file mode 100644 (file)
index 0000000..8bedc29
--- /dev/null
@@ -0,0 +1,26 @@
+const fs = require('fs');
+//var source = fs.readFileSync('./target/packed-wasm/otter_wasm_bg.wasm');
+var source = fs.readFileSync('./target/wasm32-unknown-unknown/release/otter_wasm.wasm');
+var typedArray = new Uint8Array(source);
+const env = {
+    memoryBase: 0,
+    tableBase: 0,
+    memory: new WebAssembly.Memory({
+      initial: 256
+    }),
+    table: new WebAssembly.Table({
+      initial: 0,
+      element: 'anyfunc'
+    })
+  }
+
+WebAssembly.instantiate(typedArray, {
+  env: env
+}).then(result => {
+  console.log(util.inspect(result, true, 0));
+  console.log(result.instance.exports._add(9, 9));
+}).catch(e => {
+  // error caught
+  console.log(e);
+  console.log(e.stack);
+});