OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-iterator-close | 5 // Flags: --harmony-iterator-close |
6 | 6 |
| 7 |
7 function* g() { yield 42; return 88 }; | 8 function* g() { yield 42; return 88 }; |
8 | 9 |
9 | 10 |
10 // Return method is "undefined". | 11 // Return method is "undefined". |
11 { | 12 { |
12 g.prototype.return = null; | 13 g.prototype.return = null; |
13 | 14 |
| 15 |
| 16 assertEquals(undefined, (() => { |
| 17 for (var x of g()) { break; } |
| 18 })()); |
| 19 |
14 assertEquals(undefined, (() => { | 20 assertEquals(undefined, (() => { |
15 for (let x of g()) { break; } | 21 for (let x of g()) { break; } |
16 })()); | 22 })()); |
17 | 23 |
18 assertEquals(undefined, (() => { | 24 assertEquals(undefined, (() => { |
| 25 for (const x of g()) { break; } |
| 26 })()); |
| 27 |
| 28 assertEquals(undefined, (() => { |
19 for (x of g()) { break; } | 29 for (x of g()) { break; } |
20 })()); | 30 })()); |
21 | 31 |
| 32 |
| 33 assertThrowsEquals(() => { |
| 34 for (var x of g()) { throw 42; } |
| 35 }, 42); |
| 36 |
22 assertThrowsEquals(() => { | 37 assertThrowsEquals(() => { |
23 for (let x of g()) { throw 42; } | 38 for (let x of g()) { throw 42; } |
24 }, 42); | 39 }, 42); |
25 | 40 |
26 assertThrowsEquals(() => { | 41 assertThrowsEquals(() => { |
| 42 for (const x of g()) { throw 42; } |
| 43 }, 42); |
| 44 |
| 45 assertThrowsEquals(() => { |
27 for (x of g()) { throw 42; } | 46 for (x of g()) { throw 42; } |
28 }, 42); | 47 }, 42); |
29 | 48 |
| 49 |
| 50 assertEquals(42, (() => { |
| 51 for (var x of g()) { return 42; } |
| 52 })()); |
| 53 |
30 assertEquals(42, (() => { | 54 assertEquals(42, (() => { |
31 for (let x of g()) { return 42; } | 55 for (let x of g()) { return 42; } |
32 })()); | 56 })()); |
33 | 57 |
34 assertEquals(42, (() => { | 58 assertEquals(42, (() => { |
| 59 for (const x of g()) { return 42; } |
| 60 })()); |
| 61 |
| 62 assertEquals(42, (() => { |
35 for (x of g()) { return 42; } | 63 for (x of g()) { return 42; } |
36 })()); | 64 })()); |
37 | 65 |
| 66 |
| 67 assertEquals(42, eval('for (var x of g()) { x; }')); |
| 68 |
38 assertEquals(42, eval('for (let x of g()) { x; }')); | 69 assertEquals(42, eval('for (let x of g()) { x; }')); |
39 | 70 |
40 assertEquals(42, eval('for (let x of g()) { x; }')); | 71 assertEquals(42, eval('for (const x of g()) { x; }')); |
| 72 |
| 73 assertEquals(42, eval('for (x of g()) { x; }')); |
| 74 |
| 75 |
| 76 assertEquals(42, (() => { |
| 77 var [x] = g(); return x; |
| 78 })()); |
| 79 |
| 80 assertEquals(42, (() => { |
| 81 let [x] = g(); return x; |
| 82 })()); |
| 83 |
| 84 assertEquals(42, (() => { |
| 85 const [x] = g(); return x; |
| 86 })()); |
| 87 |
| 88 assertEquals(42, (() => { |
| 89 [x] = g(); return x; |
| 90 })()); |
| 91 |
| 92 assertEquals(42, |
| 93 (([x]) => x)(g()) |
| 94 ); |
41 } | 95 } |
42 | 96 |
43 | 97 |
44 // Return method is not callable. | 98 // Return method is not callable. |
45 { | 99 { |
46 g.prototype.return = 666; | 100 g.prototype.return = 666; |
47 | 101 |
| 102 |
| 103 assertThrows(() => { |
| 104 for (var x of g()) { break; } |
| 105 }, TypeError); |
| 106 |
48 assertThrows(() => { | 107 assertThrows(() => { |
49 for (let x of g()) { break; } | 108 for (let x of g()) { break; } |
50 }, TypeError); | 109 }, TypeError); |
51 | 110 |
52 assertThrows(() => { | 111 assertThrows(() => { |
| 112 for (const x of g()) { break; } |
| 113 }, TypeError); |
| 114 |
| 115 assertThrows(() => { |
53 for (x of g()) { break; } | 116 for (x of g()) { break; } |
54 }, TypeError); | 117 }, TypeError); |
55 | 118 |
| 119 |
| 120 assertThrows(() => { |
| 121 for (var x of g()) { throw 666; } |
| 122 }, TypeError); |
| 123 |
56 assertThrows(() => { | 124 assertThrows(() => { |
57 for (let x of g()) { throw 666; } | 125 for (let x of g()) { throw 666; } |
58 }, TypeError); | 126 }, TypeError); |
59 | 127 |
60 assertThrows(() => { | 128 assertThrows(() => { |
| 129 for (const x of g()) { throw 666; } |
| 130 }, TypeError); |
| 131 |
| 132 assertThrows(() => { |
61 for (x of g()) { throw 666; } | 133 for (x of g()) { throw 666; } |
62 }, TypeError); | 134 }, TypeError); |
63 | 135 |
| 136 |
| 137 assertThrows(() => { |
| 138 for (var x of g()) { return 666; } |
| 139 }, TypeError); |
| 140 |
64 assertThrows(() => { | 141 assertThrows(() => { |
65 for (let x of g()) { return 666; } | 142 for (let x of g()) { return 666; } |
66 }, TypeError); | 143 }, TypeError); |
67 | 144 |
68 assertThrows(() => { | 145 assertThrows(() => { |
| 146 for (const x of g()) { return 666; } |
| 147 }, TypeError); |
| 148 |
| 149 assertThrows(() => { |
69 for (x of g()) { return 666; } | 150 for (x of g()) { return 666; } |
70 }, TypeError); | 151 }, TypeError); |
71 | 152 |
| 153 |
| 154 assertEquals(42, eval('for (var x of g()) { x; }')); |
| 155 |
72 assertEquals(42, eval('for (let x of g()) { x; }')); | 156 assertEquals(42, eval('for (let x of g()) { x; }')); |
73 | 157 |
74 assertEquals(42, eval('for (let x of g()) { x; }')); | 158 assertEquals(42, eval('for (const x of g()) { x; }')); |
| 159 |
| 160 assertEquals(42, eval('for (x of g()) { x; }')); |
| 161 |
| 162 |
| 163 assertThrows(() => { |
| 164 var [x] = g(); return x; |
| 165 }, TypeError); |
| 166 |
| 167 assertThrows(() => { |
| 168 let [x] = g(); return x; |
| 169 }, TypeError); |
| 170 |
| 171 assertThrows(() => { |
| 172 const [x] = g(); return x; |
| 173 }, TypeError); |
| 174 |
| 175 assertThrows(() => { |
| 176 [x] = g(); return x; |
| 177 }, TypeError); |
| 178 |
| 179 assertThrows(() => { |
| 180 (([x]) => x)(g()); |
| 181 }, TypeError); |
75 } | 182 } |
76 | 183 |
77 | 184 |
78 // Return method does not return an object. | 185 // Return method does not return an object. |
79 { | 186 { |
80 g.prototype.return = () => 666; | 187 g.prototype.return = () => 666; |
81 | 188 |
| 189 |
| 190 assertThrows(() => { |
| 191 for (var x of g()) { break; } |
| 192 }, TypeError); |
| 193 |
82 assertThrows(() => { | 194 assertThrows(() => { |
83 for (let x of g()) { break; } | 195 for (let x of g()) { break; } |
84 }, TypeError); | 196 }, TypeError); |
85 | 197 |
86 assertThrows(() => { | 198 assertThrows(() => { |
| 199 for (const x of g()) { break; } |
| 200 }, TypeError); |
| 201 |
| 202 assertThrows(() => { |
87 for (x of g()) { break; } | 203 for (x of g()) { break; } |
88 }, TypeError); | 204 }, TypeError); |
89 | 205 |
| 206 |
90 // Throw from the body of a for loop 'wins' vs throw | 207 // Throw from the body of a for loop 'wins' vs throw |
91 // originating from a bad 'return' value. | 208 // originating from a bad 'return' value. |
| 209 |
| 210 assertThrowsEquals(() => { |
| 211 for (var x of g()) { throw 666; } |
| 212 }, 666); |
| 213 |
92 assertThrowsEquals(() => { | 214 assertThrowsEquals(() => { |
93 for (let x of g()) { throw 666; } | 215 for (let x of g()) { throw 666; } |
94 }, 666); | 216 }, 666); |
95 | 217 |
96 assertThrowsEquals(() => { | 218 assertThrowsEquals(() => { |
| 219 for (const x of g()) { throw 666; } |
| 220 }, 666); |
| 221 |
| 222 assertThrowsEquals(() => { |
97 for (x of g()) { throw 666; } | 223 for (x of g()) { throw 666; } |
98 }, 666); | 224 }, 666); |
99 | 225 |
| 226 |
| 227 assertThrows(() => { |
| 228 for (var x of g()) { return 666; } |
| 229 }, TypeError); |
| 230 |
100 assertThrows(() => { | 231 assertThrows(() => { |
101 for (let x of g()) { return 666; } | 232 for (let x of g()) { return 666; } |
102 }, TypeError); | 233 }, TypeError); |
103 | 234 |
104 assertThrows(() => { | 235 assertThrows(() => { |
| 236 for (const x of g()) { return 666; } |
| 237 }, TypeError); |
| 238 |
| 239 assertThrows(() => { |
105 for (x of g()) { return 666; } | 240 for (x of g()) { return 666; } |
106 }, TypeError); | 241 }, TypeError); |
107 | 242 |
| 243 |
| 244 assertEquals(42, eval('for (var x of g()) { x; }')); |
| 245 |
108 assertEquals(42, eval('for (let x of g()) { x; }')); | 246 assertEquals(42, eval('for (let x of g()) { x; }')); |
109 | 247 |
| 248 assertEquals(42, eval('for (const x of g()) { x; }')); |
| 249 |
110 assertEquals(42, eval('for (x of g()) { x; }')); | 250 assertEquals(42, eval('for (x of g()) { x; }')); |
| 251 |
| 252 |
| 253 assertThrows(() => { |
| 254 var [x] = g(); return x; |
| 255 }, TypeError); |
| 256 |
| 257 assertThrows(() => { |
| 258 let [x] = g(); return x; |
| 259 }, TypeError); |
| 260 |
| 261 assertThrows(() => { |
| 262 const [x] = g(); return x; |
| 263 }, TypeError); |
| 264 |
| 265 assertThrows(() => { |
| 266 [x] = g(); return x; |
| 267 }, TypeError); |
| 268 |
| 269 assertThrows(() => { |
| 270 (([x]) => x)(g()); |
| 271 }, TypeError); |
111 } | 272 } |
112 | 273 |
113 | 274 |
114 // Return method returns an object. | 275 // Return method returns an object. |
115 { | 276 { |
116 let log = []; | 277 let log = []; |
117 g.prototype.return = (...args) => { log.push(args); return {} }; | 278 g.prototype.return = (...args) => { log.push(args); return {} }; |
118 | 279 |
| 280 |
| 281 log = []; |
| 282 for (var x of g()) { break; } |
| 283 assertEquals([[]], log); |
| 284 |
119 log = []; | 285 log = []; |
120 for (let x of g()) { break; } | 286 for (let x of g()) { break; } |
121 assertEquals([[]], log); | 287 assertEquals([[]], log); |
122 | 288 |
123 log = []; | 289 log = []; |
| 290 for (const x of g()) { break; } |
| 291 assertEquals([[]], log); |
| 292 |
| 293 log = []; |
124 for (x of g()) { break; } | 294 for (x of g()) { break; } |
125 assertEquals([[]], log); | 295 assertEquals([[]], log); |
126 | 296 |
| 297 |
| 298 log = []; |
| 299 assertThrowsEquals(() => { |
| 300 for (var x of g()) { throw 42; } |
| 301 }, 42); |
| 302 assertEquals([[]], log); |
| 303 |
127 log = []; | 304 log = []; |
128 assertThrowsEquals(() => { | 305 assertThrowsEquals(() => { |
129 for (let x of g()) { throw 42; } | 306 for (let x of g()) { throw 42; } |
130 }, 42); | 307 }, 42); |
131 assertEquals([[]], log); | 308 assertEquals([[]], log); |
132 | 309 |
133 log = []; | 310 log = []; |
134 assertThrowsEquals(() => { | 311 assertThrowsEquals(() => { |
| 312 for (const x of g()) { throw 42; } |
| 313 }, 42); |
| 314 assertEquals([[]], log); |
| 315 |
| 316 log = []; |
| 317 assertThrowsEquals(() => { |
135 for (x of g()) { throw 42; } | 318 for (x of g()) { throw 42; } |
136 }, 42); | 319 }, 42); |
137 assertEquals([[]], log); | 320 assertEquals([[]], log); |
138 | 321 |
| 322 |
| 323 log = []; |
| 324 assertEquals(42, (() => { |
| 325 for (var x of g()) { return 42; } |
| 326 })()); |
| 327 assertEquals([[]], log); |
| 328 |
139 log = []; | 329 log = []; |
140 assertEquals(42, (() => { | 330 assertEquals(42, (() => { |
141 for (let x of g()) { return 42; } | 331 for (let x of g()) { return 42; } |
142 })()); | 332 })()); |
143 assertEquals([[]], log); | 333 assertEquals([[]], log); |
144 | 334 |
145 log = []; | 335 log = []; |
146 assertEquals(42, (() => { | 336 assertEquals(42, (() => { |
| 337 for (const x of g()) { return 42; } |
| 338 })()); |
| 339 assertEquals([[]], log); |
| 340 |
| 341 log = []; |
| 342 assertEquals(42, (() => { |
147 for (x of g()) { return 42; } | 343 for (x of g()) { return 42; } |
148 })()); | 344 })()); |
149 assertEquals([[]], log); | 345 assertEquals([[]], log); |
150 | 346 |
| 347 |
| 348 log = []; |
| 349 assertEquals(42, eval('for (var x of g()) { x; }')); |
| 350 assertEquals([], log); |
| 351 |
151 log = []; | 352 log = []; |
152 assertEquals(42, eval('for (let x of g()) { x; }')); | 353 assertEquals(42, eval('for (let x of g()) { x; }')); |
153 assertEquals([], log); | 354 assertEquals([], log); |
154 | 355 |
155 log = []; | 356 log = []; |
| 357 assertEquals(42, eval('for (const x of g()) { x; }')); |
| 358 assertEquals([], log); |
| 359 |
| 360 log = []; |
156 assertEquals(42, eval('for (x of g()) { x; }')); | 361 assertEquals(42, eval('for (x of g()) { x; }')); |
157 assertEquals([], log); | 362 assertEquals([], log); |
158 | 363 |
| 364 |
159 // Even if doing the assignment throws, still call return | 365 // Even if doing the assignment throws, still call return |
| 366 log = []; |
160 x = { set attr(_) { throw 1234; } }; | 367 x = { set attr(_) { throw 1234; } }; |
161 assertThrowsEquals(() => { | 368 assertThrowsEquals(() => { |
162 for (x.attr of g()) { throw 456; } | 369 for (x.attr of g()) { throw 456; } |
163 }, 1234); | 370 }, 1234); |
164 assertEquals([[]], log); | 371 assertEquals([[]], log); |
| 372 |
| 373 |
| 374 log = []; |
| 375 assertEquals(42, (() => { |
| 376 var [x] = g(); return x; |
| 377 })()); |
| 378 assertEquals([[]], log); |
| 379 |
| 380 log = []; |
| 381 assertEquals(42, (() => { |
| 382 let [x] = g(); return x; |
| 383 })()); |
| 384 assertEquals([[]], log); |
| 385 |
| 386 log = []; |
| 387 assertEquals(42, (() => { |
| 388 const [x] = g(); return x; |
| 389 })()); |
| 390 assertEquals([[]], log); |
| 391 |
| 392 log = []; |
| 393 assertEquals(42, (() => { |
| 394 [x] = g(); return x; |
| 395 })()); |
| 396 assertEquals([[]], log); |
| 397 |
| 398 log = [] |
| 399 assertEquals(42, |
| 400 (([x]) => x)(g()) |
| 401 ); |
| 402 assertEquals([[]], log); |
| 403 |
| 404 |
| 405 log = []; |
| 406 assertEquals(42, (() => { |
| 407 var [x,] = g(); return x; |
| 408 })()); |
| 409 assertEquals([[]], log); |
| 410 |
| 411 log = []; |
| 412 assertEquals(42, (() => { |
| 413 let [x,] = g(); return x; |
| 414 })()); |
| 415 assertEquals([[]], log); |
| 416 |
| 417 log = []; |
| 418 assertEquals(42, (() => { |
| 419 const [x,] = g(); return x; |
| 420 })()); |
| 421 assertEquals([[]], log); |
| 422 |
| 423 log = []; |
| 424 assertEquals(42, (() => { |
| 425 [x,] = g(); return x; |
| 426 })()); |
| 427 assertEquals([[]], log); |
| 428 |
| 429 log = [] |
| 430 assertEquals(42, |
| 431 (([x,]) => x)(g()) |
| 432 ); |
| 433 assertEquals([[]], log); |
| 434 |
| 435 |
| 436 log = []; |
| 437 assertEquals(42, (() => { |
| 438 var [x,,] = g(); return x; |
| 439 })()); |
| 440 assertEquals([], log); |
| 441 |
| 442 log = []; |
| 443 assertEquals(42, (() => { |
| 444 let [x,,] = g(); return x; |
| 445 })()); |
| 446 assertEquals([], log); |
| 447 |
| 448 log = []; |
| 449 assertEquals(42, (() => { |
| 450 const [x,,] = g(); return x; |
| 451 })()); |
| 452 assertEquals([], log); |
| 453 |
| 454 log = []; |
| 455 assertEquals(42, (() => { |
| 456 [x,,] = g(); return x; |
| 457 })()); |
| 458 assertEquals([], log); |
| 459 |
| 460 log = [] |
| 461 assertEquals(42, |
| 462 (([x,,]) => x)(g()) |
| 463 ); |
| 464 assertEquals([], log); |
| 465 |
| 466 |
| 467 log = []; |
| 468 assertEquals([42, undefined], (() => { |
| 469 var [x, y] = g(); return [x, y]; |
| 470 })()); |
| 471 assertEquals([], log); |
| 472 |
| 473 log = []; |
| 474 assertEquals([42, undefined], (() => { |
| 475 let [x, y] = g(); return [x, y]; |
| 476 })()); |
| 477 assertEquals([], log); |
| 478 |
| 479 log = []; |
| 480 assertEquals([42, undefined], (() => { |
| 481 const [x, y] = g(); return [x, y]; |
| 482 })()); |
| 483 assertEquals([], log); |
| 484 |
| 485 log = []; |
| 486 assertEquals([42, undefined], (() => { |
| 487 [x, y] = g(); return [x, y]; |
| 488 })()); |
| 489 assertEquals([], log); |
| 490 |
| 491 log = [] |
| 492 assertEquals([42, undefined], |
| 493 (([x, y]) => [x, y])(g()) |
| 494 ); |
| 495 assertEquals([], log); |
| 496 |
| 497 |
| 498 log = []; |
| 499 assertEquals([42], (() => { |
| 500 var [...x] = g(); return x; |
| 501 })()); |
| 502 assertEquals([], log); |
| 503 |
| 504 log = []; |
| 505 assertEquals([42], (() => { |
| 506 let [...x] = g(); return x; |
| 507 })()); |
| 508 assertEquals([], log); |
| 509 |
| 510 log = []; |
| 511 assertEquals([42], (() => { |
| 512 const [...x] = g(); return x; |
| 513 })()); |
| 514 assertEquals([], log); |
| 515 |
| 516 log = []; |
| 517 assertEquals([42], (() => { |
| 518 [...x] = g(); return x; |
| 519 })()); |
| 520 assertEquals([], log); |
| 521 |
| 522 log = [] |
| 523 assertEquals([42], |
| 524 (([...x]) => x)(g()) |
| 525 ); |
| 526 assertEquals([], log); |
| 527 |
| 528 |
| 529 log = []; |
| 530 assertEquals([42, []], (() => { |
| 531 var [x, ...y] = g(); return [x, y]; |
| 532 })()); |
| 533 assertEquals([], log); |
| 534 |
| 535 log = []; |
| 536 assertEquals([42, []], (() => { |
| 537 let [x, ...y] = g(); return [x, y]; |
| 538 })()); |
| 539 assertEquals([], log); |
| 540 |
| 541 log = []; |
| 542 assertEquals([42, []], (() => { |
| 543 const [x, ...y] = g(); return [x, y]; |
| 544 })()); |
| 545 assertEquals([], log); |
| 546 |
| 547 log = []; |
| 548 assertEquals([42, []], (() => { |
| 549 [x, ...y] = g(); return [x, y]; |
| 550 })()); |
| 551 assertEquals([], log); |
| 552 |
| 553 log = [] |
| 554 assertEquals([42, []], |
| 555 (([x, ...y]) => [x, y])(g()) |
| 556 ); |
| 557 assertEquals([], log); |
| 558 |
| 559 |
| 560 log = []; |
| 561 assertEquals([], (() => { |
| 562 var [] = g(); return []; |
| 563 })()); |
| 564 assertEquals([[]], log); |
| 565 |
| 566 log = []; |
| 567 assertEquals([], (() => { |
| 568 let [] = g(); return []; |
| 569 })()); |
| 570 assertEquals([[]], log); |
| 571 |
| 572 log = []; |
| 573 assertEquals([], (() => { |
| 574 const [] = g(); return []; |
| 575 })()); |
| 576 assertEquals([[]], log); |
| 577 |
| 578 log = []; |
| 579 assertEquals([], (() => { |
| 580 [] = g(); return []; |
| 581 })()); |
| 582 assertEquals([[]], log); |
| 583 |
| 584 log = [] |
| 585 assertEquals([], |
| 586 (([]) => [])(g()) |
| 587 ); |
| 588 assertEquals([[]], log); |
| 589 |
| 590 |
| 591 log = []; |
| 592 assertEquals([], (() => { |
| 593 var [...[]] = g(); return []; |
| 594 })()); |
| 595 assertEquals([], log); |
| 596 |
| 597 log = []; |
| 598 assertEquals([], (() => { |
| 599 let [...[]] = g(); return []; |
| 600 })()); |
| 601 assertEquals([], log); |
| 602 |
| 603 log = []; |
| 604 assertEquals([], (() => { |
| 605 const [...[]] = g(); return []; |
| 606 })()); |
| 607 assertEquals([], log); |
| 608 |
| 609 log = []; |
| 610 assertEquals([], (() => { |
| 611 [...[]] = g(); return []; |
| 612 })()); |
| 613 assertEquals([], log); |
| 614 |
| 615 log = [] |
| 616 assertEquals([], |
| 617 (([...[]]) => [])(g()) |
| 618 ); |
| 619 assertEquals([], log); |
| 620 |
| 621 |
| 622 log = []; |
| 623 assertEquals([42], (() => { |
| 624 var [...[x]] = g(); return [x]; |
| 625 })()); |
| 626 assertEquals([], log); |
| 627 |
| 628 log = []; |
| 629 assertEquals([42], (() => { |
| 630 let [...[x]] = g(); return [x]; |
| 631 })()); |
| 632 assertEquals([], log); |
| 633 |
| 634 log = []; |
| 635 assertEquals([42], (() => { |
| 636 const [...[x]] = g(); return [x]; |
| 637 })()); |
| 638 assertEquals([], log); |
| 639 |
| 640 log = []; |
| 641 assertEquals([42], (() => { |
| 642 [...[x]] = g(); return [x]; |
| 643 })()); |
| 644 assertEquals([], log); |
| 645 |
| 646 log = [] |
| 647 assertEquals([42], |
| 648 (([...[x]]) => [x])(g()) |
| 649 ); |
| 650 assertEquals([], log); |
| 651 |
| 652 |
| 653 log = []; |
| 654 assertEquals([42, undefined], (() => { |
| 655 var [...[x, y]] = g(); return [x, y]; |
| 656 })()); |
| 657 assertEquals([], log); |
| 658 |
| 659 log = []; |
| 660 assertEquals([42, undefined], (() => { |
| 661 let [...[x, y]] = g(); return [x, y]; |
| 662 })()); |
| 663 assertEquals([], log); |
| 664 |
| 665 log = []; |
| 666 assertEquals([42, undefined], (() => { |
| 667 const [...[x, y]] = g(); return [x, y]; |
| 668 })()); |
| 669 assertEquals([], log); |
| 670 |
| 671 log = []; |
| 672 assertEquals([42, undefined], (() => { |
| 673 [...[x, y]] = g(); return [x, y]; |
| 674 })()); |
| 675 assertEquals([], log); |
| 676 |
| 677 log = [] |
| 678 assertEquals([42, undefined], |
| 679 (([...[x, y]]) => [x, y])(g()) |
| 680 ); |
| 681 assertEquals([], log); |
| 682 |
| 683 |
| 684 log = [] |
| 685 assertThrowsEquals(() => { |
| 686 let x = { set foo(_) { throw 666; } }; |
| 687 [x.foo] = g(); |
| 688 }, 666); |
| 689 assertEquals([[]], log); |
| 690 |
| 691 |
| 692 log = [] |
| 693 assertThrows(() => { |
| 694 var [[]] = g(); |
| 695 }, TypeError); |
| 696 assertEquals([[]], log); |
| 697 |
| 698 log = [] |
| 699 assertThrows(() => { |
| 700 let [[]] = g(); |
| 701 }, TypeError); |
| 702 assertEquals([[]], log); |
| 703 |
| 704 log = [] |
| 705 assertThrows(() => { |
| 706 const [[]] = g(); |
| 707 }, TypeError); |
| 708 assertEquals([[]], log); |
| 709 |
| 710 log = [] |
| 711 assertThrows(() => { |
| 712 [[]] = g(); |
| 713 }, TypeError); |
| 714 assertEquals([[]], log); |
| 715 |
| 716 log = [] |
| 717 assertThrows(() => { |
| 718 (([[]]) => 0)(g()); |
| 719 }, TypeError); |
| 720 assertEquals([[]], log); |
| 721 |
| 722 |
| 723 log = [] |
| 724 assertThrows(() => { |
| 725 var [...[[]]] = g(); |
| 726 }, TypeError); |
| 727 assertEquals([], log); |
| 728 |
| 729 log = [] |
| 730 assertThrows(() => { |
| 731 let [...[[]]] = g(); |
| 732 }, TypeError); |
| 733 assertEquals([], log); |
| 734 |
| 735 log = [] |
| 736 assertThrows(() => { |
| 737 const [...[[]]] = g(); |
| 738 }, TypeError); |
| 739 assertEquals([], log); |
| 740 |
| 741 log = [] |
| 742 assertThrows(() => { |
| 743 [...[[]]] = g(); |
| 744 }, TypeError); |
| 745 assertEquals([], log); |
| 746 |
| 747 log = [] |
| 748 assertThrows(() => { |
| 749 (([...[[]]]) => 0)(g()); |
| 750 }, TypeError); |
| 751 assertEquals([], log); |
| 752 |
| 753 |
| 754 { |
| 755 let backup = Array.prototype[Symbol.iterator]; |
| 756 Array.prototype[Symbol.iterator] = () => g(); |
| 757 |
| 758 |
| 759 log = []; |
| 760 assertDoesNotThrow(() => { |
| 761 var [x, ...[y]] = [1, 2, 3] |
| 762 }); |
| 763 assertEquals(log, [[]]); |
| 764 |
| 765 log = []; |
| 766 assertDoesNotThrow(() => { |
| 767 let [x, ...[y]] = [1, 2, 3]; |
| 768 }); |
| 769 assertEquals(log, [[]]); |
| 770 |
| 771 log = []; |
| 772 assertDoesNotThrow(() => { |
| 773 const [x, ...[y]] = [1, 2, 3]; |
| 774 }); |
| 775 assertEquals(log, [[]]); |
| 776 |
| 777 log = []; |
| 778 assertDoesNotThrow(() => { |
| 779 (([x, ...[y]]) => {})([1, 2, 3]); |
| 780 }); |
| 781 assertEquals(log, [[]]); |
| 782 |
| 783 |
| 784 log = []; |
| 785 assertThrows(() => { |
| 786 var [x, ...[[]]] = [1, 2, 3]; |
| 787 }, TypeError); |
| 788 assertEquals(log, [[]]); |
| 789 |
| 790 log = []; |
| 791 assertThrows(() => { |
| 792 let [x, ...[[]]] = [1, 2, 3]; |
| 793 }, TypeError); |
| 794 assertEquals(log, [[]]); |
| 795 |
| 796 log = []; |
| 797 assertThrows(() => { |
| 798 const [x, ...[[]]] = [1, 2, 3]; |
| 799 }, TypeError); |
| 800 assertEquals(log, [[]]); |
| 801 |
| 802 log = []; |
| 803 assertThrows(() => { |
| 804 (([x, ...[[]]]) => {})([1, 2, 3]); |
| 805 }, TypeError); |
| 806 assertEquals(log, [[]]); |
| 807 |
| 808 |
| 809 log = []; |
| 810 assertDoesNotThrow(() => { |
| 811 var [x, ...[...y]] = [1, 2, 3]; |
| 812 }); |
| 813 assertEquals(log, []); |
| 814 |
| 815 log = []; |
| 816 assertDoesNotThrow(() => { |
| 817 let [x, ...[...y]] = [1, 2, 3]; |
| 818 }); |
| 819 assertEquals(log, []); |
| 820 |
| 821 log = []; |
| 822 assertDoesNotThrow(() => { |
| 823 const [x, ...[...y]] = [1, 2, 3]; |
| 824 }); |
| 825 assertEquals(log, []); |
| 826 |
| 827 log = []; |
| 828 assertDoesNotThrow(() => { |
| 829 (([x, ...[...y]]) => {})([1, 2, 3]); |
| 830 }); |
| 831 assertEquals(log, []); |
| 832 |
| 833 |
| 834 Array.prototype[Symbol.iterator] = backup; |
| 835 } |
165 } | 836 } |
166 | 837 |
167 | 838 |
168 // Return method throws. | 839 // Return method throws. |
169 { | 840 { |
170 let log = []; | 841 let log = []; |
171 g.prototype.return = (...args) => { log.push(args); throw 23 }; | 842 g.prototype.return = (...args) => { log.push(args); throw 23 }; |
172 | 843 |
| 844 |
| 845 log = []; |
| 846 assertThrowsEquals(() => { |
| 847 for (var x of g()) { break; } |
| 848 }, 23); |
| 849 assertEquals([[]], log); |
| 850 |
173 log = []; | 851 log = []; |
174 assertThrowsEquals(() => { | 852 assertThrowsEquals(() => { |
175 for (let x of g()) { break; } | 853 for (let x of g()) { break; } |
176 }, 23); | 854 }, 23); |
177 assertEquals([[]], log); | 855 assertEquals([[]], log); |
178 | 856 |
179 log = []; | 857 log = []; |
180 assertThrowsEquals(() => { | 858 assertThrowsEquals(() => { |
| 859 for (const x of g()) { break; } |
| 860 }, 23); |
| 861 assertEquals([[]], log); |
| 862 |
| 863 log = []; |
| 864 assertThrowsEquals(() => { |
181 for (x of g()) { break; } | 865 for (x of g()) { break; } |
182 }, 23); | 866 }, 23); |
183 assertEquals([[]], log); | 867 assertEquals([[]], log); |
184 | 868 |
| 869 |
| 870 log = []; |
| 871 assertThrowsEquals(() => { |
| 872 for (var x of g()) { throw 42; } |
| 873 }, 42); |
| 874 assertEquals([[]], log); |
| 875 |
185 log = []; | 876 log = []; |
186 assertThrowsEquals(() => { | 877 assertThrowsEquals(() => { |
187 for (let x of g()) { throw 42; } | 878 for (let x of g()) { throw 42; } |
188 }, 42); | 879 }, 42); |
189 assertEquals([[]], log); | 880 assertEquals([[]], log); |
190 | 881 |
191 log = []; | 882 log = []; |
192 assertThrowsEquals(() => { | 883 assertThrowsEquals(() => { |
| 884 for (const x of g()) { throw 42; } |
| 885 }, 42); |
| 886 assertEquals([[]], log); |
| 887 |
| 888 log = []; |
| 889 assertThrowsEquals(() => { |
193 for (x of g()) { throw 42; } | 890 for (x of g()) { throw 42; } |
194 }, 42); | 891 }, 42); |
195 assertEquals([[]], log); | 892 assertEquals([[]], log); |
196 | 893 |
| 894 |
| 895 log = []; |
| 896 assertThrowsEquals(() => { |
| 897 for (var x of g()) { return 42; } |
| 898 }, 23); |
| 899 assertEquals([[]], log); |
| 900 |
197 log = []; | 901 log = []; |
198 assertThrowsEquals(() => { | 902 assertThrowsEquals(() => { |
199 for (let x of g()) { return 42; } | 903 for (let x of g()) { return 42; } |
200 }, 23); | 904 }, 23); |
201 assertEquals([[]], log); | 905 assertEquals([[]], log); |
202 | 906 |
203 log = []; | 907 log = []; |
204 assertThrowsEquals(() => { | 908 assertThrowsEquals(() => { |
| 909 for (const x of g()) { return 42; } |
| 910 }, 23); |
| 911 assertEquals([[]], log); |
| 912 |
| 913 log = []; |
| 914 assertThrowsEquals(() => { |
205 for (x of g()) { return 42; } | 915 for (x of g()) { return 42; } |
206 }, 23); | 916 }, 23); |
207 assertEquals([[]], log); | 917 assertEquals([[]], log); |
208 | 918 |
| 919 |
| 920 log = []; |
| 921 assertEquals(42, eval('for (var x of g()) { x; }')); |
| 922 assertEquals([], log); |
| 923 |
209 log = []; | 924 log = []; |
210 assertEquals(42, eval('for (let x of g()) { x; }')); | 925 assertEquals(42, eval('for (let x of g()) { x; }')); |
211 assertEquals([], log); | 926 assertEquals([], log); |
212 | 927 |
213 log = []; | 928 log = []; |
| 929 assertEquals(42, eval('for (const x of g()) { x; }')); |
| 930 assertEquals([], log); |
| 931 |
| 932 log = []; |
214 assertEquals(42, eval('for (x of g()) { x; }')); | 933 assertEquals(42, eval('for (x of g()) { x; }')); |
215 assertEquals([], log); | 934 assertEquals([], log); |
| 935 |
| 936 |
| 937 log = []; |
| 938 assertThrowsEquals(() => { |
| 939 var [x] = g(); return x; |
| 940 }, 23); |
| 941 assertEquals([[]], log); |
| 942 |
| 943 log = []; |
| 944 assertThrowsEquals(() => { |
| 945 let [x] = g(); return x; |
| 946 }, 23); |
| 947 assertEquals([[]], log); |
| 948 |
| 949 log = []; |
| 950 assertThrowsEquals(() => { |
| 951 const [x] = g(); return x; |
| 952 }, 23); |
| 953 assertEquals([[]], log); |
| 954 |
| 955 log = []; |
| 956 assertThrowsEquals(() => { |
| 957 [x] = g(); return x; |
| 958 }, 23); |
| 959 assertEquals([[]], log); |
| 960 |
| 961 log = []; |
| 962 assertThrowsEquals(() => { |
| 963 (([x]) => x)(g()) |
| 964 }, 23); |
| 965 assertEquals([[]], log); |
216 } | 966 } |
217 | 967 |
218 | 968 |
219 // Next method throws. | 969 // Next method throws. |
220 { | 970 { |
221 g.prototype.next = () => { throw 666; }; | 971 g.prototype.next = () => { throw 666; }; |
222 g.prototype.return = () => { assertUnreachable() }; | 972 g.prototype.return = () => { assertUnreachable() }; |
223 | 973 |
| 974 |
| 975 assertThrowsEquals(() => { |
| 976 for (var x of g()) {} |
| 977 }, 666); |
| 978 |
224 assertThrowsEquals(() => { | 979 assertThrowsEquals(() => { |
225 for (let x of g()) {} | 980 for (let x of g()) {} |
226 }, 666); | 981 }, 666); |
227 | 982 |
228 assertThrowsEquals(() => { | 983 assertThrowsEquals(() => { |
| 984 for (const x of g()) {} |
| 985 }, 666); |
| 986 |
| 987 assertThrowsEquals(() => { |
229 for (x of g()) {} | 988 for (x of g()) {} |
230 }, 666); | 989 }, 666); |
| 990 |
| 991 assertThrowsEquals(() => { |
| 992 var [x] = g(); |
| 993 }, 666); |
| 994 |
| 995 assertThrowsEquals(() => { |
| 996 let [x] = g(); |
| 997 }, 666); |
| 998 |
| 999 assertThrowsEquals(() => { |
| 1000 const [x] = g(); |
| 1001 }, 666); |
| 1002 |
| 1003 assertThrowsEquals(() => { |
| 1004 [x] = g(); |
| 1005 }, 666); |
| 1006 |
| 1007 assertThrowsEquals(() => { |
| 1008 (([x]) => x)(g()); |
| 1009 }, 666); |
231 } | 1010 } |
232 | 1011 |
233 | 1012 |
234 // Nested loops. | 1013 // Nested loops. |
235 { | 1014 { |
236 function* g1() { yield 1; yield 2; throw 3; } | 1015 function* g1() { yield 1; yield 2; throw 3; } |
237 function* g2() { yield -1; yield -2; throw -3; } | 1016 function* g2() { yield -1; yield -2; throw -3; } |
238 | 1017 |
239 assertDoesNotThrow(() => { | 1018 assertDoesNotThrow(() => { |
240 for (let x of g1()) { | 1019 for (let x of g1()) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 for (let x of g1()) { | 1143 for (let x of g1()) { |
365 try { | 1144 try { |
366 for (let y of g2()) { | 1145 for (let y of g2()) { |
367 } | 1146 } |
368 } catch (_) {} | 1147 } catch (_) {} |
369 if (x == 2) break; | 1148 if (x == 2) break; |
370 } | 1149 } |
371 }, 5); | 1150 }, 5); |
372 assertEquals([1], log); | 1151 assertEquals([1], log); |
373 } | 1152 } |
OLD | NEW |