Fix offset to arg comparison

This commit is contained in:
Ingvar Stepanyan 2019-05-10 15:31:59 +01:00
parent 7418cec613
commit 0c681ee2ba

View File

@ -1464,10 +1464,7 @@ impl<'a> Context<'a> {
const mem = getUint8Memory(); const mem = getUint8Memory();
for (; offset < arg.length; offset++) {{ for (; offset < arg.length; offset++) {{
const code = arg.charCodeAt(offset); const code = arg.charCodeAt(offset);
if (code > 0x7F) {{ if (code > 0x7F) break;
arg = arg.slice(offset);
break;
}}
mem[ptr + offset] = code; mem[ptr + offset] = code;
}} }}
}} }}
@ -1481,7 +1478,7 @@ impl<'a> Context<'a> {
" "
{} {}
if (offset !== arg.length) {{ if (offset !== arg.length) {{
const buf = cachedTextEncoder.encode(arg); const buf = cachedTextEncoder.encode(arg.slice(offset));
ptr = wasm.__wbindgen_realloc(ptr, size, size = offset + buf.length); ptr = wasm.__wbindgen_realloc(ptr, size, size = offset + buf.length);
getUint8Memory().set(buf, ptr + offset); getUint8Memory().set(buf, ptr + offset);
offset += buf.length; offset += buf.length;
@ -1499,6 +1496,7 @@ impl<'a> Context<'a> {
" "
{} {}
if (offset !== arg.length) {{ if (offset !== arg.length) {{
arg = arg.slice(offset);
ptr = wasm.__wbindgen_realloc(ptr, size, size = offset + arg.length * 3); ptr = wasm.__wbindgen_realloc(ptr, size, size = offset + arg.length * 3);
const view = getUint8Memory().subarray(ptr + offset, ptr + size); const view = getUint8Memory().subarray(ptr + offset, ptr + size);
offset += cachedTextEncoder.encodeInto(arg, view).written; offset += cachedTextEncoder.encodeInto(arg, view).written;