瀏覽代碼

Fixed panic propagation. See #471.

Dmitry Panov 2 年之前
父節點
當前提交
0341fef34b
共有 2 個文件被更改,包括 27 次插入1 次删除
  1. 1 1
      runtime.go
  2. 26 0
      runtime_test.go

+ 1 - 1
runtime.go

@@ -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()

+ 26 - 0
runtime_test.go

@@ -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)