Skip to content

Commit

Permalink
Fixed panic propagation. See dop251#471.
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Jan 16, 2023
1 parent 6eb401d commit 0341fef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,7 @@ func AssertConstructor(v Value) (Constructor, bool) {
func (r *Runtime) runWrapped(f func()) (err error) {
defer func() {
if x := recover(); x != nil {
if ex := asUncatchableException(x); x != nil {
if ex := asUncatchableException(x); ex != nil {
err = ex
if len(r.vm.callStack) == 0 {
r.leaveAbrupt()
Expand Down
26 changes: 26 additions & 0 deletions runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,32 @@ func TestAsyncStacktrace(t *testing.T) {
testAsyncFuncWithTestLibX(SCRIPT, _undefined, t)
}

func TestPanicPropagation(t *testing.T) {
r := New()
r.Set("doPanic", func() {
panic(true)
})
v, err := r.RunString(`(function() {
doPanic();
})`)
if err != nil {
t.Fatal(err)
}
f, ok := AssertFunction(v)
if !ok {
t.Fatal("not a function")
}
defer func() {
if x := recover(); x != nil {
if x != true {
t.Fatal("Invalid panic value")
}
}
}()
_, _ = f(nil)
t.Fatal("Expected panic")
}

/*
func TestArrayConcatSparse(t *testing.T) {
function foo(a,b,c)
Expand Down

0 comments on commit 0341fef

Please sign in to comment.