Is it possible to convert .js(not .ts) to .wasm and call it by JS WebAssembly API?

Viewed 17

following the README.md of https://github.com/Shopify/javy I got an index.wasm

I tried to call it by JS WebAssembly API:

WebAssembly.instantiateStreaming(fetch("xxxxxxx/index.wasm"), {
  wasi_snapshot_preview1: {
    fd_close: (e) => {
      console.log("fd_close", e);
    },
    fd_write: (e) => {
      console.log("fd_write", e);
    },
    fd_read: (e) => {
      console.log("fd_read", e);
    },
    fd_seek: (e) => {
      console.log("fd_seek", e);
    },
    environ_get: (e) => {
      console.log("fd_environ_get", e);
    },
    environ_sizes_get: (e) => {
      console.log("fd_environ_sizes_get", e);
    },
    clock_time_get: (e) => {
      console.log("clock_time_get", e);
    },
    fd_fdstat_get: (e) => {
      console.log("fd_fdstat_get", e);
    },
    proc_exit: (e) => {
      console.log("proc_exit", e);
    },
  },
  env: {},
}).then((obj) => {
  console.log(obj.instance.exports.main({ n: 100, bar: "test" }));
});

but this error:

RuntimeError: unreachable
    at xxxxxxx/index.wasm:wasm-function[193]:0x110ec
    at xxxxxxx/index.wasm:wasm-function[318]:0x1a4fc
    at xxxxxxx/index.wasm:wasm-function[28]:0x1489
    at xxxxxxx/index.wasm:wasm-function[88]:0x728f
    at xxxxxxx/index.wasm:wasm-function[57]:0x38ab
    at xxxxxxx/index.wasm:wasm-function[287]:0x18880
    at xxxxxxx/index.wasm:wasm-function[39]:0x1cb6
    at xxxxxxx/index.wasm:wasm-function[193]:0x11422
    at xxxxxxx/index.wasm:wasm-function[318]:0x1a4fc
    at xxxxxxx/index.wasm:wasm-function[28]:0x1489

What's wrong with my code?

Is there any better alternative to javy?

0 Answers
Related