MCPcopy
hub / github.com/sql-js/sql.js / Pointer_stringify

Function Pointer_stringify

js/sql-debug.js:680–710  ·  view source on GitHub ↗

@type {function(number, number=)}

(ptr, length)

Source from the content-addressed store, hash-verified

678
679/** @type {function(number, number=)} */
680function Pointer_stringify(ptr, length) {
681 if (length === 0 || !ptr) return '';
682 // TODO: use TextDecoder
683 // Find the length, and check for UTF while doing so
684 var hasUtf = 0;
685 var t;
686 var i = 0;
687 while (1) {
688 t = HEAPU8[(((ptr)+(i))>>0)];
689 hasUtf |= t;
690 if (t == 0 && !length) break;
691 i++;
692 if (length && i == length) break;
693 }
694 if (!length) length = i;
695
696 var ret = '';
697
698 if (hasUtf < 128) {
699 var MAX_CHUNK = 1024; // split up into chunks, because .apply on a huge string can overflow the stack
700 var curr;
701 while (length > 0) {
702 curr = String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + Math.min(length, MAX_CHUNK)));
703 ret = ret ? ret + curr : curr;
704 ptr += MAX_CHUNK;
705 length -= MAX_CHUNK;
706 }
707 return ret;
708 }
709 return UTF8ToString(ptr);
710}
711
712
713// Given a pointer 'ptr' to a null-terminated ASCII-encoded string in the emscripten HEAP, returns

Callers 5

ccallFunction · 0.70
___assert_failFunction · 0.70
sql-debug.jsFile · 0.70
_getenvFunction · 0.70
_utimesFunction · 0.70

Calls 1

UTF8ToStringFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…