diff --git a/.eslintrc.json b/.eslintrc.json index e7ca071..e1d4de0 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -29,6 +29,7 @@ "brace-style": ["error", "stroustrup", {"allowSingleLine": true}], "comma-spacing": ["error", { "before": false, "after": true }], "complexity": ["warn", 20], + "consistent-return": "error", "constructor-super": "warn", "eqeqeq": "error", "eslint-comments/no-use": ["error", {"allow": ["eslint-disable-next-line"]}], diff --git a/lib/iframeProtection.js b/lib/iframeProtection.js index 95d0278..dc1f838 100644 --- a/lib/iframeProtection.js +++ b/lib/iframeProtection.js @@ -45,7 +45,7 @@ } else { if (isWhitelisted(window.location)){ - return; + return false; } } return changeProperty; @@ -265,6 +265,10 @@ scope.protect = function protect(window, wrappedWindow, singleCallback, allCallback){ const changeProperty = createChangeProperty(window); + if (!changeProperty){ + return; + } + const api = {window, wrappedWindow, changeProperty, singleCallback, allCallback}; protectFrameProperties(api); diff --git a/lib/intercept.js b/lib/intercept.js index 56dee6f..58c7588 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -174,7 +174,7 @@ functionName: name, dataURL: false }); - return; + return undef; } }, windowToProcess), set: exportFunction(function(){}, windowToProcess) diff --git a/lib/logging.js b/lib/logging.js index ac98d44..50c1e9d 100644 --- a/lib/logging.js +++ b/lib/logging.js @@ -20,6 +20,7 @@ } else { warning("logging: Settings can only be set once."); + return settings.loaded; } }; diff --git a/lib/modifiedScreenAPI.js b/lib/modifiedScreenAPI.js index 9630ca2..02c2127 100644 --- a/lib/modifiedScreenAPI.js +++ b/lib/modifiedScreenAPI.js @@ -89,6 +89,26 @@ return window.screen; } + function fakeWidth(args, check){ + const {prefs, notify, window, original} = check; + const originalValue = original.apply(this, window.Array.from(args)); + const returnValue = Math.round(getScreenDimensions(prefs, window).width); + if (originalValue !== returnValue){ + notify("fakedScreenReadout"); + } + return returnValue; + } + + function fakeHeight(args, check){ + const {prefs, notify, window, original} = check; + const originalValue = original.apply(this, window.Array.from(args)); + const returnValue = Math.round(getScreenDimensions(prefs, window).height); + if (originalValue !== returnValue){ + notify("fakedScreenReadout"); + } + return returnValue; + } + scope.changedGetters = [ { objectGetters: [function(window){return window.Screen && window.Screen.prototype;}], @@ -96,15 +116,7 @@ getterGenerator: function(checker){ const temp = { get width(){ - return checkerWrapper(checker, this, arguments, function(args, check){ - const {prefs, notify, window, original} = check; - const originalValue = original.apply(this, window.Array.from(args)); - const returnValue = Math.round(getScreenDimensions(prefs, window).width); - if (originalValue !== returnValue){ - notify("fakedScreenReadout"); - } - return returnValue; - }); + return checkerWrapper(checker, this, arguments, fakeWidth); } }; return Object.getOwnPropertyDescriptor(temp, "width").get; @@ -116,15 +128,7 @@ getterGenerator: function(checker){ const temp = { get height(){ - return checkerWrapper(checker, this, arguments, function(args, check){ - const {prefs, notify, window, original} = check; - const originalValue = original.apply(this, window.Array.from(args)); - const returnValue = Math.round(getScreenDimensions(prefs, window).height); - if (originalValue !== returnValue){ - notify("fakedScreenReadout"); - } - return returnValue; - }); + return checkerWrapper(checker, this, arguments, fakeHeight); } }; return Object.getOwnPropertyDescriptor(temp, "height").get; @@ -136,15 +140,7 @@ getterGenerator: function(checker){ const temp = { get availWidth(){ - return checkerWrapper(checker, this, arguments, function(args, check){ - const {prefs, notify, window, original} = check; - const originalValue = original.apply(this, window.Array.from(args)); - const returnValue = Math.round(getScreenDimensions(prefs, window).width); - if (originalValue !== returnValue){ - notify("fakedScreenReadout"); - } - return returnValue; - }); + return checkerWrapper(checker, this, arguments, fakeWidth); } }; return Object.getOwnPropertyDescriptor(temp, "availWidth").get; @@ -156,15 +152,7 @@ getterGenerator: function(checker){ const temp = { get availHeight(){ - return checkerWrapper(checker, this, arguments, function(args, check){ - const {prefs, notify, window, original} = check; - const originalValue = original.apply(this, window.Array.from(args)); - const returnValue = Math.round(getScreenDimensions(prefs, window).height); - if (originalValue !== returnValue){ - notify("fakedScreenReadout"); - } - return returnValue; - }); + return checkerWrapper(checker, this, arguments, fakeHeight); } }; return Object.getOwnPropertyDescriptor(temp, "availHeight").get; diff --git a/lib/settings.js b/lib/settings.js index a639586..d2e4ded 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -146,6 +146,7 @@ } else { logging.warning("Transient setting %s cannot be stored.", name); + return Promise.reject("Transient setting " + name + " cannot be stored."); } }; @@ -162,6 +163,7 @@ } else{ logging.warning("Invalid value for %s (%s):", name, url, newValue); + return Promise.reject("Invalid value for " + name + " (" + url + "): " + newValue); } }; } @@ -173,6 +175,7 @@ } else{ logging.warning("Invalid value for %s:", name, newValue); + return Promise.reject("Invalid value for " + name + ": " + newValue); } }; } @@ -307,6 +310,7 @@ } else { logging.error("Try to set unknown setting:", name); + return Promise.reject("Try to set unknown setting: " + name); } }; scope.get = function(name, ...args){ @@ -316,6 +320,7 @@ } else { logging.error("Try to get unknown setting:", name); + return undefined; } }; diff --git a/options/options.js b/options/options.js index cd09237..ec64241 100644 --- a/options/options.js +++ b/options/options.js @@ -614,7 +614,7 @@ if (reallyShare){ return this.originalSet(value, ...args); } - return; + return false; }).catch(function(error){ logging.warning("Unable to set sharePersistentRndBetweenDomains:", error); }); diff --git a/options/whitelist.js b/options/whitelist.js index d238d8c..440d789 100644 --- a/options/whitelist.js +++ b/options/whitelist.js @@ -85,6 +85,7 @@ setSelect.selectedIndex = index; return true; } + return false; }) && searchParameters.has("domain") ){ diff --git a/pageAction/pageAction.js b/pageAction/pageAction.js index 37790e6..14f908c 100644 --- a/pageAction/pageAction.js +++ b/pageAction/pageAction.js @@ -65,7 +65,7 @@ if (choice){ return settings.set("showNotifications", false, choice); } - return; + return false; }).then(function(){ return window.close(); }); @@ -123,7 +123,7 @@ if (choice){ return settings.set(setting.name, setting.value, choice); } - return; + return false; }).then(function(){ return window.close(); }); @@ -142,7 +142,7 @@ if (choice){ return lists.appendTo("sessionWhite", choice); } - return; + return false; }).then(function(){ return window.close(); }); diff --git a/releaseNotes.txt b/releaseNotes.txt index a75bc42..b6e34d6 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -1,6 +1,7 @@ Version 0.5.15: changes: - improved storage of protected API features + - code cleanup new features: - added screen protection