From 7c68490d2ea7f106ab79e5bc7ff00b92c95614ff Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 15 Dec 2019 21:40:06 -0500 Subject: [PATCH] Add setParent to popup --- ext/fg/js/popup-proxy-host.js | 3 +-- ext/fg/js/popup.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index 157097de..cb385cc2 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -114,8 +114,7 @@ class PopupProxyHost { ++this._nextId; const popup = new Popup(id, depth, this._frameIdPromise); if (parent !== null) { - popup.parent = parent; - parent.child = popup; + popup.setParent(parent); } this._popups.set(id, popup); return {popup, id}; diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index de2c7863..fafc15aa 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -113,6 +113,20 @@ class Popup { // Popup-only public functions + setParent(parent) { + if (parent === null) { + throw new Error('Cannot set popup parent to null'); + } + if (this.parent !== null) { + throw new Error('Popup already has a parent'); + } + if (parent.child !== null) { + throw new Error('Cannot parent popup to another popup which already has a child'); + } + this.parent = parent; + parent.child = this; + } + isVisible() { return this.isInjected && (this.visibleOverride !== null ? this.visibleOverride : this.visible); }