Skip to content

Commit

Permalink
utils: Remove signal handler item on object destruction
Browse files Browse the repository at this point in the history
If we're tracking an object destruction and that object gets destroyed,
we need to remove the signals handler storage item, or we'd end up
trying to disconnect from it again when destroying the signals handler.

Closes: #2270
  • Loading branch information
3v1n0 committed Aug 26, 2024
1 parent 1a28cf3 commit 35788bb
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ const BasicHandler = class DashToDockBasicHandler {
(this._storage[label] || []).forEach(item => this._unblock(item));
}

_removeByItem(item) {
Object.getOwnPropertySymbols(this._storage).forEach(label =>
(this._storage[label] = this._storage[label].filter(it => {
if (it === item)
return false;
if (it.length === item.length &&
it.every((_, idx) => it[idx] === item[idx])) {
this._remove(item);
return false;
}
return true;
})));
}

// Virtual methods to be implemented by subclass

/**
Expand Down Expand Up @@ -168,15 +182,27 @@ export class GlobalSignalsHandler extends BasicHandler {
`found in ${object.constructor.name}`);
}

const item = [object];
const isDestroy = event === 'destroy';
const isParentObject = object === this._parentObject;

if (isDestroy && !isParentObject) {
const originalCallback = callback;
callback = () => {
this._removeByItem(item);
originalCallback();
};
}
const id = connector.call(object, event, callback);
item.push(id);

if (event === 'destroy' && object === this._parentObject) {
if (isDestroy && isParentObject) {
this._parentObject.disconnect(this._destroyId);
this._destroyId =
this._parentObject.connect('destroy', () => this.destroy());
}

return [object, id];
return item;
}

_remove(item) {
Expand Down

0 comments on commit 35788bb

Please sign in to comment.