Skip to content

Commit c4fea64

Browse files
aslushnikovCommit bot
authored andcommitted
DevTools: eliminate race condition in WI.StylesSourceMapping.
If the style file was disposed, it should not do any other scheduled actions. BUG=608106 R=pfeldman Review-Url: https://codereview.chromium.org/2016943004 Cr-Commit-Position: refs/heads/master@{#402326}
1 parent f117125 commit c4fea64

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

front_end/bindings/StylesSourceMapping.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,13 @@ WebInspector.StyleFile = function(uiSourceCode, mapping)
331331
{
332332
this._uiSourceCode = uiSourceCode;
333333
this._mapping = mapping;
334-
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
335-
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
334+
this._eventListeners = [
335+
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this),
336+
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this)
337+
];
336338
this._uiSourceCode.forceLoadOnCheckContent();
337339
this._commitThrottler = new WebInspector.Throttler(WebInspector.StyleFile.updateTimeout);
340+
this._terminated = false;
338341
}
339342

340343
WebInspector.StyleFile.updateTimeout = 200;
@@ -365,6 +368,8 @@ WebInspector.StyleFile.prototype = {
365368

366369
_commitIncrementalEdit: function()
367370
{
371+
if (this._terminated)
372+
return;
368373
var promise = this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.workingCopy(), this._isMajorChangePending)
369374
.then(this._styleContentSet.bind(this))
370375
this._isMajorChangePending = false;
@@ -392,7 +397,9 @@ WebInspector.StyleFile.prototype = {
392397

393398
dispose: function()
394399
{
395-
this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
396-
this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
400+
if (this._terminated)
401+
return;
402+
this._terminated = true;
403+
WebInspector.EventTarget.removeEventListeners(this._eventListeners);
397404
}
398405
}

0 commit comments

Comments
 (0)