Skip to content

Commit 6d60a12

Browse files
committed
wasm: terminate instance while met stackoverflow
1 parent e39e965 commit 6d60a12

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/wasm/wasm_exec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,17 @@
556556
if (this.exited) {
557557
throw new Error("Go program has already exited");
558558
}
559-
this._inst.exports.resume();
559+
try {
560+
this._inst.exports.resume();
561+
} catch (err) {
562+
if (err instanceof RangeError) {
563+
// runtime.throw
564+
this._inst.exports.throw(err.message);
565+
this.exited = true;
566+
this._resolveExitPromise();
567+
throw err;
568+
}
569+
}
560570
if (this.exited) {
561571
this._resolveExitPromise();
562572
}

src/runtime/panic.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ func internal_sync_fatal(s string) {
10861086
// See go.dev/issue/67401.
10871087
//
10881088
//go:linkname throw
1089+
//go:wasmexport throw
10891090
//go:nosplit
10901091
func throw(s string) {
10911092
// Everything throw does should be recursively nosplit so it

0 commit comments

Comments
 (0)