Bug 1333711 - guard against DOMExceptions when accessing stylesheet cssRules;r=gl
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 13 Feb 2017 16:23:39 +0100
changeset 342893 20e11ca9a35f6fffa3253811be855472ef3e1b48
parent 342892 4aef71d8a98724202391e48a1be5bbe65dc1434f
child 342894 7d9b751f833bca6466dc49eb7159b2110a7209cc
push id37402
push userjdescottes@mozilla.com
push dateWed, 15 Feb 2017 08:53:24 +0000
treeherderautoland@20e11ca9a35f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1333711
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1333711 - guard against DOMExceptions when accessing stylesheet cssRules;r=gl MozReview-Commit-ID: C2OoN0uZIo
devtools/server/css-logic.js
--- 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