Skip to content

Commit

Permalink
fix wasm runtime.js storeString to support Unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
laytan committed Apr 13, 2024
1 parent 4240e00 commit d2ca91b
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 d2ca91b

Please sign in to comment.