mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Merge pull request #3420 from laytan/fix-wasm-runtime-store-string-with-unicode
fix wasm runtime.js storeString to support Unicode
This commit is contained in:
Vendored
+5
-2
@@ -104,9 +104,12 @@ class WasmMemoryInterface {
|
|||||||
storeInt(addr, value) { this.mem.setInt32 (addr, value, true); }
|
storeInt(addr, value) { this.mem.setInt32 (addr, value, true); }
|
||||||
storeUint(addr, value) { this.mem.setUint32 (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) {
|
storeString(addr, value) {
|
||||||
const bytes = this.loadBytes(addr, value.length);
|
const src = new TextEncoder().encode(value);
|
||||||
new TextEncoder().encodeInto(value, bytes);
|
const dst = new Uint8Array(this.memory.buffer, addr, src.length);
|
||||||
|
dst.set(src);
|
||||||
|
return src.length;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user