forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage when searching undefined after shrinking buffer
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ins/TypedArray/prototype/includes/search-undefined-after-shrinking-buffer-index-is-oob.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2025 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-%typedarray%.prototype.includes | ||
description: > | ||
Search undefined after shrinking the buffer with out-of-bounds index. | ||
info: | | ||
%TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) | ||
... | ||
3. Let len be TypedArrayLength(taRecord). | ||
... | ||
5. Let n be ? ToIntegerOrInfinity(fromIndex). | ||
... | ||
11. Repeat, while k < len, | ||
... | ||
12. Return false. | ||
features: [TypedArray, resizable-arraybuffer] | ||
includes: [testTypedArray.js] | ||
---*/ | ||
|
||
testWithTypedArrayConstructors(TA => { | ||
var rab = new ArrayBuffer(TA.BYTES_PER_ELEMENT, {maxByteLength: TA.BYTES_PER_ELEMENT}); | ||
var ta = new TA(rab); | ||
assert.sameValue(ta.length, 1); | ||
|
||
var index = { | ||
valueOf() { | ||
// Resize buffer to zero. | ||
rab.resize(0); | ||
|
||
// Index is out-of-bounds when comparing to the original length. | ||
return 1; | ||
} | ||
}; | ||
|
||
var result = ta.includes(undefined, index); | ||
|
||
assert.sameValue(result, false); | ||
assert.sameValue(ta.length, 0); | ||
}); |
44 changes: 44 additions & 0 deletions
44
test/built-ins/TypedArray/prototype/includes/search-undefined-after-shrinking-buffer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2025 André Bargull. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-%typedarray%.prototype.includes | ||
description: > | ||
Search undefined after shrinking the buffer with in-bounds index. | ||
info: | | ||
%TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) | ||
... | ||
3. Let len be TypedArrayLength(taRecord). | ||
... | ||
5. Let n be ? ToIntegerOrInfinity(fromIndex). | ||
... | ||
11. Repeat, while k < len, | ||
a. Let elementK be ! Get(O, ! ToString(𝔽(k))). | ||
b. If SameValueZero(searchElement, elementK) is true, return true. | ||
... | ||
12. Return false. | ||
features: [TypedArray, resizable-arraybuffer] | ||
includes: [testTypedArray.js] | ||
---*/ | ||
|
||
testWithTypedArrayConstructors(TA => { | ||
var rab = new ArrayBuffer(TA.BYTES_PER_ELEMENT, {maxByteLength: TA.BYTES_PER_ELEMENT}); | ||
var ta = new TA(rab); | ||
assert.sameValue(ta.length, 1); | ||
|
||
var index = { | ||
valueOf() { | ||
// Resize buffer to zero. | ||
rab.resize(0); | ||
|
||
// Index is in-bounds when comparing to the original length. | ||
return 0; | ||
} | ||
}; | ||
|
||
var result = ta.includes(undefined, index); | ||
|
||
assert(result); | ||
assert.sameValue(ta.length, 0); | ||
}); |