From 2189f020dfb5d2d8728c17ead85e6f7905e3e984 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 16 Nov 2018 10:19:06 -0500 Subject: [PATCH] add new advanced setting to disable use of WASM for dev purpose --- src/js/background.js | 3 ++- src/js/hntrie.js | 9 +++++++++ src/js/lz4.js | 6 +++++- src/js/storage.js | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 75b4b5a50..f0f5b7945 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -44,8 +44,9 @@ const µBlock = (function() { // jshint ignore:line autoUpdatePeriod: 7, benchmarkingPane: false, cacheStorageCompression: true, - debugScriptlets: false, cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate', + debugScriptlets: false, + disableWebAssembly: false, ignoreRedirectFilters: false, ignoreScriptInjectFilters: false, manualUpdateAssetFetchPeriod: 500, diff --git a/src/js/hntrie.js b/src/js/hntrie.js index 381fcb451..0cf6b1da9 100644 --- a/src/js/hntrie.js +++ b/src/js/hntrie.js @@ -467,6 +467,15 @@ const hnTrieManager = { return; } + // Soft-dependency on µBlock's advanced settings so that the code here can + // be used outside of uBO (i.e. tests, benchmarks) + if ( + typeof µBlock === 'object' && + µBlock.hiddenSettings.disableWebAssembly === true + ) { + return; + } + // The wasm module will work only if CPU is natively little-endian, // as we use native uint32 array in our trie-creation js code. const uint32s = new Uint32Array(1); diff --git a/src/js/lz4.js b/src/js/lz4.js index 05a89273e..b81a45e12 100644 --- a/src/js/lz4.js +++ b/src/js/lz4.js @@ -52,7 +52,11 @@ let init = function() { return Promise.resolve(lz4CodecInstance); } if ( pendingInitialization === undefined ) { - pendingInitialization = lz4BlockCodec.createInstance() + let flavor; + if ( µBlock.hiddenSettings.disableWebAssembly === true ) { + flavor = 'js'; + } + pendingInitialization = lz4BlockCodec.createInstance(flavor) .then(instance => { lz4CodecInstance = instance; pendingInitialization = undefined; diff --git a/src/js/storage.js b/src/js/storage.js index e76578596..05dc0e729 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -186,6 +186,7 @@ vAPI.localStorage.setItem( 'immediateHiddenSettings', JSON.stringify({ + disableWebAssembly: this.hiddenSettings.disableWebAssembly, suspendTabsUntilReady: this.hiddenSettings.suspendTabsUntilReady, userResourcesLocation: this.hiddenSettings.userResourcesLocation })