diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 4a9fabcd41f..fdbb21996a4 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -1306,13 +1306,12 @@ impl<'a> Context<'a> { while (true) {{ const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size); const {{ read, written }} = cachedTextEncoder.encodeInto(arg, view); - arg = arg.substring(read); - writeOffset += written; - if (arg.length === 0) {{ + if (read === arg.length) {{ break; }} - ptr = wasm.__wbindgen_realloc(ptr, size, size * 2); - size *= 2; + arg = arg.substring(read); + writeOffset += written; + ptr = wasm.__wbindgen_realloc(ptr, size, size += arg.length * 3); }} WASM_VECTOR_LEN = writeOffset; return ptr;