From c54e714ef5f591282d7fd5d4ec78e95d83a82b3f Mon Sep 17 00:00:00 2001 From: JustOff Date: Mon, 23 Apr 2018 14:52:50 +0300 Subject: [PATCH] Fix accessing the bootstrap methods when they are declared in the new lexical scope --- .../extensions/internal/XPIProvider.jsm | 17 ++++++++++--- .../addons/test_bootstrap_const/bootstrap.js | 5 ++++ .../addons/test_bootstrap_const/install.rdf | 24 +++++++++++++++++++ .../test/xpcshell/test_bootstrap_const.js | 17 +++++++++++++ .../test/xpcshell/xpcshell-shared.ini | 1 + 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 toolkit/mozapps/extensions/test/addons/test_bootstrap_const/bootstrap.js create mode 100644 toolkit/mozapps/extensions/test/addons/test_bootstrap_const/install.rdf create mode 100644 toolkit/mozapps/extensions/test/xpcshell/test_bootstrap_const.js diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm index 72a460e4aa..c43811ba8a 100644 --- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm @@ -4436,7 +4436,18 @@ this.XPIProvider = { if (aAddon.type == "locale") return; - if (!(aMethod in this.bootstrapScopes[aAddon.id])) { + let method = undefined; + try { + method = Components.utils.evalInSandbox(`${aMethod};`, + this.bootstrapScopes[aAddon.id], + "ECMAv5"); + } + catch (e) { + // An exception will be caught if the expected method is not defined. + // That will be logged below. + } + + if (!method) { logger.warn("Add-on " + aAddon.id + " is missing bootstrap method " + aMethod); return; } @@ -4455,9 +4466,9 @@ this.XPIProvider = { } logger.debug("Calling bootstrap method " + aMethod + " on " + aAddon.id + " version " + - aAddon.version); + aAddon.version); try { - this.bootstrapScopes[aAddon.id][aMethod](params, aReason); + method(params, aReason); } catch (e) { logger.warn("Exception running bootstrap method " + aMethod + " on " + aAddon.id, e); diff --git a/toolkit/mozapps/extensions/test/addons/test_bootstrap_const/bootstrap.js b/toolkit/mozapps/extensions/test/addons/test_bootstrap_const/bootstrap.js new file mode 100644 index 0000000000..498b76526f --- /dev/null +++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap_const/bootstrap.js @@ -0,0 +1,5 @@ +Components.utils.import("resource://gre/modules/Services.jsm"); + +const install = function() { + Services.obs.notifyObservers(null, "addon-install", ""); +} \ No newline at end of file diff --git a/toolkit/mozapps/extensions/test/addons/test_bootstrap_const/install.rdf b/toolkit/mozapps/extensions/test/addons/test_bootstrap_const/install.rdf new file mode 100644 index 0000000000..af3a749cef --- /dev/null +++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap_const/install.rdf @@ -0,0 +1,24 @@ + + + + + + bootstrap@tests.mozilla.org + 1.0 + true + + + Test Bootstrap + Test Description + + + + xpcshell@tests.mozilla.org + 1 + 1 + + + + + \ No newline at end of file diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap_const.js b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap_const.js new file mode 100644 index 0000000000..fb02b59be9 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap_const.js @@ -0,0 +1,17 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); +startupManager(); + +add_task(function*() { + let sawInstall = false; + Services.obs.addObserver(function() { + sawInstall = true; + }, "addon-install", false); + + yield promiseInstallAllFiles([do_get_addon("test_bootstrap_const")]); + + ok(sawInstall); +}); \ No newline at end of file diff --git a/toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini b/toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini index bab072e830..2a12f147a6 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini +++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini @@ -29,6 +29,7 @@ skip-if = os == "android" [test_bootstrap.js] # Bug 676992: test consistently hangs on Android skip-if = os == "android" +[test_bootstrap_const.js] [test_bootstrap_resource.js] [test_bug299716.js] # Bug 676992: test consistently hangs on Android