Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / TypedArrayConstructors / internals / Set / resized-out-of-bounds-to-in-bounds-index.js
blob62268e26b6d0d0cc176c21870121fe7cf67e5a2a
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-typedarraysetelement
7 description: >
8   Index is validated after converting the right-hand side operand.
9 info: |
10   TypedArraySetElement ( O, index, value )
11     ...
12     2. Otherwise, let numValue be ? ToNumber(value).
13     3. If IsValidIntegerIndex(O, index) is true, then
14       ...
16 features: [TypedArray, resizable-arraybuffer]
17 ---*/
19 let rab = new ArrayBuffer(0, {maxByteLength: 1});
20 let ta = new Int8Array(rab);
22 // Index is initially out-of-bounds.
23 let index = 0;
25 let value = {
26   valueOf() {
27     // Make `index` an in-bounds access.
28     rab.resize(1);
29     return 100;
30   }
33 assert.sameValue(ta.length, 0);
35 ta[index] = value;
37 assert.sameValue(ta.length, 1);
38 assert.sameValue(ta[0], 100);
40 reportCompare(0, 0);