diff --git a/bug_test.go b/bug_test.go index 5e76c19d..1a52d7e2 100644 --- a/bug_test.go +++ b/bug_test.go @@ -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") } diff --git a/builtin.go b/builtin.go index fecb0c3e..c7c50dc8 100644 --- a/builtin.go +++ b/builtin.go @@ -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 { diff --git a/otto_test.go b/otto_test.go index de95a1b7..6b7edfd4 100644 --- a/otto_test.go +++ b/otto_test.go @@ -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(){ diff --git a/runtime.go b/runtime.go index d1181105..f71dfead 100644 --- a/runtime.go +++ b/runtime.go @@ -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)