diff --git a/browser/devtools/styleinspector/rule-view.js b/browser/devtools/styleinspector/rule-view.js index dad2872c589..e1154469225 100644 --- a/browser/devtools/styleinspector/rule-view.js +++ b/browser/devtools/styleinspector/rule-view.js @@ -163,6 +163,11 @@ ElementStyle.prototype = { }, destroy: function() { + if (this.destroyed) { + return; + } + this.destroyed = true; + this.dummyElement = null; this.dummyElementPromise.then(dummyElement => { dummyElement.remove(); @@ -193,6 +198,10 @@ ElementStyle.prototype = { matchedSelectors: true, filter: this.showUserAgentStyles ? "ua" : undefined, }).then(entries => { + if (this.destroyed) { + return; + } + // Make sure the dummy element has been created before continuing... return this.dummyElementPromise.then(() => { if (this.populated != populated) { @@ -1035,7 +1044,7 @@ TextProperty.prototype = { setValue: function(aValue, aPriority, force=false) { let store = this.rule.elementStyle.store; - if (aValue !== this.editor.committed.value || force) { + if (this.editor && aValue !== this.editor.committed.value || force) { store.userProperties.setProperty(this.rule.style, this.name, aValue); } @@ -1524,8 +1533,8 @@ CssRuleView.prototype = { this.element.parentNode.removeChild(this.element); } - if (this.elementStyle) { - this.elementStyle.destroy(); + if (this._elementStyle) { + this._elementStyle.destroy(); } this.popup.destroy(); @@ -1575,14 +1584,23 @@ CssRuleView.prototype = { return; } - // Repopulate the element style. - this._populate(true); + // Repopulate the element style once the current modifications are done. + let promises = []; + for (let rule of this._elementStyle.rules) { + if (rule._applyingModifications) { + promises.push(rule._applyingModifications); + } + } + + return promise.all(promises).then(() => { + return this._populate(true); + }); }, _populate: function(clearRules = false) { let elementStyle = this._elementStyle; return this._elementStyle.populate().then(() => { - if (this._elementStyle != elementStyle) { + if (this._elementStyle != elementStyle || this.isDestroyed) { return; } @@ -1628,7 +1646,11 @@ CssRuleView.prototype = { clear: function() { this._clearRules(); this._viewedElement = null; - this._elementStyle = null; + + if (this._elementStyle) { + this._elementStyle.destroy(); + this._elementStyle = null; + } }, /** diff --git a/toolkit/devtools/server/protocol.js b/toolkit/devtools/server/protocol.js index 7b0b3afd82e..5ee2aee094b 100644 --- a/toolkit/devtools/server/protocol.js +++ b/toolkit/devtools/server/protocol.js @@ -7,7 +7,7 @@ let { Cu } = require("chrome"); let DevToolsUtils = require("devtools/toolkit/DevToolsUtils"); let Services = require("Services"); -let promise = require("devtools/toolkit/deprecated-sync-thenables"); +let promise = require("promise"); let {Class} = require("sdk/core/heritage"); let {EventTarget} = require("sdk/event/target"); let events = require("sdk/event/core");