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 | |
6 | |
7 | |
8 function assertUndef(x) { | |
rossberg
2015/10/05 11:33:00
Can we also have tests that check for the correct
neis
2015/10/07 11:58:40
I added some. There's also a bunch in harmony/bloc
| |
9 assertEquals(undefined, x); | |
10 } | |
11 | |
12 | |
13 // IfStatement [13.6.7] | |
14 assertUndef(eval('42; if (true) ; else 0;')); // ES5: 42 | |
15 assertUndef(eval('42; if (true) ;')); // ES5: 42 | |
16 assertUndef(eval('42; if (false) 0;')); // ES5: 42 | |
17 | |
18 | |
19 // IterationStatement [13.7] (a few of them) | |
20 assertUndef(eval('42; do ; while (false);')); // ES5: 42 | |
21 assertUndef(eval('42; var x = 1; do ; while (x--);')); // ES5: 42 | |
22 assertUndef(eval('42; while (false) 0;')); // ES5: 42 | |
23 assertUndef(eval('42; while (true) break;')); // ES5: 42 | |
24 assertUndef(eval('42; var x = 1; while (x--) ;')); // ES5: 42 | |
25 assertUndef(eval('42; for (; false; ) 0;')); // ES5: 42 | |
26 assertUndef(eval('42; for (var x = 1; x; x--) ;')); // ES5: 42 | |
rossberg
2015/10/05 11:33:00
No tests for for-let, for-of, for-in?
neis
2015/10/07 11:58:40
Done.
| |
27 | |
28 | |
29 // WithStatement [13.11.7] | |
30 assertUndef(eval('42; with ({}) ;')); // ES5: 42 | |
31 | |
32 | |
33 // SwitchStatement [13.12.11] | |
34 assertUndef(eval('42; switch (0) {};')); // ES5: 42 | |
35 assertUndef(eval('42; switch (0) { case 1: 1; };')); // ES5: 42 | |
36 assertUndef(eval('42; switch (0) { case 0: ; };')); // ES5: 42 | |
37 assertUndef(eval('42; switch (0) { default: ; };')); // ES5: 42 | |
38 assertUndef(eval('42; switch (0) { case 0: break; }')); // ES5: 42 | |
39 assertEquals(0, eval('42; switch (0) { case 0: 0; }')); | |
40 assertEquals(0, eval('42; switch (0) { case 0: 0; break; }')); | |
41 | |
42 | |
43 // TryStatement [13.15.8] | |
44 assertUndef(eval('42; try { } catch(e) { };')); // ES5: 42 | |
45 assertUndef(eval('42; try { } catch(e) { 0; };')); // ES5: 42 | |
46 assertUndef(eval('42; try { throw Error } catch(e) { };')); // ES5: 42 | |
47 assertUndef(eval('42; try { throw Error } catch(e) { } finally { };')); // ES5: 42 | |
48 | |
49 | |
50 // Some combinations | |
rossberg
2015/10/05 11:33:00
Can we have more of those? There probably are vari
neis
2015/10/07 11:58:40
Added some. There's also a bunch in harmony/block
| |
51 assertUndef(eval('42; switch (0) { case 0: if (true) break; }')); // ES5: 42 | |
52 assertUndef(eval('42; switch (0) { case 0: 0; if (true) ; }')); // ES5: 0 | |
53 assertUndef(eval('42; switch (0) { case 0: 0; try { break } catch(e) { }; }')); // ES5: 0 | |
54 | |
55 // The following is not what ES6 says, but see ES bug 4540. | |
56 assertUndef(eval('42; switch (0) { case 0: 0; if (true) break; }')); // ES5: 0 | |
57 | |
58 | |
59 | |
60 //////////////////////////////////////////////////////////////////////////////// / | |
rossberg
2015/10/05 11:33:00
Nit: line length
neis
2015/10/07 11:58:40
Done.
| |
61 // | |
62 // The following are copied from webkit/eval-throw-return.and adapted. | |
63 | |
64 function throwFunc() { | |
65 throw ""; | |
66 } | |
67 | |
68 function throwOnReturn(){ | |
69 1; | |
70 return throwFunc(); | |
71 } | |
72 | |
73 function twoFunc() { | |
74 2; | |
75 } | |
76 | |
77 assertEquals(1, eval("1;")); | |
78 assertUndef(eval("1; try { foo = [2,3,throwFunc(), 4]; } catch (e){}")); | |
79 assertUndef(eval("1; try { 2; throw ''; } catch (e){}")); | |
80 assertUndef(eval("1; try { 2; throwFunc(); } catch (e){}")); | |
81 assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {}")); | |
82 assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {4;}")); | |
83 assertUndef(eval("function blah() { 1; }; blah();")); | |
84 assertUndef(eval("var x = 1;")); | |
85 assertEquals(1, eval("if (true) { 1; } else { 2; }")); | |
86 assertEquals(2, eval("if (false) { 1; } else { 2; }")); | |
87 assertUndef(eval("try{1; if (true) { 2; throw ''; } else { 2; }} catch(e){}")); | |
88 assertEquals(2, eval("1; var i = 0; do { ++i; 2; } while(i!=1);")); | |
89 assertUndef(eval("try{1; var i = 0; do { ++i; 2; throw ''; } while(i!=1);} catch (e){}")); | |
rossberg
2015/10/05 11:33:00
Line length
neis
2015/10/07 11:58:40
Done.
| |
90 assertUndef(eval("1; try{2; throwOnReturn();} catch(e){}")); | |
91 assertUndef(eval("1; twoFunc();")); | |
92 assertEquals(2, eval("1; with ( { a: 0 } ) { 2; }")); | |
OLD | NEW |