Bug 1247258 - Use Array.prototype.includes in Telemetry code. r=dexter
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 10 Feb 2016 15:19:37 +0100
changeset 283748 743097ee7470582a653af5a33a167cc16a14f68b
parent 283747 31150215eedfe1406dbd92058635eb619e817939
child 283749 bc6d63520f410db38eab8217c50947b78e4faa34
push id17537
push usergeorg.fritzsche@googlemail.com
push dateWed, 10 Feb 2016 14:19:53 +0000
treeherderfx-team@bc6d63520f41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdexter
bugs1247258
milestone47.0a1
Bug 1247258 - Use Array.prototype.includes in Telemetry code. r=dexter
toolkit/components/telemetry/TelemetryEnvironment.jsm
toolkit/components/telemetry/TelemetrySession.jsm
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -1193,17 +1193,17 @@ EnvironmentCache.prototype = {
   },
 
   /**
    * Get the device information, if we are on a portable device.
    * @return Object containing the device information data, or null if
    * not a portable device.
    */
   _getDeviceData: function () {
-    if (["gonk", "android"].indexOf(AppConstants.platform) === -1) {
+    if (!["gonk", "android"].includes(AppConstants.platform)) {
       return null;
     }
 
     return {
       model: getSysinfoProperty("device", null),
       manufacturer: getSysinfoProperty("manufacturer", null),
       hardware: getSysinfoProperty("hardware", null),
       isTablet: getSysinfoProperty("tablet", null),
@@ -1216,17 +1216,17 @@ EnvironmentCache.prototype = {
    */
   _getOSData: function () {
     let data = {
       name: getSysinfoProperty("name", null),
       version: getSysinfoProperty("version", null),
       locale: getSystemLocale(),
     };
 
-    if (["gonk", "android"].indexOf(AppConstants.platform) !== -1) {
+    if (["gonk", "android"].includes(AppConstants.platform)) {
       data.kernelVersion = getSysinfoProperty("kernel_version", null);
     } else if (AppConstants.platform === "win") {
       let servicePack = getServicePack();
       data.servicePackMajor = servicePack.major;
       data.servicePackMinor = servicePack.minor;
       data.installYear = getSysinfoProperty("installYear", null);
     }
 
@@ -1265,17 +1265,17 @@ EnvironmentCache.prototype = {
       // The following line is disabled due to main thread jank and will be enabled
       // again as part of bug 1154500.
       //DWriteVersion: getGfxField("DWriteVersion", null),
       adapters: [],
       monitors: [],
       features: {},
     };
 
-    if (["gonk", "android", "linux"].indexOf(AppConstants.platform) === -1) {
+    if (!["gonk", "android", "linux"].includes(AppConstants.platform)) {
       let gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
       try {
         gfxData.monitors = gfxInfo.getMonitors();
       } catch (e) {
         this._log.error("nsIGfxInfo.getMonitors() caught error", e);
       }
     }
 
@@ -1330,17 +1330,17 @@ EnvironmentCache.prototype = {
       cpu: this._getCpuData(),
       os: this._getOSData(),
       hdd: this._getHDDData(),
       gfx: this._getGFXData(),
     };
 
     if (AppConstants.platform === "win") {
       data.isWow64 = getSysinfoProperty("isWow64", null);
-    } else if (["gonk", "android"].indexOf(AppConstants.platform) !== -1) {
+    } else if (["gonk", "android"].includes(AppConstants.platform)) {
       data.device = this._getDeviceData();
     }
 
     return data;
   },
 
   _onEnvironmentChange: function (what, oldEnvironment) {
     this._log.trace("_onEnvironmentChange for " + what);
--- a/toolkit/components/telemetry/TelemetrySession.jsm
+++ b/toolkit/components/telemetry/TelemetrySession.jsm
@@ -1271,17 +1271,17 @@ var Impl = {
     this._subsessionId = Policy.generateSubsessionUUID();
     this._subsessionCounter++;
     this._profileSubsessionCounter++;
   },
 
   getSessionPayload: function getSessionPayload(reason, clearSubsession) {
     this._log.trace("getSessionPayload - reason: " + reason + ", clearSubsession: " + clearSubsession);
 
-    const isMobile = ["gonk", "android"].indexOf(AppConstants.platform) !== -1;
+    const isMobile = ["gonk", "android"].includes(AppConstants.platform);
     const isSubsession = isMobile ? false : !this._isClassicReason(reason);
 
     if (isMobile) {
       clearSubsession = false;
     }
 
     let measurements =
       this.getSimpleMeasurements(reason == REASON_SAVED_SESSION, isSubsession, clearSubsession);
@@ -1993,17 +1993,17 @@ var Impl = {
   },
 
   _isClassicReason: function(reason) {
     const classicReasons = [
       REASON_SAVED_SESSION,
       REASON_GATHER_PAYLOAD,
       REASON_TEST_PING,
     ];
-    return classicReasons.indexOf(reason) != -1;
+    return classicReasons.includes(reason);
   },
 
   /**
    * Get an object describing the current state of this module for AsyncShutdown diagnostics.
    */
   _getState: function() {
     return {
       initialized: this._initialized,
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -401,17 +401,17 @@ function checkPartnerSection(data, isIni
     Assert.strictEqual(data.partner[f], expected, f + " must have the correct value.");
   }
 
   // Check that "partnerNames" exists and contains the correct element.
   Assert.ok(Array.isArray(data.partner.partnerNames));
   if (isInitial) {
     Assert.equal(data.partner.partnerNames.length, 0);
   } else {
-    Assert.ok(data.partner.partnerNames.indexOf(PARTNER_NAME) >= 0);
+    Assert.ok(data.partner.partnerNames.includes(PARTNER_NAME));
   }
 }
 
 function checkGfxAdapter(data) {
   const EXPECTED_ADAPTER_FIELDS_TYPES = {
     description: "string",
     vendorID: "string",
     deviceID: "string",