chore: remove test usages of createIDWeakMap (#24116)
This commit is contained in:
parent
8412aae231
commit
c0182bca15
4 changed files with 8 additions and 11 deletions
|
@ -151,8 +151,6 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
"createDoubleIDWeakMap",
|
"createDoubleIDWeakMap",
|
||||||
&electron::api::KeyWeakMap<std::pair<std::string, int32_t>>::Create);
|
&electron::api::KeyWeakMap<std::pair<std::string, int32_t>>::Create);
|
||||||
#endif
|
#endif
|
||||||
dict.SetMethod("createIDWeakMap",
|
|
||||||
&electron::api::KeyWeakMap<int32_t>::Create);
|
|
||||||
dict.SetMethod("requestGarbageCollectionForTesting",
|
dict.SetMethod("requestGarbageCollectionForTesting",
|
||||||
&RequestGarbageCollectionForTesting);
|
&RequestGarbageCollectionForTesting);
|
||||||
dict.SetMethod("isSameOrigin", &IsSameOrigin);
|
dict.SetMethod("isSameOrigin", &IsSameOrigin);
|
||||||
|
|
|
@ -71,15 +71,15 @@ describe('BrowserWindow module', () => {
|
||||||
it('window does not get garbage collected when opened', (done) => {
|
it('window does not get garbage collected when opened', (done) => {
|
||||||
const w = new BrowserWindow({ show: false });
|
const w = new BrowserWindow({ show: false });
|
||||||
// Keep a weak reference to the window.
|
// Keep a weak reference to the window.
|
||||||
const map = v8Util.createIDWeakMap<Electron.BrowserWindow>();
|
// eslint-disable-next-line no-undef
|
||||||
map.set(0, w);
|
const wr = new (globalThis as any).WeakRef(w);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// Do garbage collection, since |w| is not referenced in this closure
|
// Do garbage collection, since |w| is not referenced in this closure
|
||||||
// it would be gone after next call if there is no other reference.
|
// it would be gone after next call if there is no other reference.
|
||||||
v8Util.requestGarbageCollectionForTesting();
|
v8Util.requestGarbageCollectionForTesting();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(map.has(0)).to.equal(true);
|
expect(wr.deref()).to.not.be.undefined();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -841,18 +841,18 @@ describe('Menu module', function () {
|
||||||
menu.popup({ window: w });
|
menu.popup({ window: w });
|
||||||
|
|
||||||
// Keep a weak reference to the menu.
|
// Keep a weak reference to the menu.
|
||||||
const v8Util = process.electronBinding('v8_util');
|
// eslint-disable-next-line no-undef
|
||||||
const map = v8Util.createIDWeakMap<Electron.Menu>();
|
const wr = new (globalThis as any).WeakRef(menu);
|
||||||
map.set(0, menu);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// Do garbage collection, since |menu| is not referenced in this closure
|
// Do garbage collection, since |menu| is not referenced in this closure
|
||||||
// it would be gone after next call.
|
// it would be gone after next call.
|
||||||
|
const v8Util = process.electronBinding('v8_util');
|
||||||
v8Util.requestGarbageCollectionForTesting();
|
v8Util.requestGarbageCollectionForTesting();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// Try to receive menu from weak reference.
|
// Try to receive menu from weak reference.
|
||||||
if (map.has(0)) {
|
if (wr.deref()) {
|
||||||
map.get(0)!.closePopup();
|
wr.deref().closePopup();
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done('Menu is garbage-collected while popuping');
|
done('Menu is garbage-collected while popuping');
|
||||||
|
|
1
typings/internal-ambient.d.ts
vendored
1
typings/internal-ambient.d.ts
vendored
|
@ -38,7 +38,6 @@ declare namespace NodeJS {
|
||||||
setHiddenValue<T>(obj: any, key: string, value: T): void;
|
setHiddenValue<T>(obj: any, key: string, value: T): void;
|
||||||
deleteHiddenValue(obj: any, key: string): void;
|
deleteHiddenValue(obj: any, key: string): void;
|
||||||
requestGarbageCollectionForTesting(): void;
|
requestGarbageCollectionForTesting(): void;
|
||||||
createIDWeakMap<V>(): ElectronInternal.KeyWeakMap<number, V>;
|
|
||||||
createDoubleIDWeakMap<V>(): ElectronInternal.KeyWeakMap<[string, number], V>;
|
createDoubleIDWeakMap<V>(): ElectronInternal.KeyWeakMap<[string, number], V>;
|
||||||
setRemoteCallbackFreer(fn: Function, frameId: number, contextId: String, id: number, sender: any): void
|
setRemoteCallbackFreer(fn: Function, frameId: number, contextId: String, id: number, sender: any): void
|
||||||
weaklyTrackValue(value: any): void;
|
weaklyTrackValue(value: any): void;
|
||||||
|
|
Loading…
Reference in a new issue