Skip to content

Commit

Permalink
Fix (band-aid) Go/JavaScript cross-boundary error transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
robertkrimen committed Mar 6, 2013
1 parent d013283 commit 260b2a4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
8 changes: 6 additions & 2 deletions builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion otto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
2 changes: 1 addition & 1 deletion runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 260b2a4

Please sign in to comment.