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

Side by Side Diff: test/mjsunit/harmony/iterator-close.js

Issue 1695583003: [WIP] for-of iterator finalization (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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
« src/parsing/parser.cc ('K') | « src/parsing/parser.cc ('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 2016 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
6 function* g() { yield 42; return 88 };
7
8
9 // Return method is "undefined".
10 {
11 g.prototype.return = null;
12
13 assertEquals(undefined, (() => {
14 for (let x of g()) { break; }
15 })());
16
17 assertEquals(undefined, (() => {
18 for (x of g()) { break; }
19 })());
20
21 assertThrowsEquals(() => {
22 for (let x of g()) { throw 42; }
23 }, 42);
24
25 //assertThrowsEquals(() => {
26 // for (x of g()) { throw 42; }
27 //}, 42);
neis 2016/02/12 12:30:13 This and the other two commented out tests fail wi
28
29 assertEquals(42, (() => {
30 for (let x of g()) { return 42; }
31 })());
32
33 assertEquals(42, (() => {
34 for (x of g()) { return 42; }
35 })());
36
37 assertEquals(42, eval('for (let x of g()) { x; }'));
38
39 assertEquals(42, eval('for (let x of g()) { x; }'));
40 }
41
42
43 // Return method is not callable.
44 {
45 g.prototype.return = 666;
46
47 assertThrows(() => {
48 for (let x of g()) { break; }
49 }, TypeError);
50
51 assertThrows(() => {
52 for (x of g()) { break; }
53 }, TypeError);
54
55 assertThrows(() => {
56 for (let x of g()) { throw 666; }
57 }, TypeError);
58
59 assertThrows(() => {
60 for (x of g()) { throw 666; }
61 }, TypeError);
62
63 assertThrows(() => {
64 for (let x of g()) { return 666; }
65 }, TypeError);
66
67 assertThrows(() => {
68 for (x of g()) { return 666; }
69 }, TypeError);
70
71 assertEquals(42, eval('for (let x of g()) { x; }'));
72
73 assertEquals(42, eval('for (let x of g()) { x; }'));
74 }
75
76
77 // Return method does not return an object.
78 {
79 g.prototype.return = () => 666;
80
81 assertThrows(() => {
82 for (let x of g()) { break; }
83 }, TypeError);
84
85 assertThrows(() => {
86 for (x of g()) { break; }
87 }, TypeError);
88
89 assertThrows(() => {
90 for (let x of g()) { throw 666; }
91 }, TypeError);
92
93 assertThrows(() => {
94 for (x of g()) { throw 666; }
95 }, TypeError);
96
97 assertThrows(() => {
98 for (let x of g()) { return 666; }
99 }, TypeError);
100
101 assertThrows(() => {
102 for (x of g()) { return 666; }
103 }, TypeError);
104
105 assertEquals(42, eval('for (let x of g()) { x; }'));
106
107 assertEquals(42, eval('for (x of g()) { x; }'));
108 }
109
110
111 // Return method returns an object.
112 {
113 let log = [];
114 g.prototype.return = (...args) => { log.push(args); return {} };
115
116 log.length = 0;
117 for (let x of g()) { break; }
118 assertEquals([[]], log);
119
120 log.length = 0;
121 for (x of g()) { break; }
122 assertEquals([[]], log);
123
124 log.length = 0;
125 assertThrowsEquals(() => {
126 for (let x of g()) { throw 42; }
127 }, 42);
128 assertEquals([[]], log);
129
130 //log.length = 0;
131 //assertThrowsEquals(() => {
132 // for (x of g()) { throw 42; }
133 //}, 42);
134 //assertEquals([[]], log);
135
136 log.length = 0;
137 assertEquals(42, (() => {
138 for (let x of g()) { return 42; }
139 })());
140 assertEquals([[]], log);
141
142 log.length = 0;
143 assertEquals(42, (() => {
144 for (x of g()) { return 42; }
145 })());
146 assertEquals([[]], log);
147
148 log.length = 0;
149 assertEquals(42, eval('for (let x of g()) { x; }'));
150 assertEquals([], log);
151
152 log.length = 0;
153 assertEquals(42, eval('for (x of g()) { x; }'));
154 assertEquals([], log);
155 }
156
157
158 // Return method throws.
159 {
160 let log = [];
161 g.prototype.return = (...args) => { log.push(args); throw 23 };
162
163 log.length = 0;
164 assertThrowsEquals(() => {
165 for (let x of g()) { break; }
166 }, 23);
167 assertEquals([[]], log);
168
169 log.length = 0;
170 assertThrowsEquals(() => {
171 for (x of g()) { break; }
172 }, 23);
173 assertEquals([[]], log);
174
175 log.length = 0;
176 assertThrowsEquals(() => {
177 for (let x of g()) { throw 42; }
178 }, 42);
179 assertEquals([[]], log);
180
181 //log.length = 0;
182 //assertThrowsEquals(() => {
183 // for (x of g()) { throw 42; }
184 //}, 42);
185 //assertEquals([[]], log);
186
187 log.length = 0;
188 assertThrowsEquals(() => {
189 for (let x of g()) { return 42; }
190 }, 23);
191 assertEquals([[]], log);
192
193 log.length = 0;
194 assertThrowsEquals(() => {
195 for (x of g()) { return 42; }
196 }, 23);
197 assertEquals([[]], log);
198
199 log.length = 0;
200 assertEquals(42, eval('for (let x of g()) { x; }'));
201 assertEquals([], log);
202
203 log.length = 0;
204 assertEquals(42, eval('for (x of g()) { x; }'));
205 assertEquals([], log);
206 }
207
208
209 // TODO(neis):
210 // - tests with throw in next() etc
OLDNEW
« src/parsing/parser.cc ('K') | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698