Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / TypedArray / from / from-array-mapper-makes-result-out-of-bounds.js
blobc3c541a2a84571cd81391269a912847ffb79a383
1 // |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2024 André Bargull. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-%typedarray%.from
7 description: >
8   If the mapper function makes result typed array out-of-bounds, .from performs Set operation which ignores out-of-bounds indices.
9 info: |
10   %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
12   ...
13   12. Repeat, while k < len,
14     ...
15     c. If mapping is true, then
16       i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »).
17     ...
18     e. Perform ? Set(targetObj, Pk, mappedValue, true).
19     ...
20 features: [TypedArray, resizable-arraybuffer]
21 ---*/
23 let rab = new ArrayBuffer(3, {maxByteLength: 5});
24 let target = new Int8Array(rab);
25 let values = [0, 1, 2];
27 let result = Int32Array.from.call(function() {
28   return target;
29 }, values, v => {
30   if (v === 1) {
31     rab.resize(1);
32   }
33   return v + 10;
34 });
36 assert.sameValue(result, target);
37 assert.sameValue(result.length, 1);
38 assert.sameValue(result[0], 10);
40 reportCompare(0, 0);