Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / TypedArrayConstructors / ctors / object-arg / iterated-array-with-modified-array-iterator.js
blob6ba9b5e1503317d79c74a895240ae37d6bc8c3ed
1 // Copyright (C) 2024 AndrĂ© Bargull. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-typedarray
6 description: >
7   Modifications to input array after iteration are handled correctly.
8 info: |
9   TypedArray ( ...args )
11   ...
12   6. Else,
13     ...
14     b. If firstArgument is an Object, then
15       ...
16       iv. Else,
17         ...
18         2. Let usingIterator be ? GetMethod(firstArgument, @@iterator).
19         3. If usingIterator is not undefined, then
20           a. Let values be ? IteratorToList(? GetIteratorFromMethod(firstArgument, usingIterator)).
21           b. Perform ? InitializeTypedArrayFromList(O, values).
22         ...
23 includes: [testTypedArray.js]
24 features: [TypedArray]
25 ---*/
27 let ArrayIteratorPrototype = Object.getPrototypeOf([].values());
28 let values;
30 // Modify the built-in ArrayIteratorPrototype `next` method.
31 ArrayIteratorPrototype.next = function() {
32   let done = values.length === 0;
33   let value = values.pop();
34   return {value, done};
37 testWithTypedArrayConstructors(function(TypedArray) {
38   // Reset `values` array.
39   values = [1, 2, 3, 4];
41   // Constructor called with array which uses the modified array iterator.
42   var ta = new TypedArray([0]);
44   assert.sameValue(ta.length, 4);
45   assert.sameValue(ta[0], 4);
46   assert.sameValue(ta[1], 3);
47   assert.sameValue(ta[2], 2);
48   assert.sameValue(ta[3], 1);
49 });
51 reportCompare(0, 0);