Ver Fonte

fix wasm runtime.js storeString to support Unicode

Laytan Laats há 1 ano atrás
pai
commit
d2ca91b830
1 ficheiros alterados com 5 adições e 2 exclusões
  1. 5 2
      vendor/wasm/js/runtime.js

+ 5 - 2
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;
 	}
 };