Bug 1276468 - Fix `sheetToUrl` function for inline style. r=jwalker
authorNicolas Chevobbe <chevobbe.nicolas@gmail.com>
Mon, 06 Jun 2016 21:48:54 +0200
changeset 376616 0aab68e30c0e1354f88ead24a1a75e5eab95bfa9
parent 376615 f87d1fde25f3a222d3c8ae9087ddd3141348e354
child 376686 f04aaf38f90beac203137f3d1a92eaf8320e677b
push id20629
push userchevobbe.nicolas@gmail.com
push dateWed, 08 Jun 2016 11:44:20 +0000
reviewersjwalker
bugs1276468
milestone50.0a1
Bug 1276468 - Fix `sheetToUrl` function for inline style. r=jwalker The function was trying to access `stylesheet` parameter's ownerNode property, which is undefined when the parameter is a StyleSheetActor. In the latter case, we use nodeHref and styleSheetIndex properties to match what is done when the parameter is a StyleSheet. MozReview-Commit-ID: 7FNoKasFYLL
devtools/server/actors/csscoverage.js
--- a/devtools/server/actors/csscoverage.js
+++ b/devtools/server/actors/csscoverage.js
@@ -692,25 +692,31 @@ function getTestSelector(selector) {
  */
 exports.SEL_ALL = [
   SEL_EXTERNAL, SEL_FORM, SEL_ELEMENT, SEL_STRUCTURAL, SEL_SEMI,
   SEL_COMBINING, SEL_MEDIA
 ].reduce(function (prev, curr) { return prev.concat(curr); }, []);
 
 /**
  * Find a URL for a given stylesheet
+ * @param stylesheet {StyleSheet|StyleSheetActor}
  */
 const sheetToUrl = exports.sheetToUrl = function (stylesheet) {
   // For <link> elements
   if (stylesheet.href) {
     return stylesheet.href;
   }
 
   // For <style> elements
   if (stylesheet.ownerNode) {
     let document = stylesheet.ownerNode.ownerDocument;
     let sheets = [...document.querySelectorAll("style")];
     let index = sheets.indexOf(stylesheet.ownerNode);
     return getURL(document) + " → <style> index " + index;
   }
 
+  // When `stylesheet` is a StyleSheetActor, we don't have access to ownerNode
+  if (stylesheet.nodeHref) {
+    return stylesheet.nodeHref + " → <style> index " + stylesheet.styleSheetIndex;
+  }
+
   throw new Error("Unknown sheet source");
 };