mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 11:57:32 +09:00
Fix ArrayBuffer slice after resizable source shrink
This commit is contained in:
parent
d8e52b4fce
commit
3e05786b77
2 changed files with 31 additions and 1 deletions
|
|
@ -1877,7 +1877,10 @@ function ArrayBufferSlice(start, end) {
|
||||||
ThrowTypeError(JSMSG_TYPED_ARRAY_DETACHED);
|
ThrowTypeError(JSMSG_TYPED_ARRAY_DETACHED);
|
||||||
|
|
||||||
// Steps 19-21.
|
// Steps 19-21.
|
||||||
ArrayBufferCopyData(new_, 0, O, first | 0, newLen | 0, isWrapped);
|
var currentLen = ArrayBufferByteLength(O);
|
||||||
|
var copyLen = first >= currentLen ? 0 : std_Math_min(newLen, currentLen - first);
|
||||||
|
if (copyLen > 0)
|
||||||
|
ArrayBufferCopyData(new_, 0, O, first | 0, copyLen | 0, isWrapped);
|
||||||
|
|
||||||
// Step 22.
|
// Step 22.
|
||||||
return new_;
|
return new_;
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,33 @@ assertEq(fixedMoved.maxByteLength, 10);
|
||||||
assertEq(fixedMoved.resizable, false);
|
assertEq(fixedMoved.resizable, false);
|
||||||
assertEq(new Uint8Array(fixedMoved)[0], 7);
|
assertEq(new Uint8Array(fixedMoved)[0], 7);
|
||||||
|
|
||||||
|
var sliceSource = new ArrayBuffer(8, { maxByteLength: 8 });
|
||||||
|
var sliceSourceBytes = new Uint8Array(sliceSource);
|
||||||
|
for (var i = 0; i < sliceSourceBytes.length; i++)
|
||||||
|
sliceSourceBytes[i] = i + 1;
|
||||||
|
|
||||||
|
sliceSource.constructor = {
|
||||||
|
[Symbol.species]: function(byteLength) {
|
||||||
|
sliceSource.resize(4);
|
||||||
|
return new ArrayBuffer(byteLength);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var sliced = sliceSource.slice(2, 8);
|
||||||
|
var slicedBytes = new Uint8Array(sliced);
|
||||||
|
assertEq(sliced.byteLength, 6);
|
||||||
|
assertEq(slicedBytes[0], 3);
|
||||||
|
assertEq(slicedBytes[1], 4);
|
||||||
|
assertEq(slicedBytes[2], 0);
|
||||||
|
assertEq(slicedBytes[5], 0);
|
||||||
|
|
||||||
|
sliceSource.resize(8);
|
||||||
|
for (var i = 0; i < sliceSourceBytes.length; i++)
|
||||||
|
sliceSourceBytes[i] = i + 1;
|
||||||
|
var zeroCopied = sliceSource.slice(6, 8);
|
||||||
|
assertEq(zeroCopied.byteLength, 2);
|
||||||
|
assertEq(new Uint8Array(zeroCopied)[0], 0);
|
||||||
|
|
||||||
assertThrowsInstanceOf(() => new ArrayBuffer(4, { maxByteLength: 3 }), RangeError);
|
assertThrowsInstanceOf(() => new ArrayBuffer(4, { maxByteLength: 3 }), RangeError);
|
||||||
|
|
||||||
if (typeof reportCompare === "function")
|
if (typeof reportCompare === "function")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue