dcodeIO/webassembly

(node:91015) UnhandledPromiseRejectionWarning: TypeError: wasm function signature contains illegal type

LiaoPeng opened this issue ยท 3 comments

As the description, the module provider runtime for WebAssembly modules.
I used AssemblyScript to compile the typescript file to wasm.

export function add(x: u64, y: u64): u64 {
  return x + y;
}

Then, using the webassembly to run the module,

require("webassembly")
  .load("main.wasm")
  .then(module => {
    console.log("1 + 2 = " + module.exports.add(1, 2));
  });

I got the error below

(node:92224) UnhandledPromiseRejectionWarning: TypeError: wasm function signature contains illegal type
    at require.load.then.module (/Users/Peng/Downloads/wasm-project-yolspucnghl/out/program.js:7:45)
(node:92224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:92224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Is there a gap between the AssemblyScript and webassembly?
And is there a node.js module to run the webassembly modules that AseemblyScript compiled.

xtuc commented

Since JavaScript doesn't supports int64 yet, a signature with a int64 in wasm can't be exported to JS.

also getting this issue when trying to run a .wasm file with i64 types in nodejs. anybody found a way to get this working in javascript?

Support for i64's on the boundary is behind the --experimental-wasm-bigint flag in current node. Enabling that should make it work, with BigInts representing the respective i64 value in JS.

An alternative to using experimental features is to return an i32 for the low bits, and export another helper function returning the high bits of the last operation as another i32. Something like long.js's Long.fromBits can work with these.