MCPcopy Create free account
hub / github.com/nodejs/node / Pointer_stringify

Function Pointer_stringify

deps/v8/test/mjsunit/asm/embenchen/copy.js:786–821  ·  view source on GitHub ↗
(ptr, /* optional */ length)

Source from the content-addressed store, hash-verified

784Module['allocate'] = allocate;
785
786function Pointer_stringify(ptr, /* optional */ length) {
787 // TODO: use TextDecoder
788 // Find the length, and check for UTF while doing so
789 var hasUtf = false;
790 var t;
791 var i = 0;
792 while (1) {
793 t = HEAPU8[(((ptr)+(i))|0)];
794 if (t >= 128) hasUtf = true;
795 else if (t == 0 && !length) break;
796 i++;
797 if (length && i == length) break;
798 }
799 if (!length) length = i;
800
801 var ret = '';
802
803 if (!hasUtf) {
804 var MAX_CHUNK = 1024; // split up into chunks, because .apply on a huge string can overflow the stack
805 var curr;
806 while (length > 0) {
807 curr = String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + Math.min(length, MAX_CHUNK)));
808 ret = ret ? ret + curr : curr;
809 ptr += MAX_CHUNK;
810 length -= MAX_CHUNK;
811 }
812 return ret;
813 }
814
815 var utf8 = new Runtime.UTF8Processor();
816 for (i = 0; i < length; i++) {
817 t = HEAPU8[(((ptr)+(i))|0)];
818 ret += utf8.processCChar(t);
819 }
820 return ret;
821}
822Module['Pointer_stringify'] = Pointer_stringify;
823
824// Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns

Callers 3

copy.jsFile · 0.70
fromCFunction · 0.70
demangleFunction · 0.70

Calls 2

applyMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected