Skip to content

Commit 8744a9b

Browse files
anbaptomato
authored andcommitted
Add coverage for species constructor returning typed array with same backing buffer
JSC doesn't handle this case correctly.
1 parent 8081aa7 commit 8744a9b

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.slice
6+
description: >
7+
When species constructs a typed array using the same buffer but with a
8+
different byte offset, slice output reflects element-by-element copying into
9+
that buffer.
10+
info: |
11+
%TypedArray%.prototype.slice ( start, end )
12+
13+
...
14+
14. If countBytes > 0, then
15+
g. If srcType is targetType, then
16+
ix. Repeat, while targetByteIndex < endByteIndex,
17+
1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, uint8, true, unordered).
18+
2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered).
19+
...
20+
features: [TypedArray]
21+
includes: [testTypedArray.js, compareArray.js]
22+
---*/
23+
24+
testWithTypedArrayConstructors(function(TA) {
25+
var ta = new TA([
26+
10,
27+
20,
28+
30,
29+
40,
30+
50,
31+
60,
32+
]);
33+
34+
ta.constructor = {
35+
[Symbol.species]: function() {
36+
return new TA(ta.buffer, 2 * TA.BYTES_PER_ELEMENT);
37+
}
38+
};
39+
40+
var result = ta.slice(1, 4);
41+
42+
assert.compareArray(result, [
43+
20, 20, 20, 60,
44+
]);
45+
});

0 commit comments

Comments
 (0)