mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 05:23:40 +00:00
wasm: correctly return from run() in wasm_exec.js
Instead of hanging forever, it should return the exit code from os.Exit.
This commit is contained in:
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
println("wasmexit test:", os.Args[1])
|
||||
switch os.Args[1] {
|
||||
case "normal":
|
||||
return
|
||||
case "exit-0":
|
||||
os.Exit(0)
|
||||
case "exit-0-sleep":
|
||||
time.Sleep(time.Millisecond)
|
||||
println("slept")
|
||||
os.Exit(0)
|
||||
case "exit-1":
|
||||
os.Exit(1)
|
||||
case "exit-1-sleep":
|
||||
time.Sleep(time.Millisecond)
|
||||
println("slept")
|
||||
os.Exit(1)
|
||||
}
|
||||
println("unknown wasmexit test")
|
||||
}
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
require('../targets/wasm_exec.js');
|
||||
|
||||
function runTests() {
|
||||
let testCall = (name, params, expected) => {
|
||||
let result = go._inst.exports[name].apply(null, params);
|
||||
if (result !== expected) {
|
||||
console.error(`${name}(...${params}): expected result ${expected}, got ${result}`);
|
||||
}
|
||||
}
|
||||
|
||||
// These are the same tests as in TestWasmExport.
|
||||
testCall('hello', [], undefined);
|
||||
testCall('add', [3, 5], 8);
|
||||
testCall('add', [7, 9], 16);
|
||||
testCall('add', [6, 1], 7);
|
||||
testCall('reentrantCall', [2, 3], 5);
|
||||
testCall('reentrantCall', [1, 8], 9);
|
||||
}
|
||||
|
||||
let go = new Go();
|
||||
go.importObject.tester = {
|
||||
callOutside: (a, b) => {
|
||||
return go._inst.exports.add(a, b);
|
||||
},
|
||||
callTestMain: () => {
|
||||
runTests();
|
||||
},
|
||||
};
|
||||
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then(async (result) => {
|
||||
let value = await go.run(result.instance);
|
||||
console.log('exit code:', value);
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user