fix: WebContentsView removal should compare directly (#44670)

* fix: WebContentsView removal should compare directly

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* fixup view comparision

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* chore: use erase_if

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* Apply review suggestions

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
trop[bot] 2024-11-15 13:09:34 +01:00 committed by GitHub
commit 900400e442
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++) {