Bug 1333711 - guard against DOMExceptions when accessing stylesheet cssRules;r=pbro
MozReview-Commit-ID: C2OoN0uZIo
--- a/devtools/server/css-logic.js
+++ b/devtools/server/css-logic.js
@@ -244,17 +244,17 @@ CssLogic.prototype = {
}
// Cache the sheet.
let cssSheet = this.getSheet(domSheet, this._sheetIndex++);
if (cssSheet._passId != this._passId) {
cssSheet._passId = this._passId;
// Find import and keyframes rules.
- for (let aDomRule of domSheet.cssRules) {
+ for (let aDomRule of cssSheet.getCssRules()) {
if (aDomRule.type == CSSRule.IMPORT_RULE &&
aDomRule.styleSheet &&
this.mediaMatches(aDomRule)) {
this._cacheSheet(aDomRule.styleSheet);
} else if (aDomRule.type == CSSRule.KEYFRAMES_RULE) {
this._keyframesRules.push(aDomRule);
}
}
@@ -814,19 +814,39 @@ CssSheet.prototype = {
},
/**
* Retrieve the number of rules in this stylesheet.
*
* @return {number} the number of nsIDOMCSSRule objects in this stylesheet.
*/
get ruleCount() {
- return this._ruleCount > -1 ?
- this._ruleCount :
- this.domSheet.cssRules.length;
+ try {
+ return this._ruleCount > -1 ?
+ this._ruleCount :
+ this.getCssRules().length;
+ } catch (e) {
+ return 0;
+ }
+ },
+
+ /**
+ * Retrieve the array of css rules for this stylesheet.
+ *
+ * Accessing cssRules on a stylesheet that is not completely loaded can throw a
+ * DOMException (Bug 625013). This wrapper will return an empty array instead.
+ *
+ * @return {Array} array of css rules.
+ **/
+ getCssRules: function () {
+ try {
+ return this.domSheet.cssRules;
+ } catch (e) {
+ return [];
+ }
},
/**
* Retrieve a CssRule object for the given CSSStyleRule. The CssRule object is
* cached, such that subsequent retrievals return the same CssRule object for
* the same CSSStyleRule object.
*
* @param {CSSStyleRule} aDomRule the CSSStyleRule object for which you want a