diff --git a/lib/browser/remote/objects-registry.ts b/lib/browser/remote/objects-registry.ts index 32a05018aea..ba146106469 100644 --- a/lib/browser/remote/objects-registry.ts +++ b/lib/browser/remote/objects-registry.ts @@ -4,8 +4,6 @@ const getOwnerKey = (webContents: WebContents, contextId: string) => { return `${webContents.id}-${contextId}`; }; -const electronIds = new WeakMap(); - class ObjectsRegistry { private nextId: number = 0 @@ -17,6 +15,8 @@ class ObjectsRegistry { // (ownerKey) => { id: refCount } private owners: Record> = {} + private electronIds = new WeakMap(); + // Register a new object and return its assigned ID. If the object is already // registered then the already assigned ID would be returned. add (webContents: WebContents, contextId: string, obj: any) { @@ -81,14 +81,14 @@ class ObjectsRegistry { // Private: Saves the object into storage and assigns an ID for it. saveToStorage (object: any) { - let id = electronIds.get(object); + let id = this.electronIds.get(object); if (!id) { id = ++this.nextId; this.storage[id] = { count: 0, object: object }; - electronIds.set(object, id); + this.electronIds.set(object, id); } return id; } @@ -101,7 +101,7 @@ class ObjectsRegistry { } pointer.count -= 1; if (pointer.count === 0) { - electronIds.delete(pointer.object); + this.electronIds.delete(pointer.object); delete this.storage[id]; } } diff --git a/lib/renderer/remote/callbacks-registry.ts b/lib/renderer/remote/callbacks-registry.ts index c36d84c7a3c..a413214d1c8 100644 --- a/lib/renderer/remote/callbacks-registry.ts +++ b/lib/renderer/remote/callbacks-registry.ts @@ -1,13 +1,12 @@ -const callbackIds = new WeakMap(); -const locationInfo = new WeakMap(); - export class CallbacksRegistry { private nextId: number = 0 private callbacks = new Map() + private callbackIds = new WeakMap(); + private locationInfo = new WeakMap(); add (callback: Function) { // The callback is already added. - let id = callbackIds.get(callback); + let id = this.callbackIds.get(callback); if (id != null) return id; id = this.nextId += 1; @@ -33,8 +32,8 @@ export class CallbacksRegistry { } this.callbacks.set(id, callback); - callbackIds.set(callback, id); - locationInfo.set(callback, filenameAndLine!); + this.callbackIds.set(callback, id); + this.locationInfo.set(callback, filenameAndLine!); return id; } @@ -43,7 +42,7 @@ export class CallbacksRegistry { } getLocation (callback: Function) { - return locationInfo.get(callback); + return this.locationInfo.get(callback); } apply (id: number, ...args: any[]) { @@ -53,7 +52,7 @@ export class CallbacksRegistry { remove (id: number) { const callback = this.callbacks.get(id); if (callback) { - callbackIds.delete(callback); + this.callbackIds.delete(callback); this.callbacks.delete(id); } }