I wrote a trivial AssemblyScript function:
export function F(s: string): i32 {
return s.length;
}
Loading and using the resulting F.wasm
in the browser WORKS WELL while I got RuntimeError: memory access out of bounds
using Node.js (on Windows, v18.12.1). Here is my Node.js code:
const imported_object = {env: {abort: (a, b, c, d) => console.log(a)}};
WebAssembly.instantiate(fs.readFileSync("./build/F.wasm"), imported_object).then(module => {
const {F} = module.instance.exports;
console.log(F("4719512002889")); // Output: '13' in the browser
});
Note 1: on macOS, the error is Bus error 10
, which is weird? (same Node.js ver. is used, ie, v18.12.1)
Note 2: it was mandatory to set up and pass imported_object
to avoid other errors (see also WebAssembly: TypeError: WebAssembly Instantiation: Imports argument must be present). I however feel that imported_object
isn't well configured?
Note 3: I've tried the AssemblyScript compiler with several "memory" options but the lack of explicit clear doc. on such compiler parameters does not allow me to fix my problem.
Help appreciated... Thanks in advance.