Update PopupProxyHost.popups to use a Map

This commit is contained in:
toasted-nutbread 2019-12-15 16:58:44 -05:00
parent 8efbf9bd0d
commit 88ac8f4ead

View File

@ -19,7 +19,7 @@
class PopupProxyHost { class PopupProxyHost {
constructor() { constructor() {
this.popups = {}; this.popups = new Map();
this.nextId = 0; this.nextId = 0;
this.apiReceiver = null; this.apiReceiver = null;
this.frameIdPromise = null; this.frameIdPromise = null;
@ -50,7 +50,7 @@ class PopupProxyHost {
} }
createPopup(parentId, depth) { createPopup(parentId, depth) {
const parent = (typeof parentId === 'string' && hasOwn(this.popups, parentId) ? this.popups[parentId] : null); const parent = (typeof parentId === 'string' && this.popups.has(parentId) ? this.popups.get(parentId) : null);
const id = `${this.nextId}`; const id = `${this.nextId}`;
if (parent !== null) { if (parent !== null) {
depth = parent.depth + 1; depth = parent.depth + 1;
@ -61,7 +61,7 @@ class PopupProxyHost {
popup.parent = parent; popup.parent = parent;
parent.child = popup; parent.child = popup;
} }
this.popups[id] = popup; this.popups.set(id, popup);
return popup; return popup;
} }
@ -70,11 +70,11 @@ class PopupProxyHost {
} }
getPopup(id) { getPopup(id) {
if (!hasOwn(this.popups, id)) { const popup = this.popups.get(id);
if (typeof popup === 'undefined') {
throw new Error('Invalid popup ID'); throw new Error('Invalid popup ID');
} }
return popup;
return this.popups[id];
} }
jsonRectToDOMRect(popup, jsonRect) { jsonRectToDOMRect(popup, jsonRect) {