summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/join/separator-tostring-once-after-resized.js
blob: fdae9040c5520b115b00b02276df51151ad630cc (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
41
42
// |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-%typedarray%.prototype.join
description: >
  ToString is called once when the array is resized.
info: |
  %TypedArray%.prototype.join ( separator )

  ...
  2. Let taRecord be ? ValidateTypedArray(O, seq-cst).
  3. Let len be TypedArrayLength(taRecord).
  ...
  5. Else, let sep be ? ToString(separator).
  ...

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

let rab = new ArrayBuffer(3, {maxByteLength: 5});
let ta = new Int8Array(rab);

let callCount = 0;

let index = {
  toString() {
    callCount++;
    rab.resize(0);
    return "-";
  }
};

assert.sameValue(callCount, 0);

let r = ta.join(index);

assert.sameValue(callCount, 1);
assert.sameValue(r, "--");

reportCompare(0, 0);