Bug 1252995 - Add a method to get lines and name of methods. r=chmanchester
authorGreg Mierzwinski <gmierz2@outlook.com>
Fri, 11 Mar 2016 19:18:19 -0500
changeset 293319 1602320ae20876e40c82b6d936dae74cf28ab02b
parent 293318 b72f1f574abadf0ff5c64cb8814a6b52c31d2940
child 293320 c155349cb40312927dd7c1f9756598e28ac949d2
push id18749
push usercbook@mozilla.com
push dateFri, 15 Apr 2016 12:01:19 +0000
treeherderfx-team@8f7045b63b07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1252995
milestone48.0a1
Bug 1252995 - Add a method to get lines and name of methods. r=chmanchester This method gets method names and the lines each method spans. It uses getAllOffsets to get the lines. MozReview-Commit-ID: Df4kP11obq2
testing/modules/CoverageUtils.jsm
--- a/testing/modules/CoverageUtils.jsm
+++ b/testing/modules/CoverageUtils.jsm
@@ -118,16 +118,50 @@ CoverageCollector.prototype._getUncovere
       let [lineNumber, columnNumber, offset] = key.split('#');
       uncoveredLines[scriptName].delete(parseInt(lineNumber, 10));
     }
   }
 
   return uncoveredLines;
 }
 
+CoverageCollector.prototype._getMethodNames = function() {
+  let methodNames = {};
+  this._scripts.forEach(s => {
+    let method = s.displayName;
+    // If the method name is undefined, we return early
+    if (!method){
+      return;
+    }
+
+    let scriptName = s.url;
+    let tempMethodCov = [];
+    let scriptOffsets = s.getAllOffsets();
+
+    if (!methodNames[scriptName]){
+      methodNames[scriptName] = {};
+    }
+
+    /**
+    * Get all lines contained within the method and
+    * push a record of the form:
+    * <method name> : <lines covered>
+    */
+    scriptOffsets.forEach(function (element, index){
+      if (!element){
+        return;
+      }
+      tempMethodCov.push(index);
+    });
+    methodNames[scriptName][method] = tempMethodCov;
+  });
+
+  return methodNames;
+}
+
 /**
  * Records lines covered since the last time coverage was recorded,
  * associating them with the given test name. The result is written
  * to a json file in a specified directory.
  */
 CoverageCollector.prototype.recordTestCoverage = function (testName) {
   dump("Collecting coverage for: " + testName + "\n");
   let rawLines = this._getLinesCovered(testName);