Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / TypedArray / from / iterated-array-changed-by-tonumber.js
bloba0d60991705d2ade000f57a93d570a465bf4a42e
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%.from
6 description: >
7   Modifications to input array after iteration are handled correctly.
8 info: |
9   %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
11   ...
12   6. If usingIterator is not undefined, then
13     a. Let values be ? IteratorToList(? GetIteratorFromMethod(source, usingIterator)).
14     b. Let len be the number of elements in values.
15     ...
16     e. Repeat, while k < len,
17       ...
18       vi. Perform ? Set(targetObj, Pk, mappedValue, true).
19       ...
20 features: [TypedArray]
21 ---*/
23 let values = [0, {
24   valueOf() {
25     // Removes all array elements. Caller must have saved all elements.
26     values.length = 0;
27     return 100;
28   }
29 }, 2];
31 // `from` called with array which uses the built-in array iterator.
32 let ta = Int32Array.from(values);
34 assert.sameValue(ta.length, 3);
35 assert.sameValue(ta[0], 0);
36 assert.sameValue(ta[1], 100);
37 assert.sameValue(ta[2], 2);
39 reportCompare(0, 0);