From 5273930f765c680611e9d9a04e7e57938c7ba3cc Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 15 Oct 2019 18:14:41 +0200 Subject: [PATCH] refactor: use Map for callbacks in CallbacksRegistry (#20565) --- lib/renderer/remote/callbacks-registry.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/renderer/remote/callbacks-registry.ts b/lib/renderer/remote/callbacks-registry.ts index 32d50e892719..f2f164fa6fa0 100644 --- a/lib/renderer/remote/callbacks-registry.ts +++ b/lib/renderer/remote/callbacks-registry.ts @@ -2,7 +2,7 @@ const v8Util = process.electronBinding('v8_util') export class CallbacksRegistry { private nextId: number = 0 - private callbacks: Record = {} + private callbacks = new Map() add (callback: Function) { // The callback is already added. @@ -31,14 +31,14 @@ export class CallbacksRegistry { break } - this.callbacks[id] = callback + this.callbacks.set(id, callback) v8Util.setHiddenValue(callback, 'callbackId', id) v8Util.setHiddenValue(callback, 'location', filenameAndLine) return id } get (id: number) { - return this.callbacks[id] || function () {} + return this.callbacks.get(id) || function () {} } apply (id: number, ...args: any[]) { @@ -46,10 +46,10 @@ export class CallbacksRegistry { } remove (id: number) { - const callback = this.callbacks[id] + const callback = this.callbacks.get(id) if (callback) { v8Util.deleteHiddenValue(callback, 'callbackId') - delete this.callbacks[id] + this.callbacks.delete(id) } } }