From 26c07431ee23d2c355798b940224ff830e1b6a4f Mon Sep 17 00:00:00 2001 From: Paul Shapiro Date: Thu, 1 Nov 2018 17:39:20 -0500 Subject: [PATCH] monero_utils: bringing wasm detection out of monero_utils-exported constructor (so it only has to be done once) --- monero_utils/monero_utils.js | 45 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/monero_utils/monero_utils.js b/monero_utils/monero_utils.js index 88d864d..5519118 100644 --- a/monero_utils/monero_utils.js +++ b/monero_utils/monero_utils.js @@ -34,6 +34,29 @@ const ENVIRONMENT_IS_NODE = typeof process==="object" && process.browser !== tru const wants_electronRemote = (ENVIRONMENT_IS_NODE&&ENVIRONMENT_IS_WEB)/*this may become insufficient*/ || (typeof window !== 'undefined' && window.IsElectronRendererProcess == true); // +var use_asmjs = false; +if (ENVIRONMENT_IS_WEB) { + var hasWebAssembly = false + try { + if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") { + const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); + if (module instanceof WebAssembly.Module) { + var isInstance = new WebAssembly.Instance(module) instanceof WebAssembly.Instance; + if (isInstance) { + // TODO: add ios 11 mobile safari bug check to hasWebAssembly + } + // until then… + hasWebAssembly = isInstance + } + } + } catch (e) { + // avoiding empty block statement warning.. + hasWebAssembly = false // to be clear + } + use_asmjs = hasWebAssembly != true +} +console.log("Using wasm: ", !use_asmjs) +// const fn_names = require('./__bridged_fns_spec').bridgedFn_names; const moneroUtils_promise_fn = function(options) { @@ -100,28 +123,6 @@ const moneroUtils_promise_fn = function(options) } _try(0) } else { - var use_asmjs = false; - if (ENVIRONMENT_IS_WEB) { - var hasWebAssembly = false - try { - if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") { - const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); - if (module instanceof WebAssembly.Module) { - var isInstance = new WebAssembly.Instance(module) instanceof WebAssembly.Instance; - if (isInstance) { - // TODO: add ios 11 mobile safari bug check to hasWebAssembly - } - // until then… - hasWebAssembly = isInstance - } - } - } catch (e) { - // avoiding empty block statement warning.. - hasWebAssembly = false // to be clear - } - use_asmjs = hasWebAssembly != true - } - console.log("Using wasm: ", !use_asmjs) const coreBridgeLoading_promise = require('./MyMoneroCoreBridge')({ asmjs: use_asmjs }); coreBridgeLoading_promise.catch(function(e) {