@type {function(number, number=)}
(ptr, length)
| 678 | |
| 679 | /** @type {function(number, number=)} */ |
| 680 | function 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 |
no test coverage detected
searching dependent graphs…