From c0182bca1509f7aa6f5d3b3c3acac65445420561 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Mon, 15 Jun 2020 13:56:51 -0700 Subject: [PATCH] chore: remove test usages of createIDWeakMap (#24116) --- shell/common/api/electron_api_v8_util.cc | 2 -- spec-main/api-browser-window-spec.ts | 6 +++--- spec-main/api-menu-spec.ts | 10 +++++----- typings/internal-ambient.d.ts | 1 - 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/shell/common/api/electron_api_v8_util.cc b/shell/common/api/electron_api_v8_util.cc index be7be6934e..9780d91c24 100644 --- a/shell/common/api/electron_api_v8_util.cc +++ b/shell/common/api/electron_api_v8_util.cc @@ -151,8 +151,6 @@ void Initialize(v8::Local exports, "createDoubleIDWeakMap", &electron::api::KeyWeakMap>::Create); #endif - dict.SetMethod("createIDWeakMap", - &electron::api::KeyWeakMap::Create); dict.SetMethod("requestGarbageCollectionForTesting", &RequestGarbageCollectionForTesting); dict.SetMethod("isSameOrigin", &IsSameOrigin); diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index d3b6f4bc64..a0152fc118 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -71,15 +71,15 @@ describe('BrowserWindow module', () => { it('window does not get garbage collected when opened', (done) => { const w = new BrowserWindow({ show: false }); // Keep a weak reference to the window. - const map = v8Util.createIDWeakMap(); - map.set(0, w); + // eslint-disable-next-line no-undef + const wr = new (globalThis as any).WeakRef(w); setTimeout(() => { // Do garbage collection, since |w| is not referenced in this closure // it would be gone after next call if there is no other reference. v8Util.requestGarbageCollectionForTesting(); setTimeout(() => { - expect(map.has(0)).to.equal(true); + expect(wr.deref()).to.not.be.undefined(); done(); }); }); diff --git a/spec-main/api-menu-spec.ts b/spec-main/api-menu-spec.ts index 8da25df7ae..afc7d093be 100644 --- a/spec-main/api-menu-spec.ts +++ b/spec-main/api-menu-spec.ts @@ -841,18 +841,18 @@ describe('Menu module', function () { menu.popup({ window: w }); // Keep a weak reference to the menu. - const v8Util = process.electronBinding('v8_util'); - const map = v8Util.createIDWeakMap(); - map.set(0, menu); + // eslint-disable-next-line no-undef + const wr = new (globalThis as any).WeakRef(menu); setTimeout(() => { // Do garbage collection, since |menu| is not referenced in this closure // it would be gone after next call. + const v8Util = process.electronBinding('v8_util'); v8Util.requestGarbageCollectionForTesting(); setTimeout(() => { // Try to receive menu from weak reference. - if (map.has(0)) { - map.get(0)!.closePopup(); + if (wr.deref()) { + wr.deref().closePopup(); done(); } else { done('Menu is garbage-collected while popuping'); diff --git a/typings/internal-ambient.d.ts b/typings/internal-ambient.d.ts index 0a043ff155..ec0b8c4507 100644 --- a/typings/internal-ambient.d.ts +++ b/typings/internal-ambient.d.ts @@ -38,7 +38,6 @@ declare namespace NodeJS { setHiddenValue(obj: any, key: string, value: T): void; deleteHiddenValue(obj: any, key: string): void; requestGarbageCollectionForTesting(): void; - createIDWeakMap(): ElectronInternal.KeyWeakMap; createDoubleIDWeakMap(): ElectronInternal.KeyWeakMap<[string, number], V>; setRemoteCallbackFreer(fn: Function, frameId: number, contextId: String, id: number, sender: any): void weaklyTrackValue(value: any): void;