Bug 1133282 - Remove nonstandard expression closures from netwerk. r=mcmanus
authorChris Peterson <cpeterson@mozilla.com>
Sat, 24 Jan 2015 23:50:26 -0800
changeset 229370 ad824f6cef5f2e19454a353ccb49979cf47dbeb0
parent 229369 8ea3cf306727006ff4b82557f1b159b7957364b7
child 229371 f57201a6482da17d3ee8fb76697d30a26a16879a
push id28287
push userryanvm@gmail.com
push dateTue, 17 Feb 2015 20:08:22 +0000
treeherdermozilla-central@b6c56fab513d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1133282
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1133282 - Remove nonstandard expression closures from netwerk. r=mcmanus
netwerk/protocol/http/UserAgentOverrides.jsm
netwerk/protocol/http/UserAgentUpdates.jsm
netwerk/test/httpserver/test/test_response_write.js
netwerk/test/mochitests/test_user_agent_overrides.html
netwerk/test/mochitests/test_user_agent_updates.html
netwerk/test/unit/test_httpsuspend.js
netwerk/test/unit/test_reentrancy.js
--- a/netwerk/protocol/http/UserAgentOverrides.jsm
+++ b/netwerk/protocol/http/UserAgentOverrides.jsm
@@ -25,17 +25,17 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                   "nsIMessageListenerManager");  // Might have to make this broadcast?
 
 var gPrefBranch;
 var gOverrides = new Map;
 var gUpdatedOverrides;
 var gOverrideForHostCache = new Map;
 var gInitialized = false;
 var gOverrideFunctions = [
-  function (aHttpChannel) UserAgentOverrides.getOverrideForURI(aHttpChannel.URI)
+  function (aHttpChannel) { return UserAgentOverrides.getOverrideForURI(aHttpChannel.URI); }
 ];
 var gBuiltUAs = new Map;
 
 this.UserAgentOverrides = {
   init: function uao_init() {
     if (gInitialized)
       return;
 
@@ -52,17 +52,17 @@ this.UserAgentOverrides = {
     }
 
     UserAgentUpdates.init(function(overrides) {
       gOverrideForHostCache.clear();
       if (overrides) {
         for (let domain in overrides) {
           overrides[domain] = getUserAgentFromOverride(overrides[domain]);
         }
-        overrides.get = function(key) this[key];
+        overrides.get = function(key) { return this[key]; };
       }
       gUpdatedOverrides = overrides;
     });
 
     buildOverrides();
     gInitialized = true;
   },
 
--- a/netwerk/protocol/http/UserAgentUpdates.jsm
+++ b/netwerk/protocol/http/UserAgentUpdates.jsm
@@ -21,26 +21,27 @@ XPCOMUtils.defineLazyModuleGetter(
 
 XPCOMUtils.defineLazyModuleGetter(
   this, "UpdateChannel", "resource://gre/modules/UpdateChannel.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(
   this, "gUpdateTimer", "@mozilla.org/updates/timer-manager;1", "nsIUpdateTimerManager");
 
 XPCOMUtils.defineLazyGetter(this, "gApp",
-  function() Cc["@mozilla.org/xre/app-info;1"]
-    .getService(Ci.nsIXULAppInfo).QueryInterface(Ci.nsIXULRuntime)
-);
+  function() {
+    return Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo)
+                                            .QueryInterface(Ci.nsIXULRuntime);
+  });
 
 XPCOMUtils.defineLazyGetter(this, "gDecoder",
-  function() new TextDecoder()
+  function() { return new TextDecoder(); }
 );
 
 XPCOMUtils.defineLazyGetter(this, "gEncoder",
-  function() new TextEncoder()
+  function() { return new TextEncoder(); }
 );
 
 const TIMER_ID = "user-agent-updates-timer";
 
 const PREF_UPDATES = "general.useragent.updates.";
 const PREF_UPDATES_ENABLED = PREF_UPDATES + "enabled";
 const PREF_UPDATES_URL = PREF_UPDATES + "url";
 const PREF_UPDATES_INTERVAL = PREF_UPDATES + "interval";
@@ -138,27 +139,29 @@ this.UserAgentUpdates = {
         case "boolean": return Services.prefs.getBoolPref(name);
       }
       return Services.prefs.getCharPref(name);
     } catch (e) {
       return def;
     }
   },
 
-  _getParameters: function() ({
-    "%DATE%": function() Date.now().toString(),
-    "%PRODUCT%": function() gApp.name,
-    "%APP_ID%": function() gApp.ID,
-    "%APP_VERSION%": function() gApp.version,
-    "%BUILD_ID%": function() gApp.appBuildID,
-    "%OS%": function() gApp.OS,
-    "%CHANNEL%": function() UpdateChannel.get(),
-    "%DISTRIBUTION%": function() this._getPref(PREF_APP_DISTRIBUTION, ""),
-    "%DISTRIBUTION_VERSION%": function() this._getPref(PREF_APP_DISTRIBUTION_VERSION, ""),
-  }),
+  _getParameters() {
+    return {
+      "%DATE%": function() { return Date.now().toString(); },
+      "%PRODUCT%": function() { return gApp.name; },
+      "%APP_ID%": function() { return gApp.ID; },
+      "%APP_VERSION%": function() { return gApp.version; },
+      "%BUILD_ID%": function() { return gApp.appBuildID; },
+      "%OS%": function() { return gApp.OS; },
+      "%CHANNEL%": function() { return UpdateChannel.get(); },
+      "%DISTRIBUTION%": function() { return this._getPref(PREF_APP_DISTRIBUTION, ""); },
+      "%DISTRIBUTION_VERSION%": function() { return this._getPref(PREF_APP_DISTRIBUTION_VERSION, ""); },
+    };
+  },
 
   _getUpdateURL: function() {
     let url = this._getPref(PREF_UPDATES_URL, "");
     let params = this._getParameters();
     return url.replace(/%[A-Z_]+%/g, function(match) {
       let param = params[match];
       // preserve the %FOO% string (e.g. as an encoding) if it's not a valid parameter
       return param ? encodeURIComponent(param()) : match;
--- a/netwerk/test/httpserver/test/test_response_write.js
+++ b/netwerk/test/httpserver/test/test_response_write.js
@@ -29,17 +29,17 @@ function run_test()
 }
 
 
 // TEST DATA
 
 function succeeded(ch, cx, status, data)
 {
   do_check_true(Components.isSuccessCode(status));
-  do_check_eq(data.map(function(v) String.fromCharCode(v)).join(""), "1234");
+  do_check_eq(data.map(v => String.fromCharCode(v)).join(""), "1234");
 }
 
 function check_1234(ch, cx)
 {
   do_check_eq(ch.getResponseHeader("Content-Length"), "4");
 }
 
 // PATH HANDLERS
--- a/netwerk/test/mochitests/test_user_agent_overrides.html
+++ b/netwerk/test/mochitests/test_user_agent_overrides.html
@@ -226,30 +226,30 @@ function testPriority(callback) {
     });
   })();
 }
 
 function testOverrides(callback) {
   SpecialPowers.pushPrefEnv({
     set: [[PREF_OVERRIDES_ENABLED, true]]
   }, function nextTest() {
-    testUA(tests.shift(), function () tests.length ? nextTest() : callback());
+    testUA(tests.shift(), function() { tests.length ? nextTest() : callback() });
   });
 }
 
 SpecialPowers.Cu.import('resource://gre/modules/UserAgentOverrides.jsm', window);
 SpecialPowers.wrap(UserAgentOverrides).init();
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestCompleteLog();
 
 info(SpecialPowers.Cc["@mozilla.org/dom/site-specific-user-agent;1"].number);
 
-testOverrides(function ()
-  testInactive(function ()
+testOverrides(function() {
+  testInactive(function() {
     testPriority(SimpleTest.finish)
-  )
-);
+  });
+});
 
 </script>
 </pre>
 </body>
 </html>
--- a/netwerk/test/mochitests/test_user_agent_updates.html
+++ b/netwerk/test/mochitests/test_user_agent_updates.html
@@ -115,17 +115,17 @@ function testDownload(callback) {
   info('Waiting for UA update: ' + url);
   SpecialPowers.pushPrefEnv({
     set: [
       [PREF_UPDATES_ENABLED, true],
       [PREF_UPDATES_URL, url],
       [PREF_UPDATES_TIMEOUT, 10000],
       [PREF_UPDATES_INTERVAL, 1] // 1 second interval
     ]
-  }, function waitForUpdate() setTimeout(function () {
+  }, function waitForUpdate() { setTimeout(function () {
     var ifr = document.createElement('IFRAME');
     ifr.src = "about:blank";
 
     ifr.addEventListener('load', function() {
       var nav = ifr.contentWindow.navigator;
       if (nav.userAgent !== UA_OVERRIDE) {
         waitForUpdate();
         return;
@@ -141,42 +141,42 @@ function testDownload(callback) {
       OVERRIDES.forEach(function (val) {
         val.expected && is(getUA(val.host), val.expected,
           'Incorrect URL parameter: ' + val.override);
       });
       callback();
     }, false);
 
     document.getElementById('content').appendChild(ifr);
-  }, 100));
+  }, 100); });
 }
 
 function testBadUpdate(callback) {
   var url = getServerURL() + 'invalid-json';
   var prevOverride = navigator.userAgent;
   SpecialPowers.pushPrefEnv({
     set: [
       [PREF_UPDATES_URL, url],
       [PREF_UPDATES_INTERVAL, 1] // 1 second interval
     ]
-  }, function () setTimeout(function () {
+  }, function () { setTimeout(function () {
     var ifr = document.createElement('IFRAME');
     ifr.src = "about:blank";
 
     ifr.addEventListener('load', function() {
       // We want to make sure a bad update doesn't cancel out previous
       // overrides. We do this by waiting for 5 seconds (assuming the update
       // occurs within 5 seconds), and check that the previous override hasn't
       // changed.
       is(navigator.userAgent, prevOverride,
         'Invalid update deleted previous override');
       callback();
     }, false);
     document.getElementById('content').appendChild(ifr);
-  }, 5000));
+  }, 5000); });
 }
 
 function testProfileLoad(callback) {
   var file = FU.getFile(KEY_APPDIR, [FILE_UPDATES]).path;
   var encoder = SpecialPowers.wrap(new TextEncoder());
   var overrides = {};
   overrides[location.hostname] = UA_ALT_OVERRIDE;
   var bytes = encoder.encode(JSON.stringify(overrides));
@@ -276,21 +276,21 @@ SpecialPowers.pushPrefEnv({
 
   SpecialPowers.Cu.import('resource://gre/modules/UserAgentOverrides.jsm', window);
   UAO = SpecialPowers.wrap(UserAgentOverrides);
   UAO.uninit();
 
   // testProfileLoad, testDownload, and testProfileSave must run in this order
   //  because testDownload depends on testProfileLoad to call UAO.init()
   //  and testProfileSave depends on testDownload to save overrides to the profile
-  testProfileLoad(function()
-    testDownload(function()
-      testBadUpdate(function()
+  testProfileLoad(function() {
+    testDownload(function() {
+      testBadUpdate(function() {
         testProfileSave(SimpleTest.finish)
-      )
-    )
-  );
+      })
+    })
+  });
 });
 
 </script>
 </pre>
 </body>
 </html>
--- a/netwerk/test/unit/test_httpsuspend.js
+++ b/netwerk/test/unit/test_httpsuspend.js
@@ -26,18 +26,18 @@ var listener = {
   onStartRequest: function(request, ctx) {
     this._lastEvent = Date.now();
     request.QueryInterface(Ci.nsIRequest);
 
     // Insert a delay between this and the next callback to ensure message buffering
     // works correctly
     request.suspend();
     request.suspend();
-    do_timeout(RESUME_DELAY, function() request.resume());
-    do_timeout(RESUME_DELAY + 1000, function() request.resume());
+    do_timeout(RESUME_DELAY, function() { request.resume(); });
+    do_timeout(RESUME_DELAY + 1000, function() { request.resume(); });
   },
 
   onDataAvailable: function(request, context, stream, offset, count) {
     do_check_true(Date.now() - this._lastEvent >= MIN_TIME_DIFFERENCE);
     read_stream(stream, count);
 
     // Ensure that suspending and resuming inside a callback works correctly
     request.suspend();
--- a/netwerk/test/unit/test_reentrancy.js
+++ b/netwerk/test/unit/test_reentrancy.js
@@ -37,21 +37,21 @@ var listener = {
       case 0:
         request.suspend();
         syncXHR();
         request.resume();
         break;
       case 1:
         request.suspend();
         syncXHR();
-        do_execute_soon(function() request.resume());
+        do_execute_soon(function() { request.resume(); });
         break;
       case 2:
-        do_execute_soon(function() request.suspend());
-        do_execute_soon(function() request.resume());
+        do_execute_soon(function() { request.suspend(); });
+        do_execute_soon(function() { request.resume(); });
         syncXHR();
         break;
     }
     
     this._done_onStart = true;
   },
 
   onDataAvailable: function(request, context, stream, offset, count) {