Skip to content

Commit 19a9114

Browse files
anbaptomato
authored andcommitted
Add coverage for byteOffset with detached buffer in TypedArray.prototype.subarray
JSC doesn't handle this case correctly.
1 parent 8744a9b commit 19a9114

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) 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.subarray
6+
description: >
7+
Species constructor is called with the correct byte-offset value
8+
info: |
9+
%TypedArray%.prototype.subarray ( start, end )
10+
11+
...
12+
13. Let srcByteOffset be O.[[ByteOffset]].
13+
14. Let beginByteOffset be srcByteOffset + (startIndex × elementSize).
14+
...
15+
16. Else,
16+
...
17+
f. Let argumentsList be « buffer, 𝔽(beginByteOffset), 𝔽(newLength) ».
18+
17. Return ? TypedArraySpeciesCreate(O, argumentsList).
19+
features: [TypedArray]
20+
includes: [testTypedArray.js, detachArrayBuffer.js]
21+
---*/
22+
23+
testWithTypedArrayConstructors(function(TA) {
24+
var ab = new ArrayBuffer(2 * TA.BYTES_PER_ELEMENT);
25+
var ta = new TA(ab, TA.BYTES_PER_ELEMENT, 1);
26+
var result = new TA(0);
27+
28+
ta.constructor = {
29+
[Symbol.species]: function(buffer, byteOffset, length) {
30+
assert.sameValue(buffer, ab);
31+
assert.sameValue(byteOffset, 2 * TA.BYTES_PER_ELEMENT);
32+
assert.sameValue(length, 0);
33+
return result;
34+
}
35+
};
36+
37+
var end = {
38+
valueOf() {
39+
$DETACHBUFFER(ab);
40+
return 0;
41+
}
42+
};
43+
44+
assert.sameValue(ta.subarray(1, end), result);
45+
});

0 commit comments

Comments
 (0)