From d2ca91b830b8c57396e65c3ada846fee188a83c7 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sat, 13 Apr 2024 19:32:22 +0200 Subject: [PATCH] fix wasm runtime.js storeString to support Unicode --- vendor/wasm/js/runtime.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vendor/wasm/js/runtime.js b/vendor/wasm/js/runtime.js index 2e69a28c7..320d74d68 100644 --- a/vendor/wasm/js/runtime.js +++ b/vendor/wasm/js/runtime.js @@ -104,9 +104,12 @@ class WasmMemoryInterface { storeInt(addr, value) { this.mem.setInt32 (addr, value, true); } storeUint(addr, value) { this.mem.setUint32 (addr, value, true); } + // Returned length might not be the same as `value.length` if non-ascii strings are given. storeString(addr, value) { - const bytes = this.loadBytes(addr, value.length); - new TextEncoder().encodeInto(value, bytes); + const src = new TextEncoder().encode(value); + const dst = new Uint8Array(this.memory.buffer, addr, src.length); + dst.set(src); + return src.length; } };