1
0
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:
Robert Krimen 2013-05-19 15:42:20 -07:00
parent 791a2c0c8e
commit e2e79bb697
2 changed files with 26 additions and 5 deletions

View File

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

View File

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