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
--- 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");
};