mirror of
https://github.com/robertkrimen/otto
synced 2025-09-28 18:45:22 +08:00
Fill out switch, for, for-in labelling
This and the previous commit fix #4
This commit is contained in:
parent
58cf2a4b67
commit
a780c85861
2
Makefile
2
Makefile
|
@ -20,8 +20,8 @@ TEST := -v --run API
|
|||
TEST := -v --run IsValidRegExp
|
||||
TEST := -v --run ParseFailure
|
||||
TEST := -v --run RegExp
|
||||
TEST := .
|
||||
TEST := -v --run SwitchBreak
|
||||
TEST := .
|
||||
|
||||
test: test-i
|
||||
go test $(TEST)
|
||||
|
|
63
otto_test.go
63
otto_test.go
|
@ -472,7 +472,7 @@ func TestSwitchBreak(t *testing.T) {
|
|||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
//echo "var x = true; while (x) {switch('a') {case 'a': break;} console.log('a'); x = false;}" | otto
|
||||
|
||||
test(`
|
||||
var abc = true;
|
||||
var ghi = "Xyzzy";
|
||||
|
@ -486,6 +486,67 @@ func TestSwitchBreak(t *testing.T) {
|
|||
}
|
||||
ghi
|
||||
`, "Nothing happens.")
|
||||
|
||||
test(`
|
||||
var abc = true;
|
||||
var ghi = "Xyzzy";
|
||||
WHILE:
|
||||
while (abc) {
|
||||
switch ('def') {
|
||||
case 'def':
|
||||
break WHILE;
|
||||
}
|
||||
ghi = "Nothing happens."
|
||||
abc = false
|
||||
}
|
||||
ghi
|
||||
`, "Xyzzy")
|
||||
|
||||
test(`
|
||||
var ghi = "Xyzzy";
|
||||
FOR:
|
||||
for (;;) {
|
||||
switch ('def') {
|
||||
case 'def':
|
||||
break FOR;
|
||||
ghi = ""
|
||||
}
|
||||
ghi = "Nothing happens."
|
||||
}
|
||||
ghi
|
||||
`, "Xyzzy")
|
||||
|
||||
test(`
|
||||
var ghi = "Xyzzy";
|
||||
FOR:
|
||||
for (var jkl in {}) {
|
||||
switch ('def') {
|
||||
case 'def':
|
||||
break FOR;
|
||||
ghi = "Something happens."
|
||||
}
|
||||
ghi = "Nothing happens."
|
||||
}
|
||||
ghi
|
||||
`, "Xyzzy")
|
||||
|
||||
test(`
|
||||
var ghi = "Xyzzy";
|
||||
function jkl() {
|
||||
switch ('def') {
|
||||
case 'def':
|
||||
break;
|
||||
ghi = ""
|
||||
}
|
||||
ghi = "Nothing happens."
|
||||
}
|
||||
while (abc) {
|
||||
jkl()
|
||||
abc = false
|
||||
ghi = "Something happens."
|
||||
}
|
||||
ghi
|
||||
`, "Something happens.")
|
||||
}
|
||||
|
||||
func TestTryFinally(t *testing.T) {
|
||||
|
|
|
@ -63,6 +63,12 @@ func (self *_parser) ParseStatement() _node {
|
|||
_labelSet = node._labelSet
|
||||
case *_whileNode:
|
||||
_labelSet = node._labelSet
|
||||
case *_switchNode:
|
||||
_labelSet = node._labelSet
|
||||
case *_forNode:
|
||||
_labelSet = node._labelSet
|
||||
case *_forInNode:
|
||||
_labelSet = node._labelSet
|
||||
}
|
||||
if _labelSet != nil {
|
||||
_labelSet[label] = true
|
||||
|
|
|
@ -158,6 +158,9 @@ func (self *_runtime) _callNode(environment *_functionEnvironment, node *_functi
|
|||
func (self *_runtime) Call(function *_object, this Value, argumentList []Value) (returnValue Value) {
|
||||
_functionEnvironment := self.EnterFunctionExecutionContext(function, this)
|
||||
defer func(){
|
||||
// TODO Catch any errant break/continue, etc. here?
|
||||
// They should never get here, but we want to be
|
||||
// very vocal if they do.
|
||||
self.LeaveExecutionContext();
|
||||
if caught := recover(); caught != nil {
|
||||
if result, ok := caught.(_result); ok {
|
||||
|
|
Loading…
Reference in New Issue
Block a user