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

Function TestMap

deps/v8/test/mjsunit/typedarray-growablesharedarraybuffer.js:2815–2879  ·  view source on GitHub ↗
(mapHelper)

Source from the content-addressed store, hash-verified

2813ToLocaleStringNumberPrototypeToLocaleStringGrows(ArrayToLocaleStringHelper);
2814
2815function TestMap(mapHelper) {
2816 for (let ctor of ctors) {
2817 const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
2818 8 * ctor.BYTES_PER_ELEMENT);
2819 const fixedLength = new ctor(gsab, 0, 4);
2820 const fixedLengthWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT, 2);
2821 const lengthTracking = new ctor(gsab, 0);
2822 const lengthTrackingWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT);
2823
2824 // Write some data into the array.
2825 const taWrite = new ctor(gsab);
2826 for (let i = 0; i < 4; ++i) {
2827 WriteToTypedArray(taWrite, i, 2 * i);
2828 }
2829
2830 // Orig. array: [0, 2, 4, 6]
2831 // [0, 2, 4, 6] << fixedLength
2832 // [4, 6] << fixedLengthWithOffset
2833 // [0, 2, 4, 6, ...] << lengthTracking
2834 // [4, 6, ...] << lengthTrackingWithOffset
2835
2836 function Helper(array) {
2837 const values = [];
2838 function GatherValues(n, ix) {
2839 assertEquals(values.length, ix);
2840 values.push(n);
2841 if (typeof n == 'bigint') {
2842 return n + 1n;
2843 }
2844 return n + 1;
2845 }
2846 const newValues = mapHelper(array, GatherValues);
2847 for (let i = 0; i < values.length; ++i) {
2848 if (typeof values[i] == 'bigint') {
2849 assertEquals(newValues[i], values[i] + 1n);
2850 } else {
2851 assertEquals(newValues[i], values[i] + 1);
2852 }
2853 }
2854 return ToNumbers(values);
2855 }
2856
2857 assertEquals([0, 2, 4, 6], Helper(fixedLength));
2858 assertEquals([4, 6], Helper(fixedLengthWithOffset));
2859 assertEquals([0, 2, 4, 6], Helper(lengthTracking));
2860 assertEquals([4, 6], Helper(lengthTrackingWithOffset));
2861
2862 // Grow.
2863 gsab.grow(6 * ctor.BYTES_PER_ELEMENT);
2864 for (let i = 0; i < 6; ++i) {
2865 WriteToTypedArray(taWrite, i, 2 * i);
2866 }
2867
2868 // Orig. array: [0, 2, 4, 6, 8, 10]
2869 // [0, 2, 4, 6] << fixedLength
2870 // [4, 6] << fixedLengthWithOffset
2871 // [0, 2, 4, 6, 8, 10, ...] << lengthTracking
2872 // [4, 6, 8, 10, ...] << lengthTrackingWithOffset

Calls 4

WriteToTypedArrayFunction · 0.85
HelperFunction · 0.70
assertEqualsFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…