From e2e79bb6974958a59a61c5c179bd3f88645bc36a Mon Sep 17 00:00:00 2001 From: Robert Krimen Date: Sun, 19 May 2013 15:42:20 -0700 Subject: [PATCH] A Value panic during a FunctionCall is the same as a throw in JavaScript --- error_test.go | 21 +++++++++++++++++++++ runtime.go | 10 +++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/error_test.go b/error_test.go index ab3ca48..aee4d5b 100644 --- a/error_test.go +++ b/error_test.go @@ -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") +} diff --git a/runtime.go b/runtime.go index 55a281a..8fa8376 100644 --- a/runtime.go +++ b/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) } }()