fix: WebContentsView removal should compare directly (#44656)

* fix: WebContentsView removal should compare directly

* fixup view comparision

* chore: use erase_if

* Apply review suggestions

---------

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
Shelley Vohr 2024-11-15 04:11:20 +01:00 committed by GitHub
parent b1957f52e3
commit 27fe6cc97f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 26 deletions

View file

@ -101,6 +101,30 @@ describe('WebContentsView', () => {
expect(w.contentView.children).to.deep.equal([wcv3, wcv1, wcv2]);
});
it('handle removal and re-addition of children', () => {
const w = new BaseWindow({ show: false });
const cv = new View();
w.setContentView(cv);
const wcv1 = new WebContentsView();
const wcv2 = new WebContentsView();
expect(w.contentView.children).to.deep.equal([]);
w.contentView.addChildView(wcv1);
w.contentView.addChildView(wcv2);
expect(w.contentView.children).to.deep.equal([wcv1, wcv2]);
w.contentView.removeChildView(wcv1);
expect(w.contentView.children).to.deep.equal([wcv2]);
w.contentView.addChildView(wcv1);
expect(w.contentView.children).to.deep.equal([wcv2, wcv1]);
});
function triggerGCByAllocation () {
const arr = [];
for (let i = 0; i < 1000000; i++) {