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

Function checkEncoding

deps/v8/test/mjsunit/wasm/stringrefs-exec.js:792–830  ·  view source on GitHub ↗
(str, slice, start, length)

Source from the content-addressed store, hash-verified

790 }
791
792 function checkEncoding(str, slice, start, length) {
793 let bytes = encodeWtf16LE(slice);
794 function clearMemory(low, high) {
795 for (let i = low; i < high; i++) {
796 memory[i] = 0;
797 }
798 }
799 function assertMemoryBytesZero(low, high) {
800 for (let i = low; i < high; i++) {
801 assertEquals(0, memory[i]);
802 }
803 }
804 function checkMemory(offset, bytes) {
805 let slop = 64;
806 assertMemoryBytesZero(Math.max(0, offset - slop), offset);
807 for (let i = 0; i < bytes.length; i++) {
808 assertEquals(bytes[i], memory[offset + i]);
809 }
810 assertMemoryBytesZero(offset + bytes.length,
811 Math.min(memory.length,
812 offset + bytes.length + slop));
813 }
814
815 for (let offset of [0, 42, memory.length - bytes.length]) {
816 assertEquals(slice.length,
817 instance.exports.encode(str, offset, start, length));
818 checkMemory(offset, bytes);
819 clearMemory(offset, offset + bytes.length);
820 }
821
822 assertThrows(() => instance.exports.encode(str, 1, start, length),
823 WebAssembly.RuntimeError,
824 "operation does not support unaligned accesses");
825 assertThrows(
826 () => instance.exports.encode(str, memory.length - bytes.length + 2,
827 start, length),
828 WebAssembly.RuntimeError, "memory access out of bounds");
829 checkMemory(memory.length - bytes.length - 2, []);
830 }
831 checkEncoding("fox", "f", 0, 1);
832 checkEncoding("fox", "fo", 0, 2);
833 checkEncoding("fox", "fox", 0, 3);

Callers 1

stringrefs-exec.jsFile · 0.70

Calls 11

checkMemoryFunction · 0.85
clearMemoryFunction · 0.85
Wtf8PositionTreatmentFunction · 0.85
CodepointStartFunction · 0.85
assertArrayEqualsFunction · 0.85
encodeMethod · 0.80
encodeWtf16LEFunction · 0.70
encodeWtf8Function · 0.70
assertEqualsFunction · 0.50
assertThrowsFunction · 0.50
encodeFunction · 0.50

Tested by

no test coverage detected