1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00

Fix (band-aid) Go/JavaScript cross-boundary error transformation

This commit is contained in:
Robert Krimen 2013-03-06 12:07:26 -08:00
parent d0132833fb
commit 260b2a48bf
4 changed files with 9 additions and 5 deletions

View File

@ -10,7 +10,7 @@ func Test_262(t *testing.T) {
test := runTest()
test(`raise:
42 = 42;
eval("42 = 42;");
`, "ReferenceError: Invalid left-hand side in assignment")
}

View File

@ -17,8 +17,12 @@ func builtinGlobal_eval(call FunctionCall) Value {
}
program, err := parse(toString(source))
if err != nil {
//panic(call.runtime.newError("SyntaxError", UndefinedValue()))
panic(&_syntaxError{Message: fmt.Sprintf("%v", err)})
switch err := err.(type) {
case *_syntaxError, *_error, _error:
panic(err)
default:
panic(&_syntaxError{Message: fmt.Sprintf("%v", err)})
}
}
runtime := call.runtime
if call.evalHint {

View File

@ -209,7 +209,7 @@ func Test_eval(t *testing.T) {
`, "true")
// TODO Make this a sane result
// Lightning bolt, lightning bolt, lightning bolt, ...
test(`ghi`, "SyntaxError: SyntaxError: SyntaxError: Unexpected token ILLEGAL ()")
test(`ghi`, "SyntaxError: Unexpected token ILLEGAL ()")
test(`
function abc(){

View File

@ -208,7 +208,7 @@ func (self *_runtime) tryEvaluate(inner func() Value) (tryValue Value, throw boo
return
case *_syntaxError:
throw = true
throwValue = toValue(self.newError("SyntaxError", toValue(caught.String())))
throwValue = toValue(self.newError("SyntaxError", toValue(caught.Message)))
return
}
panic(caught)