summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/values/make-out-of-bounds-after-exhausted.js
blob: 8baa1c0920667c6f5beed269d32c8e7cf55179a5 (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
43
44
45
46
47
48
49
50
51
52
// |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.values
description: >
  Calling next on an out-of-bounds typedarray throws no error when iterator exhausted.
features: [TypedArray, resizable-arraybuffer]
---*/

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

// Ensure the TypedArray is correctly initialised.
assert.sameValue(ta.length, 2);
assert.sameValue(ta.byteOffset, 1);

ta[0] = 11;
ta[1] = 22;

let it = ta.values();
let r;

// Fetch the first value.
r = it.next();
assert.sameValue(r.done, false);
assert.sameValue(r.value, 11);

// Fetch the second value.
r = it.next();
assert.sameValue(r.done, false);
assert.sameValue(r.value, 22);

// Iterator is now exhausted.
r = it.next();
assert.sameValue(r.done, true);
assert.sameValue(r.value, undefined);

// Resize buffer to zero.
rab.resize(0);

// TypedArray is now out-of-bounds.
assert.sameValue(ta.length, 0);
assert.sameValue(ta.byteOffset, 0);

// Calling next doesn't throw an error.
r = it.next();
assert.sameValue(r.done, true);
assert.sameValue(r.value, undefined);

reportCompare(0, 0);