| 1 |
// |reftest| skip-if(!xulRuntime.shell) |
| 2 |
function test() { |
| 3 |
|
| 4 |
// statements |
| 5 |
|
| 6 |
assertStmt("throw 42", throwStmt(lit(42))); |
| 7 |
assertStmt("for (;;) break", forStmt(null, null, null, breakStmt(null))); |
| 8 |
assertStmt("for (x; y; z) break", forStmt(ident("x"), ident("y"), ident("z"), breakStmt(null))); |
| 9 |
assertStmt("for (var x; y; z) break", forStmt(varDecl([{ id: ident("x"), init: null }]), ident("y"), ident("z"), breakStmt(null))); |
| 10 |
assertStmt("for (var x = 42; y; z) break", forStmt(varDecl([{ id: ident("x"), init: lit(42) }]), ident("y"), ident("z"), breakStmt(null))); |
| 11 |
assertStmt("for (x; ; z) break", forStmt(ident("x"), null, ident("z"), breakStmt(null))); |
| 12 |
assertStmt("for (var x; ; z) break", forStmt(varDecl([{ id: ident("x"), init: null }]), null, ident("z"), breakStmt(null))); |
| 13 |
assertStmt("for (var x = 42; ; z) break", forStmt(varDecl([{ id: ident("x"), init: lit(42) }]), null, ident("z"), breakStmt(null))); |
| 14 |
assertStmt("for (x; y; ) break", forStmt(ident("x"), ident("y"), null, breakStmt(null))); |
| 15 |
assertStmt("for (var x; y; ) break", forStmt(varDecl([{ id: ident("x"), init: null }]), ident("y"), null, breakStmt(null))); |
| 16 |
assertStmt("for (var x = 42; y; ) break", forStmt(varDecl([{ id: ident("x"), init: lit(42) }]), ident("y"), null, breakStmt(null))); |
| 17 |
assertStmt("for (var x in y) break", forInStmt(varDecl([{ id: ident("x"), init: null }]), ident("y"), breakStmt(null))); |
| 18 |
assertStmt("for (x in y) break", forInStmt(ident("x"), ident("y"), breakStmt(null))); |
| 19 |
assertStmt("{ }", blockStmt([])); |
| 20 |
assertStmt("{ throw 1; throw 2; throw 3; }", blockStmt([ throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))])); |
| 21 |
assertStmt(";", emptyStmt); |
| 22 |
assertStmt("if (foo) throw 42;", ifStmt(ident("foo"), throwStmt(lit(42)), null)); |
| 23 |
assertStmt("if (foo) throw 42; else true;", ifStmt(ident("foo"), throwStmt(lit(42)), exprStmt(lit(true)))); |
| 24 |
assertStmt("if (foo) { throw 1; throw 2; throw 3; }", |
| 25 |
ifStmt(ident("foo"), |
| 26 |
blockStmt([throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))]), |
| 27 |
null)); |
| 28 |
assertStmt("if (foo) { throw 1; throw 2; throw 3; } else true;", |
| 29 |
ifStmt(ident("foo"), |
| 30 |
blockStmt([throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))]), |
| 31 |
exprStmt(lit(true)))); |
| 32 |
|
| 33 |
|
| 34 |
assertStmt("foo: for(;;) break foo;", labStmt(ident("foo"), forStmt(null, null, null, breakStmt(ident("foo"))))); |
| 35 |
assertStmt("foo: for(;;) continue foo;", labStmt(ident("foo"), forStmt(null, null, null, continueStmt(ident("foo"))))); |
| 36 |
assertStmt("with (obj) { }", withStmt(ident("obj"), blockStmt([]))); |
| 37 |
assertStmt("with (obj) { obj; }", withStmt(ident("obj"), blockStmt([exprStmt(ident("obj"))]))); |
| 38 |
assertStmt("while (foo) { }", whileStmt(ident("foo"), blockStmt([]))); |
| 39 |
assertStmt("while (foo) { foo; }", whileStmt(ident("foo"), blockStmt([exprStmt(ident("foo"))]))); |
| 40 |
assertStmt("do { } while (foo);", doStmt(blockStmt([]), ident("foo"))); |
| 41 |
assertStmt("do { foo; } while (foo)", doStmt(blockStmt([exprStmt(ident("foo"))]), ident("foo"))); |
| 42 |
assertStmt("switch (foo) { case 1: 1; break; case 2: 2; break; default: 3; }", |
| 43 |
switchStmt(ident("foo"), |
| 44 |
[ caseClause(lit(1), [ exprStmt(lit(1)), breakStmt(null) ]), |
| 45 |
caseClause(lit(2), [ exprStmt(lit(2)), breakStmt(null) ]), |
| 46 |
defaultClause([ exprStmt(lit(3)) ]) ])); |
| 47 |
assertStmt("switch (foo) { case 1: 1; break; case 2: 2; break; default: 3; case 42: 42; }", |
| 48 |
switchStmt(ident("foo"), |
| 49 |
[ caseClause(lit(1), [ exprStmt(lit(1)), breakStmt(null) ]), |
| 50 |
caseClause(lit(2), [ exprStmt(lit(2)), breakStmt(null) ]), |
| 51 |
defaultClause([ exprStmt(lit(3)) ]), |
| 52 |
caseClause(lit(42), [ exprStmt(lit(42)) ]) ])); |
| 53 |
assertStmt("try { } catch (e) { }", |
| 54 |
tryStmt(blockStmt([]), |
| 55 |
catchClause(ident("e"), blockStmt([])), |
| 56 |
null)); |
| 57 |
assertStmt("try { } catch (e) { } finally { }", |
| 58 |
tryStmt(blockStmt([]), |
| 59 |
catchClause(ident("e"), blockStmt([])), |
| 60 |
blockStmt([]))); |
| 61 |
assertStmt("try { } finally { }", |
| 62 |
tryStmt(blockStmt([]), |
| 63 |
null, |
| 64 |
blockStmt([]))); |
| 65 |
assertStmt("try { } catch { }", |
| 66 |
tryStmt(blockStmt([]), |
| 67 |
catchClause(null, blockStmt([])), |
| 68 |
null)); |
| 69 |
assertStmt("try { } catch { } finally { }", |
| 70 |
tryStmt(blockStmt([]), |
| 71 |
catchClause(null, blockStmt([])), |
| 72 |
blockStmt([]))); |
| 73 |
|
| 74 |
|
| 75 |
// Bug 632028: yield outside of a function should throw |
| 76 |
(function() { |
| 77 |
var threw = false; |
| 78 |
try { |
| 79 |
Reflect.parse("yield 0"); |
| 80 |
} catch (expected) { |
| 81 |
threw = true; |
| 82 |
} |
| 83 |
assertEq(threw, true); |
| 84 |
})(); |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
runtest(test); |