Bug 1522608 - remove uses of eval() in IMAP tests and Overlay.jsm. r=aceman
authorGeoff Lankow <geoff@darktrojan.net>
Sat, 26 Jan 2019 05:37:00 +0100
changeset 33453 be6ed62ca1ec
parent 33452 0396f1f1c7a7
child 33454 63b3267ac3ba
push id2368
push userclokep@gmail.com
push dateMon, 28 Jan 2019 21:12:50 +0000
treeherdercomm-beta@56d23c07d815 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs1522608
Bug 1522608 - remove uses of eval() in IMAP tests and Overlay.jsm. r=aceman
common/src/Overlays.jsm
mailnews/imap/test/unit/head_server.js
mailnews/test/resources/IMAPpump.js
--- a/common/src/Overlays.jsm
+++ b/common/src/Overlays.jsm
@@ -476,19 +476,20 @@ class Overlays {
       try {
         Services.scriptloader.loadSubScript(url, this.window);
       } catch (ex) {
         Cu.reportError(ex);
       }
     } else if (node.textContent) {
       oconsole.debug(`Loading eval'd script into ${this.window.location}`);
       try {
+        let dataURL = "data:application/javascript," + encodeURIComponent(node.textContent);
         // It would be great if we could have script errors show the right url, but for now
-        // window.eval will have to do.
-        this.window.eval(node.textContent);
+        // loadSubScript will have to do.
+        Services.scriptloader.loadSubScript(dataURL, this.window);
       } catch (ex) {
         Cu.reportError(ex);
       }
     }
 
     if (this.document.readyState == "complete") {
       this.window.addEventListener = oldAddEventListener;
     }
--- a/mailnews/imap/test/unit/head_server.js
+++ b/mailnews/imap/test/unit/head_server.js
@@ -17,32 +17,34 @@ var CC = Components.Constructor;
 ChromeUtils.import("resource://testing-common/AppInfo.jsm");
 updateAppInfo();
 
 // Ensure the profile directory is set up
 do_get_profile();
 
 // Import fakeserver
 ChromeUtils.import("resource://testing-common/mailnews/maild.js");
-ChromeUtils.import("resource://testing-common/mailnews/imapd.js");
+var imapd = {};
+ChromeUtils.import("resource://testing-common/mailnews/imapd.js", imapd);
+var { imapDaemon, imapMessage } = imapd;
 ChromeUtils.import("resource://testing-common/mailnews/auth.js");
 
 function makeServer(daemon, infoString, otherProps) {
-  if (infoString in configurations)
-    return makeServer(daemon, configurations[infoString].join(","), otherProps);
+  if (infoString in imapd.configurations)
+    return makeServer(daemon, imapd.configurations[infoString].join(","), otherProps);
 
   function createHandler(d) {
-    var handler = new IMAP_RFC3501_handler(d);
+    var handler = new imapd.IMAP_RFC3501_handler(d);
     if (!infoString)
       infoString = "RFC2195";
 
     var parts = infoString.split(/ *, */);
     for (var part of parts) {
       if (part.startsWith("RFC"))
-        mixinExtension(handler, eval("IMAP_" + part + "_extension"));
+        imapd.mixinExtension(handler, imapd["IMAP_" + part + "_extension"]);
     }
     if (otherProps) {
       for (var prop in otherProps)
         handler[prop] = otherProps[prop];
     }
     return handler;
   }
   var server = new nsMailServer(createHandler, daemon);
--- a/mailnews/test/resources/IMAPpump.js
+++ b/mailnews/test/resources/IMAPpump.js
@@ -18,17 +18,18 @@ var EXPORTED_SYMBOLS = [
 ];
 
 ChromeUtils.import("resource:///modules/MailServices.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://testing-common/mailnews/localAccountUtils.js");
 ChromeUtils.import("resource://testing-common/mailnews/maild.js");
 ChromeUtils.import("resource://testing-common/mailnews/auth.js");
-ChromeUtils.import("resource://testing-common/mailnews/imapd.js");
+var imapd = {};
+ChromeUtils.import("resource://testing-common/mailnews/imapd.js", imapd);
 ChromeUtils.import("resource://testing-common/AppInfo.jsm");
 
 // define globals
 var IMAPPump = {
   daemon: null,         // the imap fake server daemon
   server: null,         // the imap fake server
   incomingServer: null, // nsIMsgIncomingServer for the imap server
   inbox: null,          // nsIMsgFolder/nsIMsgImapMailFolder for imap inbox
@@ -38,27 +39,27 @@ var IMAPPump = {
 function setupIMAPPump(extensions)
 {
   // Create Application info if we need it.
   updateAppInfo();
 
   // These are copied from imap's head_server.js to here so we can run
   //   this from any directory.
   function makeServer(daemon, infoString) {
-    if (infoString in configurations)
-      return makeServer(daemon, configurations[infoString].join(","));
+    if (infoString in imapd.configurations)
+      return makeServer(daemon, imapd.configurations[infoString].join(","));
 
     function createHandler(d) {
-      var handler = new IMAP_RFC3501_handler(d);
+      var handler = new imapd.IMAP_RFC3501_handler(d);
       if (!infoString)
         infoString = "RFC2195";
 
       var parts = infoString.split(/ *, */);
       for (var part of parts) {
-        mixinExtension(handler, eval("IMAP_" + part + "_extension"));
+        imapd.mixinExtension(handler, imapd["IMAP_" + part + "_extension"]);
       }
       return handler;
     }
     var server = new nsMailServer(createHandler, daemon);
     server.start();
     return server;
   }
 
@@ -66,17 +67,17 @@ function setupIMAPPump(extensions)
     let server = localAccountUtils.create_incoming_server("imap",
       IMAPPump.server.port, "user", "password");
     server.QueryInterface(Ci.nsIImapIncomingServer);
     return server;
   }
 
   // end copy from head_server.js
 
-  IMAPPump.daemon = new imapDaemon();
+  IMAPPump.daemon = new imapd.imapDaemon();
   IMAPPump.server = makeServer(IMAPPump.daemon, extensions);
 
   IMAPPump.incomingServer = createLocalIMAPServer();
 
   if (!localAccountUtils.inboxFolder)
     localAccountUtils.loadLocalMailAccount();
 
   // We need an identity so that updateFolder doesn't fail