mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 07:25:15 +02:00
RAB: Integrate staging tests for .copyWithin method (#4072)
RAB: Integrate staging tests for .copyWithin method of Array.prototype and TypedArray.prototype This is part of PR #3888 to make reviewing easier. Includes changes to use the helper ./harness/resizableArrayBufferUtils.js
This commit is contained in:
parent
c47b716e8d
commit
d7b2f4acfc
176
test/built-ins/Array/prototype/copyWithin/resizable-buffer.js
vendored
Normal file
176
test/built-ins/Array/prototype/copyWithin/resizable-buffer.js
vendored
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
// Copyright 2023 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-array.prototype.copywithin
|
||||||
|
description: >
|
||||||
|
Array.p.copyWithin behaves correctly when the receiver is backed by
|
||||||
|
resizable buffer
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const ArrayCopyWithinHelper = (ta, ...rest) => {
|
||||||
|
Array.prototype.copyWithin.call(ta, ...rest);
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
|
||||||
|
// Write some data into the array.
|
||||||
|
const taWrite = new ctor(rab);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 1, 2, 3]
|
||||||
|
// [0, 1, 2, 3] << fixedLength
|
||||||
|
// [2, 3] << fixedLengthWithOffset
|
||||||
|
// [0, 1, 2, 3, ...] << lengthTracking
|
||||||
|
// [2, 3, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
ArrayCopyWithinHelper(fixedLength, 0, 2);
|
||||||
|
assert.compareArray(ToNumbers(fixedLength), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(fixedLengthWithOffset), [
|
||||||
|
3,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
ArrayCopyWithinHelper(lengthTracking, 0, 2);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTrackingWithOffset), [
|
||||||
|
3,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Shrink so that fixed length TAs go out of bounds.
|
||||||
|
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
for (let i = 0; i < 3; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 1, 2]
|
||||||
|
// [0, 1, 2, ...] << lengthTracking
|
||||||
|
// [2, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
assert.compareArray(ToNumbers(fixedLength), []);
|
||||||
|
assert.compareArray(ToNumbers(fixedLengthWithOffset), []);
|
||||||
|
|
||||||
|
ArrayCopyWithinHelper(fixedLength, 0, 1);
|
||||||
|
ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1);
|
||||||
|
// We'll check below that these were no-op.
|
||||||
|
assert.compareArray(ToNumbers(fixedLength), []);
|
||||||
|
assert.compareArray(ToNumbers(fixedLengthWithOffset), []);
|
||||||
|
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
]);
|
||||||
|
ArrayCopyWithinHelper(lengthTracking, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
2
|
||||||
|
]);
|
||||||
|
ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTrackingWithOffset), [2]);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
WriteToTypedArray(taWrite, 0, 0);
|
||||||
|
ArrayCopyWithinHelper(fixedLength, 0, 1, 1);
|
||||||
|
ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1, 1);
|
||||||
|
ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1, 1);
|
||||||
|
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [0]);
|
||||||
|
ArrayCopyWithinHelper(lengthTracking, 0, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [0]);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
ArrayCopyWithinHelper(fixedLength, 0, 1, 1);
|
||||||
|
ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1, 1);
|
||||||
|
ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1, 1);
|
||||||
|
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), []);
|
||||||
|
ArrayCopyWithinHelper(lengthTracking, 0, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), []);
|
||||||
|
|
||||||
|
// Grow so that all TAs are back in-bounds.
|
||||||
|
rab.resize(6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
for (let i = 0; i < 6; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 1, 2, 3, 4, 5]
|
||||||
|
// [0, 1, 2, 3] << fixedLength
|
||||||
|
// [2, 3] << fixedLengthWithOffset
|
||||||
|
// [0, 1, 2, 3, 4, 5, ...] << lengthTracking
|
||||||
|
// [2, 3, 4, 5, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
ArrayCopyWithinHelper(fixedLength, 0, 2);
|
||||||
|
assert.compareArray(ToNumbers(fixedLength), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 6; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(fixedLengthWithOffset), [
|
||||||
|
3,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 6; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [0, 1, 2, 3, 4, 5, ...] << lengthTracking
|
||||||
|
// target ^ ^ start
|
||||||
|
ArrayCopyWithinHelper(lengthTracking, 0, 2);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
4,
|
||||||
|
5
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 6; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [2, 3, 4, 5, ...] << lengthTrackingWithOffset
|
||||||
|
// target ^ ^ start
|
||||||
|
ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTrackingWithOffset), [
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
5
|
||||||
|
]);
|
||||||
|
}
|
80
test/built-ins/TypedArray/prototype/copyWithin/coerced-target-start-end-shrink.js
vendored
Normal file
80
test/built-ins/TypedArray/prototype/copyWithin/coerced-target-start-end-shrink.js
vendored
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Copyright 2023 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-array.prototype.copywithin
|
||||||
|
description: >
|
||||||
|
TypedArray.p.copyWithin behaves correctly when argument coercion shrinks the receiver
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
const evil = {
|
||||||
|
valueOf: () => {
|
||||||
|
rab.resize(2 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.copyWithin(evil, 0, 1);
|
||||||
|
});
|
||||||
|
rab.resize(4 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.copyWithin(0, evil, 3);
|
||||||
|
});
|
||||||
|
rab.resize(4 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.copyWithin(0, 1, evil);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
const lengthTracking = new ctor(rab);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(lengthTracking, i, i);
|
||||||
|
}
|
||||||
|
// [0, 1, 2, 3]
|
||||||
|
// ^
|
||||||
|
// target
|
||||||
|
// ^
|
||||||
|
// start
|
||||||
|
const evil = {
|
||||||
|
valueOf: () => {
|
||||||
|
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lengthTracking.copyWithin(evil, 0);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
const lengthTracking = new ctor(rab);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(lengthTracking, i, i);
|
||||||
|
}
|
||||||
|
// [0, 1, 2, 3]
|
||||||
|
// ^
|
||||||
|
// start
|
||||||
|
// ^
|
||||||
|
// target
|
||||||
|
const evil = {
|
||||||
|
valueOf: () => {
|
||||||
|
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lengthTracking.copyWithin(0, evil);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
]);
|
||||||
|
}
|
55
test/built-ins/TypedArray/prototype/copyWithin/coerced-target-start-grow.js
vendored
Normal file
55
test/built-ins/TypedArray/prototype/copyWithin/coerced-target-start-grow.js
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Copyright 2023 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-array.prototype.copywithin
|
||||||
|
description: >
|
||||||
|
TypedArray.p.copyWithin behaves correctly when argument coercion shrinks the receiver
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
const lengthTracking = new ctor(rab);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(lengthTracking, i, i);
|
||||||
|
}
|
||||||
|
const evil = {
|
||||||
|
valueOf: () => {
|
||||||
|
rab.resize(6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
WriteToTypedArray(lengthTracking, 4, 4);
|
||||||
|
WriteToTypedArray(lengthTracking, 5, 5);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Orig. array: [0, 1, 2, 3] [4, 5]
|
||||||
|
// ^ ^ ^ new elements
|
||||||
|
// target start
|
||||||
|
lengthTracking.copyWithin(evil, 2);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5
|
||||||
|
]);
|
||||||
|
rab.resize(4 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(lengthTracking, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 1, 2, 3] [4, 5]
|
||||||
|
// ^ ^ ^ new elements
|
||||||
|
// start target
|
||||||
|
lengthTracking.copyWithin(2, evil);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
5
|
||||||
|
]);
|
||||||
|
}
|
179
test/built-ins/TypedArray/prototype/copyWithin/resizable-buffer.js
vendored
Normal file
179
test/built-ins/TypedArray/prototype/copyWithin/resizable-buffer.js
vendored
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
// Copyright 2023 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-%typedarray%.prototype.copywithin
|
||||||
|
description: >
|
||||||
|
TypedArray.p.copyWithin behaves correctly when the receiver is backed by
|
||||||
|
resizable buffer
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
|
||||||
|
// Write some data into the array.
|
||||||
|
const taWrite = new ctor(rab);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 1, 2, 3]
|
||||||
|
// [0, 1, 2, 3] << fixedLength
|
||||||
|
// [2, 3] << fixedLengthWithOffset
|
||||||
|
// [0, 1, 2, 3, ...] << lengthTracking
|
||||||
|
// [2, 3, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
fixedLength.copyWithin(0, 2);
|
||||||
|
assert.compareArray(ToNumbers(fixedLength), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
fixedLengthWithOffset.copyWithin(0, 1);
|
||||||
|
assert.compareArray(ToNumbers(fixedLengthWithOffset), [
|
||||||
|
3,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
lengthTracking.copyWithin(0, 2);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
lengthTrackingWithOffset.copyWithin(0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTrackingWithOffset), [
|
||||||
|
3,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Shrink so that fixed length TAs go out of bounds.
|
||||||
|
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
for (let i = 0; i < 3; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 1, 2]
|
||||||
|
// [0, 1, 2, ...] << lengthTracking
|
||||||
|
// [2, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.copyWithin(0, 1);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.copyWithin(0, 1);
|
||||||
|
});
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
]);
|
||||||
|
lengthTracking.copyWithin(0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
2
|
||||||
|
]);
|
||||||
|
lengthTrackingWithOffset.copyWithin(0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTrackingWithOffset), [2]);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
WriteToTypedArray(taWrite, 0, 0);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.copyWithin(0, 1, 1);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.copyWithin(0, 1, 1);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.copyWithin(0, 1, 1);
|
||||||
|
});
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [0]);
|
||||||
|
lengthTracking.copyWithin(0, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [0]);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.copyWithin(0, 1, 1);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.copyWithin(0, 1, 1);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.copyWithin(0, 1, 1);
|
||||||
|
});
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), []);
|
||||||
|
lengthTracking.copyWithin(0, 0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), []);
|
||||||
|
|
||||||
|
// Grow so that all TAs are back in-bounds.
|
||||||
|
rab.resize(6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
for (let i = 0; i < 6; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 1, 2, 3, 4, 5]
|
||||||
|
// [0, 1, 2, 3] << fixedLength
|
||||||
|
// [2, 3] << fixedLengthWithOffset
|
||||||
|
// [0, 1, 2, 3, 4, 5, ...] << lengthTracking
|
||||||
|
// [2, 3, 4, 5, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
fixedLength.copyWithin(0, 2);
|
||||||
|
assert.compareArray(ToNumbers(fixedLength), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 6; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
fixedLengthWithOffset.copyWithin(0, 1);
|
||||||
|
assert.compareArray(ToNumbers(fixedLengthWithOffset), [
|
||||||
|
3,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 6; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [0, 1, 2, 3, 4, 5, ...] << lengthTracking
|
||||||
|
// target ^ ^ start
|
||||||
|
lengthTracking.copyWithin(0, 2);
|
||||||
|
assert.compareArray(ToNumbers(lengthTracking), [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
4,
|
||||||
|
5
|
||||||
|
]);
|
||||||
|
for (let i = 0; i < 6; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [2, 3, 4, 5, ...] << lengthTrackingWithOffset
|
||||||
|
// target ^ ^ start
|
||||||
|
lengthTrackingWithOffset.copyWithin(0, 1);
|
||||||
|
assert.compareArray(ToNumbers(lengthTrackingWithOffset), [
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
5
|
||||||
|
]);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user