reduce the js file generated code

remove node test for browser test

update usages

revert test-support changes
This commit is contained in:
Sendil Kumar 2018-04-03 22:36:17 +02:00
parent 40e1ee4484
commit 6d5afbb3d2
2 changed files with 5 additions and 17 deletions

View File

@ -568,7 +568,7 @@ impl<'a> Context<'a> {
self.globals.push_str(&format!("
function passStringToWasm(arg) {{
{}
const buf = textEncoder().encode(arg);
const buf = cachedEncoder.encode(arg);
const ptr = wasm.__wbindgen_malloc(buf.length);
getUint8Memory().set(buf, ptr);
return [ptr, buf.length];
@ -665,13 +665,7 @@ impl<'a> Context<'a> {
"));
}
self.globals.push_str(&format!("
let cachedEncoder = null;
function textEncoder() {{
if (cachedEncoder)
return cachedEncoder;
cachedEncoder = new TextEncoder('utf-8');
return cachedEncoder;
}}
let cachedEncoder = new TextEncoder('utf-8');
"));
}
@ -691,13 +685,7 @@ impl<'a> Context<'a> {
"));
}
self.globals.push_str(&format!("
let cachedDecoder = null;
function textDecoder() {{
if (cachedDecoder)
return cachedDecoder;
cachedDecoder = new TextDecoder('utf-8');
return cachedDecoder;
}}
let cachedDecoder = new TextDecoder('utf-8');
"));
}
@ -709,7 +697,7 @@ impl<'a> Context<'a> {
self.expose_uint8_memory();
self.globals.push_str(&format!("
function getStringFromWasm(ptr, len) {{
return textDecoder().decode(getUint8Memory().slice(ptr, ptr + len));
return cachedDecoder.decode(getUint8Memory().slice(ptr, ptr + len));
}}
"));
}

View File

@ -272,4 +272,4 @@ fn run(cmd: &mut Command, program: &str) {
println!("stderr ---\n{}", String::from_utf8_lossy(&output.stderr));
}
assert!(output.status.success());
}
}