diff --git a/src/library.js b/src/library.js index a7c92125c954..aab41cd1fa86 100644 --- a/src/library.js +++ b/src/library.js @@ -1534,7 +1534,7 @@ addToLibrary({ emscripten_log__deps: ['$formatString', '$emscriptenLog'], emscripten_log: (flags, format, varargs) => { var result = formatString(format, varargs); - var str = UTF8ArrayToString(result, 0); + var str = UTF8ArrayToString(result); emscriptenLog(flags, str); }, diff --git a/src/library_fs.js b/src/library_fs.js index c01999dfafcb..b5cf19e5d3a0 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -1303,7 +1303,7 @@ FS.staticInit(); var buf = new Uint8Array(length); FS.read(stream, buf, 0, length, 0); if (opts.encoding === 'utf8') { - ret = UTF8ArrayToString(buf, 0); + ret = UTF8ArrayToString(buf); } else if (opts.encoding === 'binary') { ret = buf; } diff --git a/src/library_strings.js b/src/library_strings.js index 72e61a7fe644..4931a316924e 100644 --- a/src/library_strings.js +++ b/src/library_strings.js @@ -20,14 +20,14 @@ addToLibrary({ * array that contains uint8 values, returns a copy of that string as a * Javascript String object. * heapOrArray is either a regular array, or a JavaScript typed array view. - * @param {number} idx + * @param {number=} idx * @param {number=} maxBytesToRead * @return {string} */`, #if TEXTDECODER $UTF8ArrayToString__deps: ['$UTF8Decoder'], #endif - $UTF8ArrayToString: (heapOrArray, idx, maxBytesToRead) => { + $UTF8ArrayToString: (heapOrArray, idx = 0, maxBytesToRead = NaN) => { #if CAN_ADDRESS_2GB idx >>>= 0; #endif @@ -38,7 +38,7 @@ addToLibrary({ // null terminator by itself. Also, use the length info to avoid running tiny // strings through TextDecoder, since .subarray() allocates garbage. // (As a tiny code save trick, compare endPtr against endIdx using a negation, - // so that undefined means Infinity) + // so that undefined/NaN means Infinity) while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr; #endif // TEXTDECODER diff --git a/src/library_tty.js b/src/library_tty.js index ed619cc838d8..28c1d5232d5a 100644 --- a/src/library_tty.js +++ b/src/library_tty.js @@ -106,7 +106,7 @@ addToLibrary({ }, put_char(tty, val) { if (val === null || val === {{{ charCode('\n') }}}) { - out(UTF8ArrayToString(tty.output, 0)); + out(UTF8ArrayToString(tty.output)); tty.output = []; } else { if (val != 0) tty.output.push(val); // val == 0 would cut text output off in the middle. @@ -114,7 +114,7 @@ addToLibrary({ }, fsync(tty) { if (tty.output && tty.output.length > 0) { - out(UTF8ArrayToString(tty.output, 0)); + out(UTF8ArrayToString(tty.output)); tty.output = []; } }, @@ -143,7 +143,7 @@ addToLibrary({ default_tty1_ops: { put_char(tty, val) { if (val === null || val === {{{ charCode('\n') }}}) { - err(UTF8ArrayToString(tty.output, 0)); + err(UTF8ArrayToString(tty.output)); tty.output = []; } else { if (val != 0) tty.output.push(val); @@ -151,7 +151,7 @@ addToLibrary({ }, fsync(tty) { if (tty.output && tty.output.length > 0) { - err(UTF8ArrayToString(tty.output, 0)); + err(UTF8ArrayToString(tty.output)); tty.output = []; } } diff --git a/src/library_wasi.js b/src/library_wasi.js index 3877a4f75f1c..ff78134aad0b 100644 --- a/src/library_wasi.js +++ b/src/library_wasi.js @@ -245,7 +245,7 @@ var WasiLibrary = { assert(buffer); #endif if (curr === 0 || curr === {{{ charCode('\n') }}}) { - (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)); + (stream === 1 ? out : err)(UTF8ArrayToString(buffer)); buffer.length = 0; } else { buffer.push(curr); diff --git a/src/library_wasmfs.js b/src/library_wasmfs.js index 982be847217e..b209d4be9ec9 100644 --- a/src/library_wasmfs.js +++ b/src/library_wasmfs.js @@ -146,7 +146,7 @@ FS.init(); // The buffer contents exist 8 bytes after the returned pointer. var ret = new Uint8Array(HEAPU8.subarray(buf + 8, buf + 8 + length)); if (opts.encoding === 'utf8') { - ret = UTF8ArrayToString(ret, 0); + ret = UTF8ArrayToString(ret); } return ret; diff --git a/src/source_map_support.js b/src/source_map_support.js index 7d8979b530ae..713cf017e65b 100644 --- a/src/source_map_support.js +++ b/src/source_map_support.js @@ -103,7 +103,7 @@ if (!isDataURI(wasmSourceMapFile)) { function getSourceMap() { var buf = readBinary(wasmSourceMapFile); - return JSON.parse(UTF8ArrayToString(buf, 0, buf.length)); + return JSON.parse(UTF8ArrayToString(buf)); } function getSourceMapPromise() { diff --git a/test/js_optimizer/applyImportAndExportNameChanges2-output.js b/test/js_optimizer/applyImportAndExportNameChanges2-output.js index 127893d00822..5da1dd336285 100644 --- a/test/js_optimizer/applyImportAndExportNameChanges2-output.js +++ b/test/js_optimizer/applyImportAndExportNameChanges2-output.js @@ -101,7 +101,7 @@ var SYSCALLS = { printChar: function(stream, curr) { var buffer = SYSCALLS.buffers[stream]; if (curr === 0 || curr === 10) { - (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)); + (stream === 1 ? out : err)(UTF8ArrayToString(buffer)); buffer.length = 0; } else { buffer.push(curr); diff --git a/test/js_optimizer/applyImportAndExportNameChanges2.js b/test/js_optimizer/applyImportAndExportNameChanges2.js index 0637f9162ff6..1900946eabfa 100644 --- a/test/js_optimizer/applyImportAndExportNameChanges2.js +++ b/test/js_optimizer/applyImportAndExportNameChanges2.js @@ -87,7 +87,7 @@ var SYSCALLS = { printChar: (function(stream, curr) { var buffer = SYSCALLS.buffers[stream]; if (curr === 0 || curr === 10) { - (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)); + (stream === 1 ? out : err)(UTF8ArrayToString(buffer)); buffer.length = 0 } else { buffer.push(curr) diff --git a/test/other/codesize/test_codesize_cxx_wasmfs.gzsize b/test/other/codesize/test_codesize_cxx_wasmfs.gzsize index 1ffa5bc74e2d..1547a9838ca6 100644 --- a/test/other/codesize/test_codesize_cxx_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_cxx_wasmfs.gzsize @@ -1 +1 @@ -3899 +3894 diff --git a/test/other/codesize/test_codesize_cxx_wasmfs.jssize b/test/other/codesize/test_codesize_cxx_wasmfs.jssize index 8fcfbb730380..4b31228cc86d 100644 --- a/test/other/codesize/test_codesize_cxx_wasmfs.jssize +++ b/test/other/codesize/test_codesize_cxx_wasmfs.jssize @@ -1 +1 @@ -8636 +8628 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index d9d9f4a8751e..c2334f0da43d 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7594 +7595 diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize index 3f86e3f051e8..8688021bf46f 100644 --- a/test/other/codesize/test_codesize_files_js_fs.jssize +++ b/test/other/codesize/test_codesize_files_js_fs.jssize @@ -1 +1 @@ -18702 +18696 diff --git a/test/other/codesize/test_codesize_files_wasmfs.gzsize b/test/other/codesize/test_codesize_files_wasmfs.gzsize index 9870e4a2f07e..3f59c1716c21 100644 --- a/test/other/codesize/test_codesize_files_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_files_wasmfs.gzsize @@ -1 +1 @@ -2984 +2976 diff --git a/test/other/codesize/test_codesize_files_wasmfs.jssize b/test/other/codesize/test_codesize_files_wasmfs.jssize index 8b3c3b919eea..f08c23793004 100644 --- a/test/other/codesize/test_codesize_files_wasmfs.jssize +++ b/test/other/codesize/test_codesize_files_wasmfs.jssize @@ -1 +1 @@ -6272 +6265 diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize index 1862acef2928..f8a3551b3f10 100644 --- a/test/other/codesize/test_codesize_hello_dylink.gzsize +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -1 +1 @@ -6319 +6326 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize index d9a47e815449..2dfa22ed7286 100644 --- a/test/other/codesize/test_codesize_hello_dylink.jssize +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -1 +1 @@ -13868 +13872 diff --git a/test/other/codesize/test_codesize_minimal_pthreads.gzsize b/test/other/codesize/test_codesize_minimal_pthreads.gzsize index 896626c774f6..3fc7764b32fa 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.gzsize +++ b/test/other/codesize/test_codesize_minimal_pthreads.gzsize @@ -1 +1 @@ -4948 +4951 diff --git a/test/other/codesize/test_codesize_minimal_pthreads.jssize b/test/other/codesize/test_codesize_minimal_pthreads.jssize index 95d444e5f38f..6cc48c769c97 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.jssize +++ b/test/other/codesize/test_codesize_minimal_pthreads.jssize @@ -1 +1 @@ -10453 +10465 diff --git a/test/other/test_emit_tsd.d.ts b/test/other/test_emit_tsd.d.ts index cae877ecbb9b..bb24bb177964 100644 --- a/test/other/test_emit_tsd.d.ts +++ b/test/other/test_emit_tsd.d.ts @@ -5,11 +5,11 @@ declare namespace RuntimeExports { * array that contains uint8 values, returns a copy of that string as a * Javascript String object. * heapOrArray is either a regular array, or a JavaScript typed array view. - * @param {number} idx + * @param {number=} idx * @param {number=} maxBytesToRead * @return {string} */ - function UTF8ArrayToString(heapOrArray: any, idx: number, maxBytesToRead?: number | undefined): string; + function UTF8ArrayToString(heapOrArray: any, idx?: number | undefined, maxBytesToRead?: number | undefined): string; let wasmTable: WebAssembly.Table; let HEAPF32: any; let HEAPF64: any; diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index 6542e5e29761..3d8ed4d2e73a 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -54846 +54854 diff --git a/test/other/test_unoptimized_code_size_no_asserts.js.size b/test/other/test_unoptimized_code_size_no_asserts.js.size index 16c36a8a4cdc..fe3034f39199 100644 --- a/test/other/test_unoptimized_code_size_no_asserts.js.size +++ b/test/other/test_unoptimized_code_size_no_asserts.js.size @@ -1 +1 @@ -30510 +30518 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index a98901eb67a7..f4faabd473a1 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -53824 +53832 diff --git a/test/test_other.py b/test/test_other.py index 9466f0566f88..0d5e3a4057b7 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -1691,7 +1691,7 @@ def test_module_stdout_stderr(self): Module['postRun'] = () => { assert(stderr.length === 0, 'stderr should be empty. \\n' + 'stderr: \\n' + stderr); - assert(UTF8ArrayToString(stdout, 0).startsWith('hello, world!'), 'stdout should start with the famous greeting. \\n' + + assert(UTF8ArrayToString(stdout).startsWith('hello, world!'), 'stdout should start with the famous greeting. \\n' + 'stdout: \\n' + stdout); } ''') diff --git a/test/wasmfs/wasmfs_readfile.c b/test/wasmfs/wasmfs_readfile.c index 36623832dfbf..1d10c2f5e9e6 100644 --- a/test/wasmfs/wasmfs_readfile.c +++ b/test/wasmfs/wasmfs_readfile.c @@ -31,7 +31,7 @@ int main() { EM_ASM({ var output = FS.readFile("/root/test"); - out(UTF8ArrayToString(output, 0)); + out(UTF8ArrayToString(output)); out("Length: " + output.byteLength); var err = FS.unlink("/root/test"); out("FS.unlink: " + err);