mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
A Value panic during a FunctionCall is the same as a throw in JavaScript
This commit is contained in:
parent
791a2c0c8e
commit
e2e79bb697
|
@ -13,3 +13,24 @@ func TestError_instanceof(t *testing.T) {
|
|||
(new TypeError()) instanceof Error
|
||||
`, "true")
|
||||
}
|
||||
|
||||
func TestPanicValue(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
|
||||
failSet("abc", func(call FunctionCall) Value {
|
||||
value, err := call.Otto.Run(`({ def: 3.14159 })`)
|
||||
Is(err, nil)
|
||||
panic(value)
|
||||
})
|
||||
test(`
|
||||
try {
|
||||
abc();
|
||||
}
|
||||
catch (err) {
|
||||
error = err;
|
||||
}
|
||||
[ error instanceof Error, error.message, error.def ];
|
||||
`, "false,,3.14159")
|
||||
}
|
||||
|
|
10
runtime.go
10
runtime.go
|
@ -202,23 +202,23 @@ func (self *_runtime) tryCatchEvaluate(inner func() Value) (resultValue Value, t
|
|||
case resultThrow:
|
||||
throw = true
|
||||
throwValue = caught.Value
|
||||
return
|
||||
case resultReturn, resultBreak, resultContinue:
|
||||
fallthrough
|
||||
default:
|
||||
other = &caught
|
||||
return
|
||||
}
|
||||
case _error:
|
||||
throw = true
|
||||
throwValue = toValue(self.newError(caught.Name, caught.MessageValue()))
|
||||
return
|
||||
case *_syntaxError:
|
||||
throw = true
|
||||
throwValue = toValue(self.newError("SyntaxError", toValue(caught.Message)))
|
||||
return
|
||||
case Value:
|
||||
throw = true
|
||||
throwValue = caught
|
||||
default:
|
||||
panic(caught)
|
||||
}
|
||||
panic(caught)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user