Bug 1284259 - store eventEditors map on EventTooltip instance to fix destroy failures;r=ochameau draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 13 Jul 2016 15:52:07 +0200
changeset 387172 eb47f8c887f8d2235617ef6a092304d3f6120af4
parent 387171 5b59319ed5b9790957fc2c1d30ab49d191fb6b76
child 525293 4ac1881386732ea6fe2c5b1efd865de8a341929d
push id22900
push userjdescottes@mozilla.com
push dateWed, 13 Jul 2016 13:52:39 +0000
reviewersochameau
bugs1284259
milestone50.0a1
Bug 1284259 - store eventEditors map on EventTooltip instance to fix destroy failures;r=ochameau MozReview-Commit-ID: XbahMTzqUA
devtools/client/shared/widgets/tooltip/EventTooltipHelper.js
--- a/devtools/client/shared/widgets/tooltip/EventTooltipHelper.js
+++ b/devtools/client/shared/widgets/tooltip/EventTooltipHelper.js
@@ -37,17 +37,17 @@ function setEventTooltip(tooltip, eventL
   let eventTooltip = new EventTooltip(tooltip, eventListenerInfos, toolbox);
   eventTooltip.init();
 }
 
 function EventTooltip(tooltip, eventListenerInfos, toolbox) {
   this._tooltip = tooltip;
   this._eventListenerInfos = eventListenerInfos;
   this._toolbox = toolbox;
-  this._tooltip.eventEditors = new WeakMap();
+  this._eventEditors = new WeakMap();
 
   this._headerClicked = this._headerClicked.bind(this);
   this._debugClicked = this._debugClicked.bind(this);
   this.destroy = this.destroy.bind(this);
 }
 
 EventTooltip.prototype = {
   init: function () {
@@ -140,17 +140,17 @@ EventTooltip.prototype = {
         dom0.textContent = level;
         dom0.setAttribute("title", level);
         attributesBox.appendChild(dom0);
       }
 
       // Content
       let content = doc.createElementNS(XHTML_NS, "div");
       let editor = new Editor(config);
-      this._tooltip.eventEditors.set(content, {
+      this._eventEditors.set(content, {
         editor: editor,
         handler: listener.handler,
         searchString: listener.searchString,
         uri: listener.origin,
         dom0: listener.DOM0,
         appended: false
       });
 
@@ -187,32 +187,32 @@ EventTooltip.prototype = {
       for (let node of contentNodes) {
         if (node !== content) {
           node.removeAttribute("open");
         }
       }
 
       content.setAttribute("open", "");
 
-      let eventEditors = this._tooltip.eventEditors.get(content);
+      let eventEditor = this._eventEditors.get(content);
 
-      if (eventEditors.appended) {
+      if (eventEditor.appended) {
         return;
       }
 
-      let {editor, handler} = eventEditors;
+      let {editor, handler} = eventEditor;
 
       let iframe = doc.createElementNS(XHTML_NS, "iframe");
       iframe.setAttribute("style", "width: 100%; height: 100%; border-style: none;");
 
       editor.appendTo(content, iframe).then(() => {
         let tidied = beautify.js(handler, { "indent_size": 2 });
         editor.setText(tidied);
 
-        eventEditors.appended = true;
+        eventEditor.appended = true;
 
         let container = header.parentElement.getBoundingClientRect();
         if (header.getBoundingClientRect().top < container.top) {
           header.scrollIntoView(true);
         } else if (content.getBoundingClientRect().bottom > container.bottom) {
           content.scrollIntoView(false);
         }
 
@@ -220,17 +220,17 @@ EventTooltip.prototype = {
       });
     }
   },
 
   _debugClicked: function (event) {
     let header = event.currentTarget;
     let content = header.nextElementSibling;
 
-    let {uri, searchString, dom0} = this._tooltip.eventEditors.get(content);
+    let {uri, searchString, dom0} = this._eventEditors.get(content);
 
     if (uri && uri !== "?") {
       // Save a copy of toolbox as it will be set to null when we hide the tooltip.
       let toolbox = this._toolbox;
 
       this._tooltip.hide();
 
       uri = uri.replace(/"/g, "");
@@ -285,21 +285,21 @@ EventTooltip.prototype = {
 
   destroy: function () {
     if (this._tooltip) {
       this._tooltip.off("hidden", this.destroy);
 
       let boxes = this.container.querySelectorAll(".event-tooltip-content-box");
 
       for (let box of boxes) {
-        let {editor} = this._tooltip.eventEditors.get(box);
+        let {editor} = this._eventEditors.get(box);
         editor.destroy();
       }
 
-      this._tooltip.eventEditors = null;
+      this._eventEditors = null;
     }
 
     let headerNodes = this.container.querySelectorAll(".event-header");
 
     for (let node of headerNodes) {
       node.removeEventListener("click", this._headerClicked);
     }