fix: Invalidate weak ptrs before window Javascript object is destroyed (backport: 3-0-x) (#14591)

* fix: Invalidate weak ptrs before window Javascript object is destroyed

* chore: add regression test for #14513

This test is similar to the original gist at https://gist.github.com/bpasero/a02a645e11f4946dcca1331d0299149d -- the key is to open multiple windows and add an `app.on('browser-window-focus') listener that accesses window.id.

* fix: last commit didn't test the right thing.

The test needs to run in the main process to reproduce the
conditions reported in #14513
This commit is contained in:
trop[bot] 2018-09-12 15:22:05 -05:00 committed by Charles Kerr
parent 3348e5162f
commit 02b1069fd8
3 changed files with 30 additions and 0 deletions

View file

@ -142,6 +142,11 @@ void TopLevelWindow::WillCloseWindow(bool* prevent_default) {
}
void TopLevelWindow::OnWindowClosed() {
// Invalidate weak ptrs before the Javascript object is destroyed,
// there might be some delayed emit events which shouldn't be
// triggered after this.
weak_factory_.InvalidateWeakPtrs();
RemoveFromWeakMap();
window_->RemoveObserver(this);