Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Flags: --harmony-completion --harmony --no-legacy-const | |
|
rossberg
2015/10/07 12:28:46
Don't use the generic --harmony flag in tests.
neis
2015/10/08 12:57:25
Done.
| |
| 6 | |
| 7 | |
| 8 function assertUndef(x) { | |
| 9 assertEquals(undefined, x); | |
| 10 } | |
| 11 | |
| 12 | |
| 13 // IfStatement [13.6.7] | |
| 14 | |
| 15 assertUndef(eval('42; if (true) ; else 0;')); // ES5: 42 | |
| 16 assertUndef(eval('42; if (true) ;')); // ES5: 42 | |
| 17 assertUndef(eval('42; if (false) 0;')); // ES5: 42 | |
| 18 | |
| 19 assertEquals(1, eval('42; if (true) 1;')); | |
| 20 assertEquals(1, eval('42; if (true) 1; else 0;')); | |
| 21 assertEquals(0, eval('42; if (false) 1; else 0;')); | |
| 22 | |
| 23 | |
| 24 // IterationStatement [13.7] | |
| 25 | |
| 26 assertUndef(eval('42; do ; while (false);')); // ES5: 42 | |
| 27 assertUndef(eval('42; var x = 1; do ; while (x--);')); // ES5: 42 | |
| 28 assertUndef(eval('42; while (false) 0;')); // ES5: 42 | |
| 29 assertUndef(eval('42; while (true) break;')); // ES5: 42 | |
| 30 assertUndef(eval('42; bla: while (true) break bla;')); // ES5: 42 | |
| 31 assertUndef(eval('42; var x = 1; while (x--) ;')); // ES5: 42 | |
| 32 assertUndef(eval('42; for (; false; ) 0;')); // ES5: 42 | |
| 33 assertUndef(eval('42; for (var x = 1; x; x--) ;')); // ES5: 42 | |
| 34 assertUndef(eval('42; for (var x in ["foo", "bar"]) ;')); | |
| 35 assertUndef(eval('42; for (var x of ["foo", "bar"]) ;')); | |
| 36 assertUndef(eval('42; for (let x = 1; x; x--) ;')); | |
| 37 assertUndef(eval('42; for (let x in ["foo", "bar"]) ;')); | |
| 38 assertUndef(eval('42; for (let x of ["foo", "bar"]) ;')); | |
| 39 assertUndef(eval('42; for (const x in ["foo", "bar"]) ;')); | |
| 40 assertUndef(eval('42; for (const x of ["foo", "bar"]) ;')); | |
| 41 | |
| 42 assertEquals(1, eval('42; var x = 10; do x--; while (x);')); | |
| 43 assertEquals(1, eval('42; var x = 10; while (x) x--;')); | |
| 44 assertEquals(1, eval('42; for (var x = 10; x; x--) x;')); | |
| 45 assertEquals(1, eval('42; for (var x = 10; x; --x) x;')); | |
| 46 assertEquals(1, eval('42; for (let x = 10; x; --x) x;')); | |
| 47 assertEquals(1, eval('42; var y = 2; for (var x in ["foo", "bar"]) y--;')); | |
| 48 assertEquals(1, eval('42; var y = 2; for (const x in ["foo", "bar"]) y--;')); | |
| 49 assertEquals(1, eval('42; var y = 2; for (let x in ["foo", "bar"]) y--;')); | |
| 50 assertEquals(1, eval('42; var y = 2; for (var x of ["foo", "bar"]) y--;')); | |
| 51 assertEquals(1, eval('42; var y = 2; for (const x of ["foo", "bar"]) y--;')); | |
| 52 assertEquals(1, eval('42; var y = 2; for (let x of ["foo", "bar"]) y--;')); | |
| 53 | |
| 54 | |
| 55 // WithStatement [13.11.7] | |
| 56 | |
| 57 assertUndef(eval('42; with ({}) ;')); // ES5: 42 | |
| 58 | |
| 59 assertEquals(1, eval('42; with ({}) 1;')); | |
| 60 | |
| 61 | |
| 62 // SwitchStatement [13.12.11] | |
| 63 | |
| 64 assertUndef(eval('42; switch (0) {};')); // ES5: 42 | |
| 65 assertUndef(eval('42; switch (0) { case 1: 1; };')); // ES5: 42 | |
| 66 assertUndef(eval('42; switch (0) { case 0: ; };')); // ES5: 42 | |
| 67 assertUndef(eval('42; switch (0) { default: ; };')); // ES5: 42 | |
| 68 assertUndef(eval('42; switch (0) { case 0: break; }')); // ES5: 42 | |
| 69 | |
| 70 assertEquals(1, eval('42; switch (0) { case 0: 1; }')); | |
| 71 assertEquals(1, eval('42; switch (0) { case 0: 1; break; }')); | |
| 72 assertEquals(1, eval('42; switch (0) { case 0: 1; case 666: break; }')); | |
| 73 assertEquals(2, eval('42; switch (0) { case 0: 1; case 666: 2; break; }')); | |
| 74 | |
| 75 | |
| 76 // TryStatement [13.15.8] | |
| 77 | |
| 78 assertUndef(eval('42; try { } catch(e) { };')); // ES5: 42 | |
| 79 assertUndef(eval('42; try { } catch(e) { 0; };')); // ES5: 42 | |
| 80 assertUndef(eval('42; try { throw Error } catch(e) { };')); // ES5: 42 | |
| 81 assertUndef(eval('42; try { throw Error } catch(e) { } finally { };')); // ES5: 42 | |
|
rossberg
2015/10/07 12:28:46
Nit: Add one for finally without catch
neis
2015/10/08 12:57:25
Done.
| |
| 82 | |
| 83 | |
| 84 // Some combinations | |
| 85 | |
| 86 assertUndef(eval('42; switch (0) { case 0: if (true) break; }')); // ES5: 42 | |
| 87 assertUndef(eval('42; switch (0) { case 0: 1; if (true) ; }')); // ES5: 1 | |
| 88 assertUndef(eval('42; switch (0) { case 0: 1; try { break } catch(e) { }; }')); // ES5: 1 | |
| 89 | |
| 90 assertEquals(0, eval('42; switch (0) { case 0: 0; case 1: break; }')); | |
| 91 assertEquals(0, eval('42; while (1) { 0; break; }')) | |
| 92 assertEquals(0, eval('42; bla: while (1) { 0; break bla; }')) | |
| 93 assertEquals(0, eval('42; while (1) { with ({}) { 0; break; } }')) | |
| 94 assertEquals(0, eval('42; while (1) { try { 0; break } catch(e) {666} }')) | |
| 95 assertEquals(0, eval( | |
| 96 '42; while (1) { try { 0; break } catch(e) {666} finally {666} }')) | |
| 97 assertEquals(0, eval( | |
| 98 '42; while (1) { try { throw "bla" } catch(e) {666} finally {0; break} }')) | |
|
rossberg
2015/10/07 12:28:46
Also:
'42; while (1) { try { 666 } finally {0; br
neis
2015/10/08 12:57:25
Good point. Done.
| |
| 99 assertEquals(0, eval( | |
| 100 '42; while (1) { try { throw "bla" } catch(e) {0; break} finally {666} }')) | |
| 101 assertEquals(undefined, eval( | |
| 102 'var b = 1; ' + | |
| 103 'outer: while (1) { while (1) { if (b--) 42; else break outer; }; 666 }')); | |
| 104 | |
| 105 // The following is not what ES6 says, but see ES bug 4540. | |
| 106 assertUndef(eval('42; switch (0) { case 0: 1; if (true) break; }')); // ES5: 1 | |
| 107 | |
| 108 | |
| 109 | |
| 110 //////////////////////////////////////////////////////////////////////////////// | |
| 111 // | |
| 112 // The following are copied from webkit/eval-throw-return.and adapted. | |
| 113 | |
| 114 function throwFunc() { | |
| 115 throw ""; | |
| 116 } | |
| 117 | |
| 118 function throwOnReturn(){ | |
| 119 1; | |
| 120 return throwFunc(); | |
| 121 } | |
| 122 | |
| 123 function twoFunc() { | |
| 124 2; | |
| 125 } | |
| 126 | |
| 127 assertEquals(1, eval("1;")); | |
| 128 assertUndef(eval("1; try { foo = [2,3,throwFunc(), 4]; } catch (e){}")); | |
| 129 assertUndef(eval("1; try { 2; throw ''; } catch (e){}")); | |
| 130 assertUndef(eval("1; try { 2; throwFunc(); } catch (e){}")); | |
| 131 assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {}")); | |
| 132 assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {4;}")); | |
| 133 assertUndef(eval("function blah() { 1; }; blah();")); | |
| 134 assertUndef(eval("var x = 1;")); | |
| 135 assertEquals(1, eval("if (true) { 1; } else { 2; }")); | |
| 136 assertEquals(2, eval("if (false) { 1; } else { 2; }")); | |
| 137 assertUndef(eval("try{1; if (true) { 2; throw ''; } else { 2; }} catch(e){}")); | |
| 138 assertEquals(2, eval("1; var i = 0; do { ++i; 2; } while(i!=1);")); | |
| 139 assertUndef(eval( | |
| 140 "try{1; var i = 0; do { ++i; 2; throw ''; } while (i!=1);} catch(e){}")); | |
| 141 assertUndef(eval("1; try{2; throwOnReturn();} catch(e){}")); | |
| 142 assertUndef(eval("1; twoFunc();")); | |
| 143 assertEquals(2, eval("1; with ( { a: 0 } ) { 2; }")); | |
| OLD | NEW |