Bug 1463652 - Lazy load the sourceMapURLService from the rule editor. r=pbro draft
authorGabriel Luong <gabriel.luong@gmail.com>
Wed, 23 May 2018 02:00:18 -0400
changeset 798617 52bfc320649589a04634a9054a7fbb9ab3b5a7d9
parent 798616 66f6b8d84e5d35d0de8d07d3e9de44a9cce913f2
push id110803
push userbmo:gl@mozilla.com
push dateWed, 23 May 2018 06:00:40 +0000
reviewerspbro
bugs1463652
milestone62.0a1
Bug 1463652 - Lazy load the sourceMapURLService from the rule editor. r=pbro MozReview-Commit-ID: Ei9g4zLO7KI
devtools/client/inspector/rules/views/rule-editor.js
--- a/devtools/client/inspector/rules/views/rule-editor.js
+++ b/devtools/client/inspector/rules/views/rule-editor.js
@@ -49,19 +49,16 @@ const STYLE_INSPECTOR_L10N = new Localiz
  *        The Rule object we're editing.
  */
 function RuleEditor(ruleView, rule) {
   EventEmitter.decorate(this);
 
   this.ruleView = ruleView;
   this.doc = this.ruleView.styleDocument;
   this.toolbox = this.ruleView.inspector.toolbox;
-  // We stash this locally so that we can refer to it from |destroy|
-  // without accidentally reinstantiating the service during shutdown.
-  this.sourceMapURLService = this.toolbox.sourceMapURLService;
   this.rule = rule;
 
   this.isEditable = !rule.isSystem;
   // Flag that blocks updates of the selector and properties when it is
   // being edited
   this.isEditing = false;
 
   this._onNewProperty = this._onNewProperty.bind(this);
@@ -90,21 +87,32 @@ RuleEditor.prototype = {
     if (this.rule.sheet) {
       url = this.rule.sheet.href || this.rule.sheet.nodeHref;
     }
     if (url && !this.rule.isSystem && this.rule.domRule.type !== ELEMENT_STYLE) {
       // Only get the original source link if the rule isn't a system
       // rule and if it isn't an inline rule.
       let sourceLine = this.rule.ruleLine;
       let sourceColumn = this.rule.ruleColumn;
-      this.sourceMapURLService.unsubscribe(url, sourceLine, sourceColumn,
-                                           this._updateLocation);
+
+      if (this._sourceMapURLService) {
+        this.sourceMapURLService.unsubscribe(url, sourceLine, sourceColumn,
+          this._updateLocation);
+      }
     }
   },
 
+  get sourceMapURLService() {
+    if (!this._sourceMapURLService) {
+      this._sourceMapURLService = this.toolbox.sourceMapURLService;
+    }
+
+    return this._sourceMapURLService;
+  },
+
   get isSelectorEditable() {
     let trait = this.isEditable &&
       this.ruleView.inspector.target.client.traits.selectorEditable &&
       this.rule.domRule.type !== ELEMENT_STYLE &&
       this.rule.domRule.type !== CSSRule.KEYFRAME_RULE;
 
     // Do not allow editing anonymousselectors until we can
     // detect mutations on  pseudo elements in Bug 1034110.