Bug 1319365 - Bail out of the async function getSelectorHighlighter when the inspector is unavailable. r=jdescottes
authorGabriel Luong <gabriel.luong@gmail.com>
Tue, 22 Nov 2016 18:54:09 +0800
changeset 323832 39efc7bfb839484ef121a2f275481770906d9021
parent 323831 ee8e6503d47c5f5cf5515b41f9594ec5d9eb63ae
child 323833 5230f39d8f21270414aea3cdfb97914fc6acf4c1
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersjdescottes
bugs1319365
milestone53.0a1
Bug 1319365 - Bail out of the async function getSelectorHighlighter when the inspector is unavailable. r=jdescottes
devtools/client/inspector/rules/rules.js
--- a/devtools/client/inspector/rules/rules.js
+++ b/devtools/client/inspector/rules/rules.js
@@ -207,16 +207,20 @@ CssRuleView.prototype = {
   /**
    * Get an instance of SelectorHighlighter (used to highlight nodes that match
    * selectors in the rule-view). A new instance is only created the first time
    * this function is called. The same instance will then be returned.
    *
    * @return {Promise} Resolves to the instance of the highlighter.
    */
   getSelectorHighlighter: Task.async(function* () {
+    if (!this.inspector) {
+      return null;
+    }
+
     let utils = this.inspector.toolbox.highlighterUtils;
     if (!utils.supportsCustomHighlighters()) {
       return null;
     }
 
     if (this.selectorHighlighter) {
       return this.selectorHighlighter;
     }
@@ -265,23 +269,23 @@ CssRuleView.prototype = {
       } else {
         this.highlighters.selectorHighlighterShown = null;
         this.emit("ruleview-selectorhighlighter-toggled", false);
       }
     }, e => console.error(e));
   },
 
   highlightSelector: Task.async(function* (selector) {
-    let node = this.inspector.selection.nodeFront;
-
     let highlighter = yield this.getSelectorHighlighter();
     if (!highlighter) {
       return;
     }
 
+    let node = this.inspector.selection.nodeFront;
+
     yield highlighter.show(node, {
       hideInfoBar: true,
       hideGuides: true,
       selector
     });
   }),
 
   unhighlightSelector: Task.async(function* () {