-
-
Notifications
You must be signed in to change notification settings - Fork 687
String concat from external function will get RuntimeError: unreachable #1057
Copy link
Copy link
Closed
Description
I use the external function from JS host, to concat a string in the assemblyscript function, will got RuntimeError: unreachable error. the demo code shows below:
node.js code:
const loader = require("@assemblyscript/loader");
const fs = require("fs");
const myImports = {
env: {
abort(_msg, _file, line, column) {},
},
index: {
getSth: function () {
return wasm.__allocString('world');
}
}
};
const wasm = loader.instantiateSync(
fs.readFileSync("build/untouched.wasm"),
myImports
);
// execute the wasm.test2()
console.log(wasm.__getString(wasm.test2()));
index.ts
declare function getSth(): string;
export function test2(): string {
return 'hello' + getSth();
}
when executed, get the error below:
wasm://wasm/00014e42:29
^
RuntimeError: unreachable
at ~lib/rt/pure/decrement (wasm-function[28]:45)
at ~lib/rt/pure/__release (wasm-function[29]:13)
at assembly/index/test2 (wasm-function[65]:71)
at Object.wrap [as test2] (/Users/mac/myProject/assemblyscript/as2/node_modules/@assemblyscript/loader/index.js:277:12)
at Object.<anonymous> (/Users/mac/myProject/assemblyscript/as2/node.js:41:35)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Is there are sth wrong with me?
Btw, when I change return 'hello' + getSth(); to return getSth();, the function works well, and console the world. I read the document then and knowns that __allocString will return the header points of the string. Is there any ways to let ptr to string? I v try 'hello' + getSth().toString(), but is still useless.
Reactions are currently unavailable