From c8ad85dd0b00cbf608da3ff6f19b39939dece8e8 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Sun, 10 Feb 2019 13:39:11 -0500 Subject: [PATCH 1/2] Use `unwrap_throw` instead of normal `unwrap` for JsString -> String conversion Should have less code size. --- crates/js-sys/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 556b827f..a74802a4 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -4339,7 +4339,7 @@ impl From for JsString { impl<'a> From<&'a JsString> for String { fn from(s: &'a JsString) -> Self { - s.obj.as_string().unwrap() + s.obj.as_string().unwrap_throw() } } From 4975ca295430f7e4b9faa9861e1f45ef824044e6 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Sun, 10 Feb 2019 13:58:13 -0500 Subject: [PATCH 2/2] Don't give up when servers don't set the application/wasm MIME type It is quite annoying when using `python -m SimpleHTTPServer` or equivalent. --- crates/cli-support/src/js/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 8d86487c..c315bc39 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -612,7 +612,17 @@ impl<'a> Context<'a> { memory = __exports.memory = {init_memory}; const response = fetch(module_or_path); if (typeof WebAssembly.instantiateStreaming === 'function') {{ - result = WebAssembly.instantiateStreaming(response, imports); + result = WebAssembly.instantiateStreaming(response, imports) + .catch(e => {{ + console.warn(\"`WebAssembly.instantiateStreaming` failed. Assuming this is \ + because your server does not serve wasm with \ + `application/wasm` MIME type. Falling back to \ + `WebAssembly.instantiate` which is slower. Original \ + error:\\n\", e); + return response + .then(r => r.arrayBuffer()) + .then(bytes => WebAssembly.instantiate(bytes, imports)); + }}); }} else {{ result = response .then(r => r.arrayBuffer())