| 784 | Module['allocate'] = allocate; |
| 785 | |
| 786 | function 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 | } |
| 822 | Module['Pointer_stringify'] = Pointer_stringify; |
| 823 | |
| 824 | // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns |