Commit e930b89c authored by Kris Maglione's avatar Kris Maglione
Browse files

Bug 1514594: Part 3 - Change ChromeUtils.import API.

***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8

This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:

  ChromeUtils.import("resource://gre/modules/Services.jsm");

is approximately the same as the following, in the new model:

  var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");

Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs

This was done using the followng script:

https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16750

--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
parent 8fd72369
......@@ -6,8 +6,8 @@
var EXPORTED_SYMBOLS = ["AccessFu"];
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const {Logger, Utils} = ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
ChromeUtils.defineModuleGetter(this, "Rect",
"resource://gre/modules/Geometry.jsm");
......@@ -51,8 +51,6 @@ var AccessFu = {
}
this._enabled = true;
ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
Services.obs.addObserver(this, "remote-browser-shown");
Services.obs.addObserver(this, "inprocess-browser-shown");
Services.ww.registerNotification(this);
......
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const AndroidEvents = {
VIEW_CLICKED: 0x01,
......
......@@ -6,7 +6,7 @@
var EXPORTED_SYMBOLS = ["TraversalRules", "TraversalHelper"]; // jshint ignore:line
ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
const {PrefCache, Utils} = ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
ChromeUtils.defineModuleGetter(this, "Roles", // jshint ignore:line
"resource://gre/modules/accessibility/Constants.jsm");
ChromeUtils.defineModuleGetter(this, "Filters", // jshint ignore:line
......
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
var {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
/**
* Load the browser with the given url and then invokes the given function.
......@@ -91,7 +91,7 @@ function reloadButton() {
// //////////////////////////////////////////////////////////////////////////////
// private section
ChromeUtils.import("resource://gre/modules/Services.jsm");
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var gBrowserContext =
{
......
......@@ -87,7 +87,7 @@ const MAX_TRIM_LENGTH = 100;
/**
* Services to determine if e10s is enabled.
*/
ChromeUtils.import("resource://gre/modules/Services.jsm");
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
/**
* nsIAccessibilityService service.
......
......@@ -40,7 +40,7 @@ const kFromUserInput = 1;
// //////////////////////////////////////////////////////////////////////////////
// General
ChromeUtils.import("resource://gre/modules/Services.jsm");
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
/**
* Set up this variable to dump events into DOM.
......
......@@ -88,7 +88,7 @@
function doTests() {
// Front end stuff sometimes likes to stuff things in the hidden window(s)
// in which case we should repress all accessibles for those.
ChromeUtils.import("resource://gre/modules/Services.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// Try to create an accessible for the hidden window's document.
let doc = Services.appShell.hiddenDOMWindow.document;
......
......@@ -110,7 +110,7 @@
function doTests() {
// Front end stuff sometimes likes to stuff things in the hidden window(s)
// in which case we should repress all accessibles for those.
ChromeUtils.import("resource://gre/modules/Services.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// Try to create an accessible for the hidden window's document.
let doc = Services.appShell.hiddenDOMWindow.document;
......
......@@ -24,7 +24,7 @@
<script type="application/javascript">
ChromeUtils.import("resource://gre/modules/InlineSpellChecker.jsm");
const {InlineSpellChecker} = ChromeUtils.import("resource://gre/modules/InlineSpellChecker.jsm");
function spelledTextInvoker(aID) {
this.DOMNode = getNode(aID);
......
......@@ -2,8 +2,8 @@
"use strict";
/* global isDeeply, getMainChromeWindow, SimpleTest, SpecialPowers, Logger,
AccessFu, Utils, addMessageListener, currentTabDocument, currentBrowser*/
/* global isDeeply, getMainChromeWindow, SimpleTest, SpecialPowers,
addMessageListener, currentTabDocument, currentBrowser*/
/**
* A global variable holding an array of test functions.
......@@ -14,8 +14,9 @@ var gTestFuncs = [];
*/
var gIterator;
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var AccessFu;
const {Logger, Utils} = ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
const MovementGranularity = {
CHARACTER: 1,
......@@ -143,7 +144,7 @@ var AccessFuTest = {
Logger.logLevel = Logger.DEBUG;
// Start AccessFu and put it in stand-by.
ChromeUtils.import("resource://gre/modules/accessibility/AccessFu.jsm");
({AccessFu} = ChromeUtils.import("resource://gre/modules/accessibility/AccessFu.jsm"));
var prefs = [["accessibility.accessfu.notify_output", 1]];
prefs.push.apply(prefs, aAdditionalPrefs);
......@@ -213,7 +214,8 @@ class AccessFuContentTestRunner {
async setupMessageManager(aMessageManager) {
function contentScript() {
ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
// eslint-disable-next-line no-shadow
const {Logger, Utils} = ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
Logger.logLevel = "DEBUG";
Utils.inTest = true;
......
const PREF_UTTERANCE_ORDER = "accessibility.accessfu.utterance";
ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
const {PivotContext} = ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
ChromeUtils.import("resource://gre/modules/accessibility/OutputGenerator.jsm", this);
/**
......
......@@ -21,7 +21,7 @@
<script type="application/javascript" src="../layout.js"></script>
<script type="application/javascript">
ChromeUtils.import("resource://gre/modules/accessibility/Traversal.jsm");
const {TraversalRules} = ChromeUtils.import("resource://gre/modules/accessibility/Traversal.jsm");
var gBrowserWnd = null;
var gQueue = null;
......
......@@ -21,7 +21,7 @@
<script type="application/javascript" src="../layout.js"></script>
<script type="application/javascript">
ChromeUtils.import("resource://gre/modules/accessibility/Traversal.jsm");
const {TraversalHelper} = ChromeUtils.import("resource://gre/modules/accessibility/Traversal.jsm");
var vc;
......
......@@ -6,7 +6,7 @@
var EXPORTED_SYMBOLS = ["AboutReaderChild"];
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
ChromeUtils.defineModuleGetter(this, "AboutReader",
"resource://gre/modules/AboutReader.jsm");
......
......@@ -3,11 +3,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
ChromeUtils.import("resource://gre/modules/Services.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var EXPORTED_SYMBOLS = ["BlockedSiteChild"];
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
ChromeUtils.defineModuleGetter(this, "Utils",
"resource://gre/modules/sessionstore/Utils.jsm");
......
......@@ -6,7 +6,7 @@
var EXPORTED_SYMBOLS = ["BrowserTabChild"];
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
ChromeUtils.defineModuleGetter(this, "E10SUtils",
"resource://gre/modules/E10SUtils.jsm");
......
......@@ -5,8 +5,8 @@
var EXPORTED_SYMBOLS = ["ClickHandlerChild"];
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(this, "BrowserUtils",
"resource://gre/modules/BrowserUtils.jsm");
......
......@@ -6,7 +6,7 @@
var EXPORTED_SYMBOLS = ["ContentSearchChild"];
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
class ContentSearchChild extends ActorChild {
handleEvent(event) {
......
......@@ -8,10 +8,10 @@
var EXPORTED_SYMBOLS = ["ContextMenuChild"];
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
......
......@@ -6,7 +6,7 @@
var EXPORTED_SYMBOLS = ["DOMFullscreenChild"];
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
class DOMFullscreenChild extends ActorChild {
receiveMessage(aMessage) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment