Bug 1423839 - Part 1: Enable ESLint for NetUtil.jsm and netwerk/cookie/test/unit/ (automatic changes) r=Standard8,jdm
authorJames Lee <jamesl33info@gmail.com>
Tue, 23 Oct 2018 08:34:13 +0000
changeset 490890 eff50d9238028b1202f7a3d68a7c9da92ddbadcd
parent 490889 dc03893f95d727b995e1365a41d3c20558cc54bf
child 490891 0dc37e5676af1f7851a7a86a339d9903fa42e59c
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersStandard8, jdm
bugs1423839
milestone65.0a1
Bug 1423839 - Part 1: Enable ESLint for NetUtil.jsm and netwerk/cookie/test/unit/ (automatic changes) r=Standard8,jdm Ran ESLint's automatic '--fix' option on the above files. Differential Revision: https://phabricator.services.mozilla.com/D9293
.eslintignore
netwerk/base/NetUtil.jsm
netwerk/cookie/test/unit/test_bug1155169.js
netwerk/cookie/test/unit/test_eviction.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -21,19 +21,17 @@ extensions/universalchardet/**
 gfx/layers/**
 gfx/tests/browser/**
 gfx/tests/chrome/**
 gfx/tests/mochitest/**
 image/**
 layout/**
 memory/replace/dmd/test/**
 modules/**
-netwerk/base/NetUtil.jsm
 netwerk/cookie/test/browser/**
-netwerk/cookie/test/unit/**
 netwerk/protocol/**
 netwerk/dns/**
 netwerk/test/browser/**
 netwerk/test/httpserver/**
 netwerk/test/mochitests/**
 netwerk/test/unit*/**
 netwerk/wifi/**
 parser/**
--- a/netwerk/base/NetUtil.jsm
+++ b/netwerk/base/NetUtil.jsm
@@ -7,29 +7,29 @@
 var EXPORTED_SYMBOLS = [
   "NetUtil",
 ];
 
 /**
  * Necko utilities
  */
 
-////////////////////////////////////////////////////////////////////////////////
-//// Constants
+// //////////////////////////////////////////////////////////////////////////////
+// // Constants
 
 const PR_UINT32_MAX = 0xffffffff;
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
                                                  "nsIBinaryInputStream", "setInputStream");
 
-////////////////////////////////////////////////////////////////////////////////
-//// NetUtil Object
+// //////////////////////////////////////////////////////////////////////////////
+// // NetUtil Object
 
 var NetUtil = {
     /**
      * Function to perform simple async copying from aSource (an input stream)
      * to aSink (an output stream).  The copy will happen on some background
      * thread.  Both streams will be closed when the copy completes.
      *
      * @param aSource
@@ -40,18 +40,17 @@ var NetUtil = {
      *        A function that will be called at copy completion with a single
      *        argument: the nsresult status code for the copy operation.
      *
      * @return An nsIRequest representing the copy operation (for example, this
      *         can be used to cancel the copying).  The consumer can ignore the
      *         return value if desired.
      */
     asyncCopy: function NetUtil_asyncCopy(aSource, aSink,
-                                          aCallback = null)
-    {
+                                          aCallback = null) {
         if (!aSource || !aSink) {
             let exception = new Components.Exception(
                 "Must have a source and a sink",
                 Cr.NS_ERROR_INVALID_ARG,
                 Components.stack.caller
             );
             throw exception;
         }
@@ -62,21 +61,21 @@ var NetUtil = {
         copier.init(aSource, aSink,
                     null /* Default event target */,
                     0 /* Default length */,
                     true, true /* Auto-close */);
 
         var observer;
         if (aCallback) {
             observer = {
-                onStartRequest: function(aRequest, aContext) {},
-                onStopRequest: function(aRequest, aContext, aStatusCode) {
+                onStartRequest(aRequest, aContext) {},
+                onStopRequest(aRequest, aContext, aStatusCode) {
                     aCallback(aStatusCode);
-                }
-            }
+                },
+            };
         } else {
             observer = null;
         }
 
         // start the copying
         copier.QueryInterface(Ci.nsIAsyncStreamCopier).asyncCopy(observer, null);
         return copier;
     },
@@ -94,18 +93,17 @@ var NetUtil = {
      *        Using an nsIURI, nsIFile, or string spec directly is deprecated.
      * @param aCallback
      *        The callback function that will be notified upon completion.  It
      *        will get these arguments:
      *        1) An nsIInputStream containing the data from aSource, if any.
      *        2) The status code from opening the source.
      *        3) Reference to the nsIRequest.
      */
-    asyncFetch: function NetUtil_asyncFetch(aSource, aCallback)
-    {
+    asyncFetch: function NetUtil_asyncFetch(aSource, aCallback) {
         if (!aSource || !aCallback) {
             let exception = new Components.Exception(
                 "Must have a source and a callback",
                 Cr.NS_ERROR_INVALID_ARG,
                 Components.stack.caller
             );
             throw exception;
         }
@@ -115,21 +113,21 @@ var NetUtil = {
         let pipe = Cc["@mozilla.org/pipe;1"].
                    createInstance(Ci.nsIPipe);
         pipe.init(true, true, 0, PR_UINT32_MAX, null);
 
         // Create a listener that will give data to the pipe's output stream.
         let listener = Cc["@mozilla.org/network/simple-stream-listener;1"].
                        createInstance(Ci.nsISimpleStreamListener);
         listener.init(pipe.outputStream, {
-            onStartRequest: function(aRequest, aContext) {},
-            onStopRequest: function(aRequest, aContext, aStatusCode) {
+            onStartRequest(aRequest, aContext) {},
+            onStopRequest(aRequest, aContext, aStatusCode) {
                 pipe.outputStream.close();
                 aCallback(pipe.inputStream, aStatusCode, aRequest);
-            }
+            },
         });
 
         // Input streams are handled slightly differently from everything else.
         if (aSource instanceof Ci.nsIInputStream) {
             let pump = Cc["@mozilla.org/network/input-stream-pump;1"].
                        createInstance(Ci.nsIInputStreamPump);
             pump.init(aSource, 0, 0, true);
             pump.asyncRead(listener, null);
@@ -142,29 +140,27 @@ var NetUtil = {
         }
 
         try {
             // Open the channel using asyncOpen2() if the loadinfo contains one
             // of the security mode flags, otherwise fall back to use asyncOpen().
             if (channel.loadInfo &&
                 channel.loadInfo.securityMode != 0) {
                 channel.asyncOpen2(listener);
-            }
-            else {
+            } else {
                 // Log deprecation warning to console to make sure all channels
                 // are created providing the correct security flags in the loadinfo.
                 // See nsILoadInfo for all available security flags and also the API
                 // of NetUtil.newChannel() for details above.
                 Cu.reportError("NetUtil.jsm: asyncFetch() requires the channel to have " +
                     "one of the security flags set in the loadinfo (see nsILoadInfo). " +
                     "Please create channel using NetUtil.newChannel()");
                 channel.asyncOpen(listener, null);
             }
-        }
-        catch (e) {
+        } catch (e) {
             let exception = new Components.Exception(
                 "Failed to open input source '" + channel.originalURI.spec + "'",
                 e.result,
                 Components.stack.caller,
                 aSource,
                 e
             );
             throw exception;
@@ -181,18 +177,17 @@ var NetUtil = {
      *        The character set for the URI.  Only used if aTarget is not an
      *        nsIFile.
      * @param aBaseURI [optional]
      *        The base URI for the spec.  Only used if aTarget is not an
      *        nsIFile.
      *
      * @return an nsIURI object.
      */
-    newURI: function NetUtil_newURI(aTarget, aOriginCharset, aBaseURI)
-    {
+    newURI: function NetUtil_newURI(aTarget, aOriginCharset, aBaseURI) {
         if (!aTarget) {
             let exception = new Components.Exception(
                 "Must have a non-null string spec or nsIFile object",
                 Cr.NS_ERROR_INVALID_ARG,
                 Components.stack.caller
             );
             throw exception;
         }
@@ -231,18 +226,17 @@ var NetUtil = {
      *          loadUsingSystemPrincipal:
      *            Set this to true to use the system principal as
      *            loadingPrincipal.  This must be omitted if loadingPrincipal or
      *            loadingNode are present.
      *            This should be used with care as it skips security checks.
      *        }
      * @return an nsIChannel object.
      */
-    newChannel: function NetUtil_newChannel(aWhatToLoad)
-    {
+    newChannel: function NetUtil_newChannel(aWhatToLoad) {
         // Make sure the API is called using only the options object.
         if (typeof aWhatToLoad != "object" || arguments.length != 1) {
             throw new Components.Exception(
                 "newChannel requires a single object argument",
                 Cr.NS_ERROR_INVALID_ARG,
                 Components.stack.caller
             );
         }
@@ -350,18 +344,17 @@ var NetUtil = {
      * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from aInputStream would
      *         block the calling thread (non-blocking mode only).
      * @throws NS_ERROR_FAILURE if there are not enough bytes available to read
      *         aCount amount of data.
      * @throws NS_ERROR_ILLEGAL_INPUT if aInputStream has invalid sequences
      */
     readInputStreamToString: function NetUtil_readInputStreamToString(aInputStream,
                                                                       aCount,
-                                                                      aOptions)
-    {
+                                                                      aOptions) {
         if (!(aInputStream instanceof Ci.nsIInputStream)) {
             let exception = new Components.Exception(
                 "First argument should be an nsIInputStream",
                 Cr.NS_ERROR_INVALID_ARG,
                 Components.stack.caller
             );
             throw exception;
         }
@@ -389,31 +382,29 @@ var NetUtil = {
             }
 
             cis.init(aInputStream, aOptions.charset, aCount,
                      aOptions.replacement);
             let str = {};
             cis.readString(-1, str);
             cis.close();
             return str.value;
-          }
-          catch (e) {
+          } catch (e) {
             // Adjust the stack so it throws at the caller's location.
             throw new Components.Exception(e.message, e.result,
                                            Components.stack.caller, e.data);
           }
         }
 
         let sis = Cc["@mozilla.org/scriptableinputstream;1"].
                   createInstance(Ci.nsIScriptableInputStream);
         sis.init(aInputStream);
         try {
             return sis.readBytes(aCount);
-        }
-        catch (e) {
+        } catch (e) {
             // Adjust the stack so it throws at the caller's location.
             throw new Components.Exception(e.message, e.result,
                                            Components.stack.caller, e.data);
         }
     },
 
     /**
      * Reads aCount bytes from aInputStream into a string.
@@ -426,18 +417,17 @@ var NetUtil = {
      * @return the bytes from the input stream in string form.
      *
      * @throws NS_ERROR_INVALID_ARG if aInputStream is not an nsIInputStream.
      * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from aInputStream would
      *         block the calling thread (non-blocking mode only).
      * @throws NS_ERROR_FAILURE if there are not enough bytes available to read
      *         aCount amount of data.
      */
-    readInputStream(aInputStream, aCount)
-    {
+    readInputStream(aInputStream, aCount) {
         if (!(aInputStream instanceof Ci.nsIInputStream)) {
             let exception = new Components.Exception(
                 "First argument should be an nsIInputStream",
                 Cr.NS_ERROR_INVALID_ARG,
                 Components.stack.caller
             );
             throw exception;
         }
@@ -452,15 +442,14 @@ var NetUtil = {
         return result;
     },
 
     /**
      * Returns a reference to nsIIOService.
      *
      * @return a reference to nsIIOService.
      */
-    get ioService()
-    {
+    get ioService() {
         delete this.ioService;
         return this.ioService = Cc["@mozilla.org/network/io-service;1"].
                                 getService(Ci.nsIIOService);
     },
 };
--- a/netwerk/cookie/test/unit/test_bug1155169.js
+++ b/netwerk/cookie/test/unit/test_bug1155169.js
@@ -9,39 +9,39 @@ function run_test() {
   // Allow all cookies.
   Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
 
   // Clear cookies.
   Services.cookies.removeAll();
 
   // Add a new cookie.
   setCookie("foo=bar", {
-    type: "added", isSession: true, isSecure: false, isHttpOnly: false
+    type: "added", isSession: true, isSecure: false, isHttpOnly: false,
   });
 
   // Update cookie with isHttpOnly=true.
   setCookie("foo=bar; HttpOnly", {
-    type: "changed", isSession: true, isSecure: false, isHttpOnly: true
+    type: "changed", isSession: true, isSecure: false, isHttpOnly: true,
   });
 
   // Update cookie with isSecure=true.
   setCookie("foo=bar; Secure", {
-    type: "changed", isSession: true, isSecure: true, isHttpOnly: false
+    type: "changed", isSession: true, isSecure: true, isHttpOnly: false,
   });
 
   // Update cookie with isSession=false.
   let expiry = new Date();
   expiry.setUTCFullYear(expiry.getUTCFullYear() + 2);
   setCookie(`foo=bar; Expires=${expiry.toGMTString()}`, {
-    type: "changed", isSession: false, isSecure: false, isHttpOnly: false
+    type: "changed", isSession: false, isSecure: false, isHttpOnly: false,
   });
 
   // Reset cookie.
   setCookie("foo=bar", {
-    type: "changed", isSession: true, isSecure: false, isHttpOnly: false
+    type: "changed", isSession: true, isSecure: false, isHttpOnly: false,
   });
 }
 
 function setCookie(value, expected) {
   function setCookieInternal(value, expected = null) {
     function observer(subject, topic, data) {
       if (!expected) {
         do_throw("no notification expected");
--- a/netwerk/cookie/test/unit/test_eviction.js
+++ b/netwerk/cookie/test/unit/test_eviction.js
@@ -25,60 +25,60 @@ async function test_basic_eviction(base_
     const FOO_PATH = Services.io.newURI("http://" + base_host + "/foo/");
     const BAR_PATH = Services.io.newURI("http://" + base_host + "/bar/");
 
     await setCookie("session_foo_path_1", null, "/foo", null, FOO_PATH);
     await setCookie("session_foo_path_2", null, "/foo", null, FOO_PATH);
     await setCookie("session_foo_path_3", null, "/foo", null, FOO_PATH);
     await setCookie("session_foo_path_4", null, "/foo", null, FOO_PATH);
     await setCookie("session_foo_path_5", null, "/foo", null, FOO_PATH);
-    verifyCookies(['session_foo_path_1',
-                   'session_foo_path_2',
-                   'session_foo_path_3',
-                   'session_foo_path_4',
-                   'session_foo_path_5'], BASE_URI);
+    verifyCookies(["session_foo_path_1",
+                   "session_foo_path_2",
+                   "session_foo_path_3",
+                   "session_foo_path_4",
+                   "session_foo_path_5"], BASE_URI);
 
     // Check if cookies are evicted by creation time.
     await setCookie("session_foo_path_6", null, "/foo", null, FOO_PATH);
-    verifyCookies(['session_foo_path_4',
-                   'session_foo_path_5',
-                   'session_foo_path_6'], BASE_URI);
+    verifyCookies(["session_foo_path_4",
+                   "session_foo_path_5",
+                   "session_foo_path_6"], BASE_URI);
 
     await setCookie("session_bar_path_1", null, "/bar", null, BAR_PATH);
     await setCookie("session_bar_path_2", null, "/bar", null, BAR_PATH);
 
-    verifyCookies(['session_foo_path_4',
-                   'session_foo_path_5',
-                   'session_foo_path_6',
-                   'session_bar_path_1',
-                   'session_bar_path_2'], BASE_URI);
+    verifyCookies(["session_foo_path_4",
+                   "session_foo_path_5",
+                   "session_foo_path_6",
+                   "session_bar_path_1",
+                   "session_bar_path_2"], BASE_URI);
 
     // Check if cookies are evicted by last accessed time.
     cs.getCookieString(FOO_PATH, null);
     await setCookie("session_foo_path_7", null, "/foo", null, FOO_PATH);
-    verifyCookies(['session_foo_path_5',
-                   'session_foo_path_6',
-                   'session_foo_path_7'], BASE_URI);
+    verifyCookies(["session_foo_path_5",
+                   "session_foo_path_6",
+                   "session_foo_path_7"], BASE_URI);
 
     const EXPIRED_TIME = 3;
 
     await setCookie("non_session_expired_foo_path_1", null, "/foo", EXPIRED_TIME, FOO_PATH);
     await setCookie("non_session_expired_foo_path_2", null, "/foo", EXPIRED_TIME, FOO_PATH);
-    verifyCookies(['session_foo_path_5',
-                   'session_foo_path_6',
-                   'session_foo_path_7',
-                   'non_session_expired_foo_path_1',
-                   'non_session_expired_foo_path_2'], BASE_URI);
+    verifyCookies(["session_foo_path_5",
+                   "session_foo_path_6",
+                   "session_foo_path_7",
+                   "non_session_expired_foo_path_1",
+                   "non_session_expired_foo_path_2"], BASE_URI);
 
     // Check if expired cookies are evicted first.
     await new Promise(resolve => do_timeout(EXPIRED_TIME * 1000, resolve));
     await setCookie("session_foo_path_8", null, "/foo", null, FOO_PATH);
-    verifyCookies(['session_foo_path_6',
-                   'session_foo_path_7',
-                   'session_foo_path_8'], BASE_URI);
+    verifyCookies(["session_foo_path_6",
+                   "session_foo_path_7",
+                   "session_foo_path_8"], BASE_URI);
 }
 
 // Verify that the given cookie names exist, and are ordered from least to most recently accessed
 function verifyCookies(names, uri) {
     Assert.equal(cm.countCookiesFromHost(uri.host), names.length);
     let actual_cookies = [];
     for (let cookie of cm.getCookiesFromHost(uri.host, {})) {
         actual_cookies.push(cookie);
@@ -88,17 +88,17 @@ function verifyCookies(names, uri) {
             return actual_cookies.findIndex(function(c) {
                 return c.name == n;
             }) == -1;
         });
         let right = actual_cookies.filter(function(c) {
             return names.findIndex(function(n) {
                 return c.name == n;
             }) == -1;
-        }).map(function(c) { return c.name });
+        }).map(function(c) { return c.name; });
         if (left.length) {
             info("unexpected cookies: " + left);
         }
         if (right.length) {
             info("expected cookies: " + right);
         }
     }
     Assert.equal(names.length, actual_cookies.length);
@@ -106,40 +106,40 @@ function verifyCookies(names, uri) {
         if (a.lastAccessed < b.lastAccessed)
             return -1;
         if (a.lastAccessed > b.lastAccessed)
             return 1;
         return 0;
     });
     for (var i = 0; i < names.length; i++) {
         Assert.equal(names[i], actual_cookies[i].name);
-        Assert.equal(names[i].startsWith('session'), actual_cookies[i].isSession);
+        Assert.equal(names[i].startsWith("session"), actual_cookies[i].isSession);
     }
 }
 
-var lastValue = 0
+var lastValue = 0;
 function setCookie(name, domain, path, maxAge, url) {
     let value = name + "=" + ++lastValue;
-    var s = 'setting cookie ' + value;
+    var s = "setting cookie " + value;
     if (domain) {
         value += "; Domain=" + domain;
-        s += ' (d=' + domain + ')';
+        s += " (d=" + domain + ")";
     }
     if (path) {
         value += "; Path=" + path;
-        s += ' (p=' + path + ')';
+        s += " (p=" + path + ")";
     }
     if (maxAge) {
         value += "; Max-Age=" + maxAge;
-        s += ' (non-session)';
+        s += " (non-session)";
     } else {
-        s += ' (session)';
+        s += " (session)";
     }
-    s += ' for ' + url.spec;
+    s += " for " + url.spec;
     info(s);
     cs.setCookieStringFromHttp(url, null, null, value, null, null);
     return new Promise(function(resolve) {
         // Windows XP has low precision timestamps that cause our cookie eviction
         // algorithm to produce different results from other platforms. We work around
         // this by ensuring that there's a clear gap between each cookie update.
         do_timeout(10, resolve);
-    })
+    });
 }