Bug 1728072 - [devtools] Prevent leaking the first top level target. r=nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D123925
This commit is contained in:
Alexandre Poirot 2021-09-15 17:04:15 +00:00
Родитель e5e5c95702
Коммит a3e86c32a8
1 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@ -247,6 +247,20 @@ class TabDescriptorFront extends DescriptorMixin(
if (this.isServerTargetSwitchingEnabled()) {
this._resolveTargetFrontPromise(targetFront);
// Set a new promise in order to:
// 1) Avoid leaking the targetFront we just resolved into the previous promise.
// 2) Never return an empty target from `getTarget`
//
// About the second point:
// There is a race condition where we call `onTargetDestroyed` (which clears `this.targetFront`)
// a bit before calling `setTarget`. So that `this.targetFront` could be null,
// while we now a new target will eventually come when calling `setTarget`.
// Setting a new promise will help wait for the next target while `_targetFront` is null.
// Note that `getTarget` first look into `_targetFront` before checking for `_targetFrontPromise`.
this._targetFrontPromise = new Promise(
r => (this._resolveTargetFrontPromise = r)
);
}
}