Skip to content

Commit a977d3b

Browse files
anbaljharb
authored andcommitted
Add coverage when searching undefined after shrinking buffer
1 parent e7a84b0 commit a977d3b

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2025 André Bargull. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-%typedarray%.prototype.includes
6+
description: >
7+
Search undefined after shrinking the buffer with out-of-bounds index.
8+
info: |
9+
%TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
10+
11+
...
12+
3. Let len be TypedArrayLength(taRecord).
13+
...
14+
5. Let n be ? ToIntegerOrInfinity(fromIndex).
15+
...
16+
11. Repeat, while k < len,
17+
...
18+
12. Return false.
19+
features: [TypedArray, resizable-arraybuffer]
20+
includes: [testTypedArray.js]
21+
---*/
22+
23+
testWithTypedArrayConstructors(TA => {
24+
var rab = new ArrayBuffer(TA.BYTES_PER_ELEMENT, {maxByteLength: TA.BYTES_PER_ELEMENT});
25+
var ta = new TA(rab);
26+
assert.sameValue(ta.length, 1);
27+
28+
var index = {
29+
valueOf() {
30+
// Resize buffer to zero.
31+
rab.resize(0);
32+
33+
// Index is out-of-bounds when comparing to the original length.
34+
return 1;
35+
}
36+
};
37+
38+
var result = ta.includes(undefined, index);
39+
40+
assert.sameValue(result, false);
41+
assert.sameValue(ta.length, 0);
42+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2025 André Bargull. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-%typedarray%.prototype.includes
6+
description: >
7+
Search undefined after shrinking the buffer with in-bounds index.
8+
info: |
9+
%TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
10+
11+
...
12+
3. Let len be TypedArrayLength(taRecord).
13+
...
14+
5. Let n be ? ToIntegerOrInfinity(fromIndex).
15+
...
16+
11. Repeat, while k < len,
17+
a. Let elementK be ! Get(O, ! ToString(𝔽(k))).
18+
b. If SameValueZero(searchElement, elementK) is true, return true.
19+
...
20+
12. Return false.
21+
features: [TypedArray, resizable-arraybuffer]
22+
includes: [testTypedArray.js]
23+
---*/
24+
25+
testWithTypedArrayConstructors(TA => {
26+
var rab = new ArrayBuffer(TA.BYTES_PER_ELEMENT, {maxByteLength: TA.BYTES_PER_ELEMENT});
27+
var ta = new TA(rab);
28+
assert.sameValue(ta.length, 1);
29+
30+
var index = {
31+
valueOf() {
32+
// Resize buffer to zero.
33+
rab.resize(0);
34+
35+
// Index is in-bounds when comparing to the original length.
36+
return 0;
37+
}
38+
};
39+
40+
var result = ta.includes(undefined, index);
41+
42+
assert.sameValue(result, true);
43+
assert.sameValue(ta.length, 0);
44+
});

0 commit comments

Comments
 (0)