Bug 1468768 - Part 3: Clean up the code in ElementStyle. r=pbro
authorGabriel Luong <gabriel.luong@gmail.com>
Tue, 19 Jun 2018 09:59:34 -0400
changeset 479720 2d5727bbe035f34e4044878e2870520291286156
parent 479719 c86e60a88b37921d2a98d57dab7d5ea281e39351
child 479721 e429320fcdd2d5236bb4713e6c435456146e42b9
child 479742 5e2eaa601a6d98b5c6d892dc1a6f409145edef7e
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1468768
milestone62.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 1468768 - Part 3: Clean up the code in ElementStyle. r=pbro
devtools/client/inspector/rules/models/element-style.js
--- a/devtools/client/inspector/rules/models/element-style.js
+++ b/devtools/client/inspector/rules/models/element-style.js
@@ -25,18 +25,17 @@ const { ELEMENT_STYLE } = require("devto
  *         that might outlast the rule view, particularly the current
  *         set of disabled properties.
  * @param  {PageStyleFront} pageStyle
  *         Front for the page style actor that will be providing
  *         the style information.
  * @param  {Boolean} showUserAgentStyles
  *         Should user agent styles be inspected?
  */
-function ElementStyle(element, ruleView, store, pageStyle,
-    showUserAgentStyles) {
+function ElementStyle(element, ruleView, store, pageStyle, showUserAgentStyles) {
   this.element = element;
   this.ruleView = ruleView;
   this.store = store || {};
   this.pageStyle = pageStyle;
   this.showUserAgentStyles = showUserAgentStyles;
   this.rules = [];
   this.cssProperties = getCssProperties(this.ruleView.inspector.toolbox);
   this.variables = new Map();
@@ -48,23 +47,21 @@ function ElementStyle(element, ruleView,
   }
 
   if (!("disabled" in this.store)) {
     this.store.disabled = new WeakMap();
   }
 }
 
 ElementStyle.prototype = {
-  // The element we're looking at.
-  element: null,
-
   destroy: function() {
     if (this.destroyed) {
       return;
     }
+
     this.destroyed = true;
 
     for (const rule of this.rules) {
       if (rule.editor) {
         rule.editor.destroy();
       }
     }
   },
@@ -87,22 +84,17 @@ ElementStyle.prototype = {
    * ready.
    */
   populate: function() {
     const populated = this.pageStyle.getApplied(this.element, {
       inherited: true,
       matchedSelectors: true,
       filter: this.showUserAgentStyles ? "ua" : undefined,
     }).then(entries => {
-      if (this.destroyed) {
-        return promise.resolve(undefined);
-      }
-
-      if (this.populated !== populated) {
-        // Don't care anymore.
+      if (this.destroyed || this.populated !== populated) {
         return promise.resolve(undefined);
       }
 
       // Store the current list of rules (if any) during the population
       // process. They will be reused if possible.
       const existingRules = this.rules;
 
       this.rules = [];
@@ -174,22 +166,18 @@ ElementStyle.prototype = {
    * @param  {Array} existingRules
    *         Rules to reuse if possible. If a rule is reused, then it
    *         it will be deleted from this array.
    * @return {Boolean} true if we added the rule.
    */
   _maybeAddRule: function(options, existingRules) {
     // If we've already included this domRule (for example, when a
     // common selector is inherited), ignore it.
-    if (options.rule &&
-        this.rules.some(rule => rule.domRule === options.rule)) {
-      return false;
-    }
-
-    if (options.system) {
+    if (options.system ||
+        (options.rule && this.rules.some(rule => rule.domRule === options.rule))) {
       return false;
     }
 
     let rule = null;
 
     // If we're refreshing and the rule previously existed, reuse the
     // Rule object.
     if (existingRules) {