]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/destructuring-assignment-accepts-iterables.js
f14688b3732d6c6d7ecf0378cbbd85247b3bbe77
1 function shouldBe(actual
, expected
) {
2 if (actual
!== expected
)
3 throw new Error('bad value: ' + actual
);
6 function shouldThrow(func
, errorMessage
) {
7 var errorThrown
= false;
16 throw new Error('not thrown');
17 if (String(error
) !== errorMessage
)
18 throw new Error(`bad error: ${String(error)}`);
22 var [a
, b
, c
] = [1, 2, 3];
29 var [a
, b
, c
] = [1, 2, 3].keys();
36 var [a
, b
, c
] = [1, 2, 3].values();
43 var [a
, , c
] = [1, 2, 3].values();
49 var [a
, b
, c
] = [1, , 3].values();
51 shouldBe(b
, undefined);
56 var [, b
, c
] = [1, 2, 3, 4, 5, 6].values();
62 var [a
, b
, c
] = [1].values();
64 shouldBe(b
, undefined);
65 shouldBe(c
, undefined);
68 (function ([a
, b
, c
]) {
70 shouldBe(b
, undefined);
71 shouldBe(c
, undefined);
75 var [a
= 0, b
= 2, c
= 3] = [1].values();
82 var [a
= 1, b
= 2, c
= 3] = [undefined, undefined, undefined];
88 // String with a surrogate pair.
91 var [a
, b
, c
] = string
;
92 shouldBe(string
.length
, 4);
99 var set = new Set([1, 2, 3]);
101 shouldBe(set.has(a
), true);
102 shouldBe(set.has(b
), true);
103 shouldBe(set.has(c
), true);
107 var map
= new Map([[1, 1], [2, 2], [3, 3]]);
109 shouldBe(Array
.isArray(a
), true);
110 shouldBe(Array
.isArray(b
), true);
111 shouldBe(Array
.isArray(c
), true);
112 shouldBe(map
.has(a
[0]), true);
113 shouldBe(map
.has(b
[0]), true);
114 shouldBe(map
.has(c
[0]), true);
119 shouldThrow(function () {
121 [Symbol
.iterator
]() {
125 }, "TypeError: [a, b, c] is not a function. (In '[a, b, c]', '[a, b, c]' is undefined)");
127 shouldThrow(function () {
129 [Symbol
.iterator
]() {
133 }, "TypeError: [a, b, c] is not a function. (In '[a, b, c]', '[a, b, c]' is undefined)");
135 shouldThrow(function () {
137 [Symbol
.iterator
]() {
142 throw new Error('out');
147 shouldThrow(function () {
149 [Symbol
.iterator
]() {
157 }, 'TypeError: Iterator result interface is not an object.');
161 shouldThrow(function () {
163 [Symbol
.iterator
]() {
175 }, 'TypeError: Iterator result interface is not an object.');
182 shouldThrow(function () {
184 [Symbol
.iterator
]() {
193 return { value: 20, done: false };
196 }, 'TypeError: Iterator result interface is not an object.');
205 [Symbol
.iterator
]() {
214 return { value: 20, done: true };
218 shouldBe(a
, undefined);
219 shouldBe(b
, undefined);
220 shouldBe(c
, undefined);
230 [Symbol
.iterator
]() {
242 return { value: 20, done: prev
};
247 shouldBe(b
, undefined);
248 shouldBe(c
, undefined);
259 [Symbol
.iterator
]() {
265 return { done: true };
270 return { value: 20, done: false };
287 [Symbol
.iterator
]() {
293 return { done: true };
300 var done
= ++this.count
=== 3;
301 return { value: 20, done
};
307 shouldBe(c
, undefined);
318 [Symbol
.iterator
]() {
324 return { done: true };
331 var done
= ++this.count
=== 4;
332 return { value: 20, done
};
346 shouldThrow(function () {
348 [Symbol
.iterator
]() {
354 throw new Error('out');
359 return { value: 20, done: false };
371 shouldThrow(function () {
373 [Symbol
.iterator
]() {
379 throw new Error('out');
384 return { value: 20, done: false };
396 shouldThrow(function () {
398 [Symbol
.iterator
]() {
404 throw new Error('ng');
409 throw new Error('out');
421 shouldThrow(function () {
423 [Symbol
.iterator
]() {
429 throw new Error('ng');
434 throw new Error('out');