Skip to content

Commit c0182bc

Browse files
authored
chore: remove test usages of createIDWeakMap (electron#24116)
1 parent 8412aae commit c0182bc

4 files changed

Lines changed: 8 additions & 11 deletions

File tree

shell/common/api/electron_api_v8_util.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ void Initialize(v8::Local<v8::Object> exports,
151151
"createDoubleIDWeakMap",
152152
&electron::api::KeyWeakMap<std::pair<std::string, int32_t>>::Create);
153153
#endif
154-
dict.SetMethod("createIDWeakMap",
155-
&electron::api::KeyWeakMap<int32_t>::Create);
156154
dict.SetMethod("requestGarbageCollectionForTesting",
157155
&RequestGarbageCollectionForTesting);
158156
dict.SetMethod("isSameOrigin", &IsSameOrigin);

spec-main/api-browser-window-spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ describe('BrowserWindow module', () => {
7171
it('window does not get garbage collected when opened', (done) => {
7272
const w = new BrowserWindow({ show: false });
7373
// Keep a weak reference to the window.
74-
const map = v8Util.createIDWeakMap<Electron.BrowserWindow>();
75-
map.set(0, w);
74+
// eslint-disable-next-line no-undef
75+
const wr = new (globalThis as any).WeakRef(w);
7676
setTimeout(() => {
7777
// Do garbage collection, since |w| is not referenced in this closure
7878
// it would be gone after next call if there is no other reference.
7979
v8Util.requestGarbageCollectionForTesting();
8080

8181
setTimeout(() => {
82-
expect(map.has(0)).to.equal(true);
82+
expect(wr.deref()).to.not.be.undefined();
8383
done();
8484
});
8585
});

spec-main/api-menu-spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,18 +841,18 @@ describe('Menu module', function () {
841841
menu.popup({ window: w });
842842

843843
// Keep a weak reference to the menu.
844-
const v8Util = process.electronBinding('v8_util');
845-
const map = v8Util.createIDWeakMap<Electron.Menu>();
846-
map.set(0, menu);
844+
// eslint-disable-next-line no-undef
845+
const wr = new (globalThis as any).WeakRef(menu);
847846

848847
setTimeout(() => {
849848
// Do garbage collection, since |menu| is not referenced in this closure
850849
// it would be gone after next call.
850+
const v8Util = process.electronBinding('v8_util');
851851
v8Util.requestGarbageCollectionForTesting();
852852
setTimeout(() => {
853853
// Try to receive menu from weak reference.
854-
if (map.has(0)) {
855-
map.get(0)!.closePopup();
854+
if (wr.deref()) {
855+
wr.deref().closePopup();
856856
done();
857857
} else {
858858
done('Menu is garbage-collected while popuping');

typings/internal-ambient.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ declare namespace NodeJS {
3838
setHiddenValue<T>(obj: any, key: string, value: T): void;
3939
deleteHiddenValue(obj: any, key: string): void;
4040
requestGarbageCollectionForTesting(): void;
41-
createIDWeakMap<V>(): ElectronInternal.KeyWeakMap<number, V>;
4241
createDoubleIDWeakMap<V>(): ElectronInternal.KeyWeakMap<[string, number], V>;
4342
setRemoteCallbackFreer(fn: Function, frameId: number, contextId: String, id: number, sender: any): void
4443
weaklyTrackValue(value: any): void;

0 commit comments

Comments
 (0)