Bug 1394479: Only override Services.scriptloader for XPCOMUtils. r?florian
Overriding Services.scriptloader has a lot of consequences in terms of path
name magling and choice of target global when no target object is passed.
Since this test code doesn't care about callers outside of XPCOMUtils, it
should only override the instance used by XPCOMUtils, and not the instance
used by other callers.
MozReview-Commit-ID: 2LEchjzn0U5
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -161,33 +161,41 @@ function Tester(aTests, structuredLogger
this.SimpleTestOriginal = {};
SIMPLETEST_OVERRIDES.forEach(m => {
this.SimpleTestOriginal[m] = this.SimpleTest[m];
});
this._coverageCollector = null;
+ const XPCOMUtilsMod = Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", {});
+
// Avoid failing tests when XPCOMUtils.defineLazyScriptGetter is used.
- Services.scriptloader = {
- loadSubScript: (url, obj, charset) => {
- let before = Object.keys(window);
- try {
- return this._scriptLoader.loadSubScript(url, obj, charset);
- } finally {
- for (let property of Object.keys(window)) {
- if (!before.includes(property) && !this._globalProperties.includes(property)) {
- this._globalProperties.push(property);
- this.SimpleTest.info("Global property added while loading " + url + ": " + property);
+ XPCOMUtilsMod.Services = Object.create(Services, {
+ scriptloader: {
+ configurable: true,
+ writable: true,
+ value: {
+ loadSubScript: (url, obj, charset) => {
+ let before = Object.keys(window);
+ try {
+ return this._scriptLoader.loadSubScript(url, obj, charset);
+ } finally {
+ for (let property of Object.keys(window)) {
+ if (!before.includes(property) && !this._globalProperties.includes(property)) {
+ this._globalProperties.push(property);
+ this.SimpleTest.info("Global property added while loading " + url + ": " + property);
+ }
+ }
}
- }
- }
+ },
+ loadSubScriptWithOptions: this._scriptLoader.loadSubScriptWithOptions.bind(this._scriptLoader),
+ },
},
- loadSubScriptWithOptions: this._scriptLoader.loadSubScriptWithOptions.bind(this._scriptLoader),
- };
+ });
}
Tester.prototype = {
EventUtils: {},
SimpleTest: {},
Task: null,
ContentTask: null,
ExtensionTestUtils: null,
Assert: null,