Skip to content

Commit

Permalink
Merge pull request #3420 from laytan/fix-wasm-runtime-store-string-wi…
Browse files Browse the repository at this point in the history
…th-unicode

fix wasm runtime.js storeString to support Unicode
  • Loading branch information
gingerBill committed Apr 13, 2024
2 parents 5970503 + d2ca91b commit 6dc9fdb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vendor/wasm/js/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down

0 comments on commit 6dc9fdb

Please sign in to comment.