mirror of
https://github.com/robertkrimen/otto
synced 2025-09-28 18:45:22 +08:00
Convert _syntaxError to SyntaxError (eval)
This commit is contained in:
parent
32cbffe7b8
commit
474a473e36
|
@ -20,12 +20,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)})
|
||||
}
|
||||
runtime := call.runtime
|
||||
runtime.EnterEvalExecutionContext(call)
|
||||
defer runtime.LeaveExecutionContext()
|
||||
// TODO Catch syntax error and convert to... SyntaxError
|
||||
returnValue := runtime.evaluate(program)
|
||||
if returnValue.isEmpty() {
|
||||
return UndefinedValue()
|
||||
|
|
|
@ -164,5 +164,7 @@ Second line \
|
|||
|
||||
test("/",
|
||||
"/",
|
||||
"EOF")
|
||||
"EOF",
|
||||
)
|
||||
|
||||
}
|
||||
|
|
19
otto_test.go
19
otto_test.go
|
@ -1797,12 +1797,15 @@ func Test_eval(t *testing.T) {
|
|||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
|
||||
test(`
|
||||
abc = 1
|
||||
`)
|
||||
|
||||
test(`
|
||||
eval("abc += 1")
|
||||
`, "2")
|
||||
|
||||
test(`
|
||||
(function(){
|
||||
var abc = 11
|
||||
|
@ -1811,6 +1814,22 @@ func Test_eval(t *testing.T) {
|
|||
})()
|
||||
`, "12")
|
||||
test(`abc`, "2")
|
||||
|
||||
test(`
|
||||
var ghi;
|
||||
(function(){
|
||||
try {
|
||||
eval("var prop = \\u2029;");
|
||||
return false;
|
||||
} catch (abc) {
|
||||
ghi = abc.toString()
|
||||
return abc instanceof SyntaxError;
|
||||
}
|
||||
})()
|
||||
`, "true")
|
||||
// TODO Make this a sane result
|
||||
// Lightning bolt, lightning bolt, lightning bolt, ...
|
||||
test(`ghi`, "SyntaxError: SyntaxError: SyntaxError: Unexpected token ILLEGAL ()")
|
||||
}
|
||||
|
||||
func Test_isNaN(t *testing.T) {
|
||||
|
|
|
@ -191,6 +191,10 @@ func (self *_runtime) tryEvaluate(inner func() Value) (tryValue Value, throw boo
|
|||
throw = true
|
||||
throwValue = toValue(self.newError(caught.Name, caught.MessageValue()))
|
||||
return
|
||||
case *_syntaxError:
|
||||
throw = true
|
||||
throwValue = toValue(self.newError("SyntaxError", toValue(caught.String())))
|
||||
return
|
||||
}
|
||||
panic(caught)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user