summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/resized-out-of-bounds-to-in-bounds-index.js
blob: 62268e26b6d0d0cc176c21870121fe7cf67e5a2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-typedarraysetelement
description: >
  Index is validated after converting the right-hand side operand.
info: |
  TypedArraySetElement ( O, index, value )
    ...
    2. Otherwise, let numValue be ? ToNumber(value).
    3. If IsValidIntegerIndex(O, index) is true, then
      ...

features: [TypedArray, resizable-arraybuffer]
---*/

let rab = new ArrayBuffer(0, {maxByteLength: 1});
let ta = new Int8Array(rab);

// Index is initially out-of-bounds.
let index = 0;

let value = {
  valueOf() {
    // Make `index` an in-bounds access.
    rab.resize(1);
    return 100;
  }
};

assert.sameValue(ta.length, 0);

ta[index] = value;

assert.sameValue(ta.length, 1);
assert.sameValue(ta[0], 100);

reportCompare(0, 0);