MCPcopy Index your code
hub / github.com/nodejs/node / TestCopyWithin

Function TestCopyWithin

deps/v8/test/mjsunit/typedarray-resizablearraybuffer.js:1824–1962  ·  view source on GitHub ↗
(helper, oobThrows)

Source from the content-addressed store, hash-verified

1822})();
1823
1824function TestCopyWithin(helper, oobThrows) {
1825 for (let ctor of ctors) {
1826 const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
1827 8 * ctor.BYTES_PER_ELEMENT);
1828 const fixedLength = new ctor(rab, 0, 4);
1829 const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
1830 const lengthTracking = new ctor(rab, 0);
1831 const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
1832
1833 // Write some data into the array.
1834 const taWrite = new ctor(rab);
1835 for (let i = 0; i < 4; ++i) {
1836 WriteToTypedArray(taWrite, i, i);
1837 }
1838
1839 // Orig. array: [0, 1, 2, 3]
1840 // [0, 1, 2, 3] << fixedLength
1841 // [2, 3] << fixedLengthWithOffset
1842 // [0, 1, 2, 3, ...] << lengthTracking
1843 // [2, 3, ...] << lengthTrackingWithOffset
1844
1845 helper(fixedLength, 0, 2);
1846 assertEquals([2, 3, 2, 3], ToNumbers(fixedLength));
1847
1848 for (let i = 0; i < 4; ++i) {
1849 WriteToTypedArray(taWrite, i, i);
1850 }
1851
1852 helper(fixedLengthWithOffset, 0, 1);
1853 assertEquals([3, 3], ToNumbers(fixedLengthWithOffset));
1854
1855 for (let i = 0; i < 4; ++i) {
1856 WriteToTypedArray(taWrite, i, i);
1857 }
1858
1859 helper(lengthTracking, 0, 2);
1860 assertEquals([2, 3, 2, 3], ToNumbers(lengthTracking));
1861
1862 helper(lengthTrackingWithOffset, 0, 1);
1863 assertEquals([3, 3], ToNumbers(lengthTrackingWithOffset));
1864
1865 // Shrink so that fixed length TAs go out of bounds.
1866 rab.resize(3 * ctor.BYTES_PER_ELEMENT);
1867 for (let i = 0; i < 3; ++i) {
1868 WriteToTypedArray(taWrite, i, i);
1869 }
1870
1871 // Orig. array: [0, 1, 2]
1872 // [0, 1, 2, ...] << lengthTracking
1873 // [2, ...] << lengthTrackingWithOffset
1874
1875 if (oobThrows) {
1876 assertThrows(() => { helper(fixedLength, 0, 1); });
1877 assertThrows(() => { helper(fixedLengthWithOffset, 0, 1); });
1878 } else {
1879 helper(fixedLength, 0, 1);
1880 helper(fixedLengthWithOffset, 0, 1);
1881 // We'll check below that these were no-op.

Calls 6

WriteToTypedArrayFunction · 0.85
ToNumbersFunction · 0.85
helperFunction · 0.50
assertEqualsFunction · 0.50
assertThrowsFunction · 0.50

Tested by

no test coverage detected