OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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-destructuring-assignment --harmony-destructuring-bind | 5 // Flags: --harmony-destructuring-assignment --harmony-destructuring-bind |
6 | 6 |
7 // script-level tests | 7 // script-level tests |
8 var ox, oy = {}, oz; | 8 var ox, oy = {}, oz; |
9 ({ | 9 ({ |
10 x: ox, | 10 x: ox, |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 "use strict"; | 421 "use strict"; |
422 const c = "untouchable"; | 422 const c = "untouchable"; |
423 assertThrows(() => { [ c ] = [ "nope!" ]; }, TypeError); | 423 assertThrows(() => { [ c ] = [ "nope!" ]; }, TypeError); |
424 assertThrows(() => { [ [ c ] ] = [ [ "nope!" ] ]; }, TypeError); | 424 assertThrows(() => { [ [ c ] ] = [ [ "nope!" ] ]; }, TypeError); |
425 assertThrows(() => { [ { c } ] = [ { c: "nope!" } ]; }, TypeError); | 425 assertThrows(() => { [ { c } ] = [ { c: "nope!" } ]; }, TypeError); |
426 assertThrows(() => { ({ c } = { c: "nope!" }); }, TypeError); | 426 assertThrows(() => { ({ c } = { c: "nope!" }); }, TypeError); |
427 assertThrows(() => { ({ a: { c } } = { a: { c: "nope!" } }); }, TypeError); | 427 assertThrows(() => { ({ a: { c } } = { a: { c: "nope!" } }); }, TypeError); |
428 assertThrows(() => { ({ a: [ c ] } = { a: [ "nope!" ] }); }, TypeError); | 428 assertThrows(() => { ({ a: [ c ] } = { a: [ "nope!" ] }); }, TypeError); |
429 assertEquals("untouchable", c); | 429 assertEquals("untouchable", c); |
430 })(); | 430 })(); |
| 431 |
| 432 (function testForIn() { |
| 433 var log = []; |
| 434 var x = {}; |
| 435 var object = { |
| 436 "Apenguin": 1, |
| 437 "\u{1F382}cake": 2, |
| 438 "Bpuppy": 3, |
| 439 "Cspork": 4 |
| 440 }; |
| 441 for ([x.firstLetter, ...x.rest] in object) { |
| 442 if (x.firstLetter === "A") { |
| 443 assertEquals(["p", "e", "n", "g", "u", "i", "n"], x.rest); |
| 444 continue; |
| 445 } |
| 446 if (x.firstLetter === "C") { |
| 447 assertEquals(["s", "p", "o", "r", "k"], x.rest); |
| 448 break; |
| 449 } |
| 450 log.push({ firstLetter: x.firstLetter, rest: x.rest }); |
| 451 } |
| 452 assertEquals([ |
| 453 { firstLetter: "\u{1F382}", rest: ["c", "a", "k", "e"] }, |
| 454 { firstLetter: "B", rest: ["p", "u", "p", "p", "y"] }, |
| 455 ], log); |
| 456 })(); |
| 457 |
| 458 (function testForOf() { |
| 459 var log = []; |
| 460 var x = {}; |
| 461 var names = [ |
| 462 "Apenguin", |
| 463 "\u{1F382}cake", |
| 464 "Bpuppy", |
| 465 "Cspork" |
| 466 ]; |
| 467 for ([x.firstLetter, ...x.rest] of names) { |
| 468 if (x.firstLetter === "A") { |
| 469 assertEquals(["p", "e", "n", "g", "u", "i", "n"], x.rest); |
| 470 continue; |
| 471 } |
| 472 if (x.firstLetter === "C") { |
| 473 assertEquals(["s", "p", "o", "r", "k"], x.rest); |
| 474 break; |
| 475 } |
| 476 log.push({ firstLetter: x.firstLetter, rest: x.rest }); |
| 477 } |
| 478 assertEquals([ |
| 479 { firstLetter: "\u{1F382}", rest: ["c", "a", "k", "e"] }, |
| 480 { firstLetter: "B", rest: ["p", "u", "p", "p", "y"] }, |
| 481 ], log); |
| 482 })(); |
OLD | NEW |