1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-26 20:28:49 +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 := runTest()
test(`raise: test(`raise:
42 = 42; eval("42 = 42;");
`, "ReferenceError: Invalid left-hand side in assignment") `, "ReferenceError: Invalid left-hand side in assignment")
} }

View File

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

View File

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

View File

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