Browse Source

Bug 19459.2: Don't let Cu.import pollute namespaces

Arthur Edelstein 3 years ago
parent
commit
e33d7c3ae6

+ 2 - 1
src/chrome/content/content-sizer.js

@@ -41,7 +41,8 @@ let torbuttonBundle = Services.strings.createBundle(
                         "chrome://torbutton/locale/torbutton.properties");
 
 // Import utility functions
-let { bindPrefAndInit, getEnv } = Cu.import("resource://torbutton/modules/utils.js");
+let { bindPrefAndInit, getEnv, observe } =
+    Cu.import("resource://torbutton/modules/utils.js", {});
 
 // __windowUtils(window)__.
 // See nsIDOMWindowUtils on MDN.

+ 1 - 1
src/chrome/content/preferences.js

@@ -3,7 +3,7 @@
 // Utilities
 let { utils: Cu } = Components;
 let { getBoolPref, getIntPref, setBoolPref, setIntPref } =
-    Cu.import("resource://gre/modules/Services.jsm").Services.prefs;
+    Cu.import("resource://gre/modules/Services.jsm", {}).Services.prefs;
 
 // Description elements have the follow names.
 const descNames =

+ 2 - 2
src/chrome/content/tor-circuit-display.js

@@ -31,10 +31,10 @@ Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 
 // Import the controller code.
-let { controller } = Cu.import("resource://torbutton/modules/tor-control-port.js");
+let { controller } = Cu.import("resource://torbutton/modules/tor-control-port.js", {});
 
 // Utility functions
-let { bindPrefAndInit } = Cu.import("resource://torbutton/modules/utils.js");
+let { bindPrefAndInit } = Cu.import("resource://torbutton/modules/utils.js", {});
 
 // Make the TorButton logger available.
 let logger = Cc["@torproject.org/torbutton-logger;1"]

+ 5 - 5
src/chrome/content/torbutton.js

@@ -7,11 +7,11 @@
 // TODO: Double-check there are no strange exploits to defeat:
 //       http://kb.mozillazine.org/Links_to_local_pages_don%27t_work
 
-let { LoadContextInfo } = Cu.import('resource://gre/modules/LoadContextInfo.jsm');
-let { Services } = Cu.import("resource://gre/modules/Services.jsm");
-let { showDialog } = Cu.import("resource://torbutton/modules/utils.js");
-let { unescapeTorString } = Cu.import("resource://torbutton/modules/utils.js");
-let SecurityPrefs = Cu.import("resource://torbutton/modules/security-prefs.js");
+let { LoadContextInfo } = Cu.import('resource://gre/modules/LoadContextInfo.jsm', {});
+let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+let { showDialog } = Cu.import("resource://torbutton/modules/utils.js", {});
+let { unescapeTorString } = Cu.import("resource://torbutton/modules/utils.js", {});
+let SecurityPrefs = Cu.import("resource://torbutton/modules/security-prefs.js", {});
 
 const k_tb_last_browser_version_pref = "extensions.torbutton.lastBrowserVersion";
 const k_tb_browser_update_needed_pref = "extensions.torbutton.updateNeeded";

+ 3 - 3
src/modules/security-prefs.js

@@ -4,9 +4,9 @@
 
 let {classes: Cc, utils: Cu } = Components;
 let { getBoolPref, setBoolPref, getIntPref, setIntPref } =
-    Cu.import("resource://gre/modules/Services.jsm").Services.prefs;
-let { bindPref } =
-    Cu.import("resource://torbutton/modules/utils.js");
+    Cu.import("resource://gre/modules/Services.jsm", {}).Services.prefs;
+let { bindPref, bindPrefAndInit } =
+    Cu.import("resource://torbutton/modules/utils.js", {});
 let logger = Components.classes["@torproject.org/torbutton-logger;1"]
     .getService(Components.interfaces.nsISupports).wrappedJSObject;
 let log = (level, msg) => logger.log(level, msg);

+ 1 - 1
src/modules/tor-control-port.js

@@ -7,7 +7,7 @@
 //
 // To import the module, use
 //
-//  let { controller } = Components.utils.import("path/to/tor-control-port.js");
+//  let { controller } = Components.utils.import("path/to/tor-control-port.js", {});
 //
 // See the last function defined in this file:
 //   controller(ipcFile, host, port, password, onError)