Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: test/mjsunit/harmony/completion.js

Issue 1361403003: Implement ES6 completion semantics (--harmony-completion). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Proper rebase. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/block-for-sloppy.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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-sloppy-let --no-legacy-const
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 "" } catch(e) { };')); // ES5: 42
81 assertUndef(eval('42; try { throw "" } catch(e) { } finally { };')); // ES5: 42
82 assertUndef(eval('42; try { } finally { 666 };')); // ES5: 42
83
84
85 // Some combinations
86
87 assertUndef(eval('42; switch (0) { case 0: if (true) break; }')); // ES5: 42
88 assertUndef(eval('42; switch (0) { case 0: 1; if (true) ; }')); // ES5: 1
89 assertUndef(eval('42; switch (0) { case 0: 1; try { break } catch(e) { }; }')); // ES5: 1
90
91 assertEquals(0, eval('42; switch (0) { case 0: 0; case 1: break; }'));
92 assertEquals(0, eval('42; while (1) { 0; break; }'))
93 assertEquals(0, eval('42; bla: while (1) { 0; break bla; }'))
94 assertEquals(0, eval('42; while (1) { with ({}) { 0; break; } }'))
95 assertEquals(0, eval('42; while (1) { try { 0; break } catch(e) {666} }'))
96 assertEquals(0, eval(
97 '42; while (1) { try { 0; break } catch(e) {666} finally {666} }'))
98 assertEquals(0, eval(
99 '42; while (1) { try { throw "" } catch(e) {666} finally {0; break} }'))
100 assertEquals(0, eval(
101 '42; while (1) { try { throw "" } catch(e) {0; break} finally {666} }'))
102 assertEquals(0, eval(
103 '42; while (1) { try { 666 } finally {0; break} }'));
104 assertEquals(0, eval(
105 '42; while (1) { try { 666; break } finally {0; break} }'));
106 assertEquals(0, eval(
107 '42; lab: try { 666; break lab } finally {0; break lab}'));
108 assertEquals(undefined, eval(
109 'var b = 1; ' +
110 'outer: while (1) { while (1) { if (b--) 42; else break outer; }; 666 }'));
111
112 // The following is not what ES6 says, but see ES bug 4540.
113 assertUndef(eval('42; switch (0) { case 0: 1; if (true) break; }')); // ES5: 1
114
115
116
117 ////////////////////////////////////////////////////////////////////////////////
118 //
119 // The following are copied from webkit/eval-throw-return and adapted.
120
121 function throwFunc() {
122 throw "";
123 }
124
125 function throwOnReturn(){
126 1;
127 return throwFunc();
128 }
129
130 function twoFunc() {
131 2;
132 }
133
134 assertEquals(1, eval("1;"));
135 assertUndef(eval("1; try { foo = [2,3,throwFunc(), 4]; } catch (e){}"));
136 assertUndef(eval("1; try { 2; throw ''; } catch (e){}"));
137 assertUndef(eval("1; try { 2; throwFunc(); } catch (e){}"));
138 assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {}"));
139 assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {4;}"));
140 assertUndef(eval("function blah() { 1; }; blah();"));
141 assertUndef(eval("var x = 1;"));
142 assertEquals(1, eval("if (true) { 1; } else { 2; }"));
143 assertEquals(2, eval("if (false) { 1; } else { 2; }"));
144 assertUndef(eval("try{1; if (true) { 2; throw ''; } else { 2; }} catch(e){}"));
145 assertEquals(2, eval("1; var i = 0; do { ++i; 2; } while(i!=1);"));
146 assertUndef(eval(
147 "try{1; var i = 0; do { ++i; 2; throw ''; } while (i!=1);} catch(e){}"));
148 assertUndef(eval("1; try{2; throwOnReturn();} catch(e){}"));
149 assertUndef(eval("1; twoFunc();"));
150 assertEquals(2, eval("1; with ( { a: 0 } ) { 2; }"));
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/block-for-sloppy.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698