From 6d5afbb3d222f52977fefdc56c3fb5b460c36530 Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 3 Apr 2018 22:36:17 +0200 Subject: [PATCH 1/3] reduce the js file generated code remove node test for browser test update usages revert test-support changes --- crates/cli-support/src/js.rs | 20 ++++---------------- crates/test-support/src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/crates/cli-support/src/js.rs b/crates/cli-support/src/js.rs index 6ab6b96e..2ef67d95 100644 --- a/crates/cli-support/src/js.rs +++ b/crates/cli-support/src/js.rs @@ -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)); }} ")); } diff --git a/crates/test-support/src/lib.rs b/crates/test-support/src/lib.rs index d05f9364..cdd33347 100644 --- a/crates/test-support/src/lib.rs +++ b/crates/test-support/src/lib.rs @@ -272,4 +272,4 @@ fn run(cmd: &mut Command, program: &str) { println!("stderr ---\n{}", String::from_utf8_lossy(&output.stderr)); } assert!(output.status.success()); -} +} \ No newline at end of file From 9421edaab5fce92cc901a5afa1dc67d0eae15ac7 Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Wed, 4 Apr 2018 11:22:13 +0200 Subject: [PATCH 2/3] add missed out TextEncoder --- crates/cli-support/src/js.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli-support/src/js.rs b/crates/cli-support/src/js.rs index 2ef67d95..b7f4d6d3 100644 --- a/crates/cli-support/src/js.rs +++ b/crates/cli-support/src/js.rs @@ -655,7 +655,7 @@ impl<'a> Context<'a> { } if self.config.nodejs { self.globals.push_str(&format!(" - const TextEncoder = require('util'); + const TextEncoder = require('util').TextEncoder; ")); } else if !self.config.browser { self.globals.push_str(&format!(" From 64d7c8d0824e7bfc6373cdb4d091b5415693f299 Mon Sep 17 00:00:00 2001 From: Sendil Kumar N Date: Wed, 4 Apr 2018 11:27:27 +0200 Subject: [PATCH 3/3] Update lib.rs --- crates/test-support/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/test-support/src/lib.rs b/crates/test-support/src/lib.rs index cdd33347..d05f9364 100644 --- a/crates/test-support/src/lib.rs +++ b/crates/test-support/src/lib.rs @@ -272,4 +272,4 @@ fn run(cmd: &mut Command, program: &str) { println!("stderr ---\n{}", String::from_utf8_lossy(&output.stderr)); } assert!(output.status.success()); -} \ No newline at end of file +}