diff --git a/shell/common/api/electron_api_v8_util.cc b/shell/common/api/electron_api_v8_util.cc index f8ae215b9197..4109ba1de987 100644 --- a/shell/common/api/electron_api_v8_util.cc +++ b/shell/common/api/electron_api_v8_util.cc @@ -106,28 +106,6 @@ bool IsSameOrigin(const GURL& l, const GURL& r) { return url::Origin::Create(l).IsSameOriginWith(url::Origin::Create(r)); } -#if DCHECK_IS_ON() -std::vector> weakly_tracked_values; - -void WeaklyTrackValue(v8::Isolate* isolate, v8::Local value) { - v8::Global global_value(isolate, value); - global_value.SetWeak(); - weakly_tracked_values.push_back(std::move(global_value)); -} - -void ClearWeaklyTrackedValues() { - weakly_tracked_values.clear(); -} - -std::vector> GetWeaklyTrackedValues(v8::Isolate* isolate) { - std::vector> locals; - for (const auto& value : weakly_tracked_values) { - if (!value.IsEmpty()) - locals.push_back(value.Get(isolate)); - } - return locals; -} - // This causes a fatal error by creating a circular extension dependency. void TriggerFatalErrorForTesting(v8::Isolate* isolate) { static const char* aDeps[] = {"B"}; @@ -141,7 +119,6 @@ void TriggerFatalErrorForTesting(v8::Isolate* isolate) { void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } -#endif void Initialize(v8::Local exports, v8::Local unused, @@ -157,9 +134,6 @@ void Initialize(v8::Local exports, &RequestGarbageCollectionForTesting); dict.SetMethod("isSameOrigin", &IsSameOrigin); dict.SetMethod("triggerFatalErrorForTesting", &TriggerFatalErrorForTesting); - dict.SetMethod("getWeaklyTrackedValues", &GetWeaklyTrackedValues); - dict.SetMethod("clearWeaklyTrackedValues", &ClearWeaklyTrackedValues); - dict.SetMethod("weaklyTrackValue", &WeaklyTrackValue); dict.SetMethod("runUntilIdle", &RunUntilIdle); } diff --git a/spec-main/api-context-bridge-spec.ts b/spec-main/api-context-bridge-spec.ts index ca3b965bd985..5a979611f1f6 100644 --- a/spec-main/api-context-bridge-spec.ts +++ b/spec-main/api-context-bridge-spec.ts @@ -615,11 +615,11 @@ describe('contextBridge', () => { if (!useSandbox) { it('should release the global hold on methods sent across contexts', async () => { await makeBindingWindow(() => { - require('electron').ipcRenderer.on('get-gc-info', (e: Electron.IpcRendererEvent) => e.sender.send('gc-info', { trackedValues: process._linkedBinding('electron_common_v8_util').getWeaklyTrackedValues().length })); - const { weaklyTrackValue } = process._linkedBinding('electron_common_v8_util'); + const trackedValues: WeakRef[] = []; + require('electron').ipcRenderer.on('get-gc-info', e => e.sender.send('gc-info', { trackedValues: trackedValues.filter(value => value.deref()).length })); contextBridge.exposeInMainWorld('example', { getFunction: () => () => 123, - track: weaklyTrackValue + track: (value: object) => { trackedValues.push(new WeakRef(value)); } }); }); await callWithBindings(async (root: any) => { @@ -643,11 +643,11 @@ describe('contextBridge', () => { if (useSandbox) { it('should not leak the global hold on methods sent across contexts when reloading a sandboxed renderer', async () => { await makeBindingWindow(() => { - require('electron').ipcRenderer.on('get-gc-info', e => e.sender.send('gc-info', { trackedValues: process._linkedBinding('electron_common_v8_util').getWeaklyTrackedValues().length })); - const { weaklyTrackValue } = process._linkedBinding('electron_common_v8_util'); + const trackedValues: WeakRef[] = []; + require('electron').ipcRenderer.on('get-gc-info', e => e.sender.send('gc-info', { trackedValues: trackedValues.filter(value => value.deref()).length })); contextBridge.exposeInMainWorld('example', { getFunction: () => () => 123, - track: weaklyTrackValue + track: (value: object) => { trackedValues.push(new WeakRef(value)); } }); require('electron').ipcRenderer.send('window-ready-for-tasking'); }); diff --git a/typings/internal-ambient.d.ts b/typings/internal-ambient.d.ts index b8540dc11978..3d676c9a9fe9 100644 --- a/typings/internal-ambient.d.ts +++ b/typings/internal-ambient.d.ts @@ -44,9 +44,6 @@ declare namespace NodeJS { setHiddenValue(obj: any, key: string, value: T): void; deleteHiddenValue(obj: any, key: string): void; requestGarbageCollectionForTesting(): void; - weaklyTrackValue(value: any): void; - clearWeaklyTrackedValues(): void; - getWeaklyTrackedValues(): any[]; runUntilIdle(): void; isSameOrigin(a: string, b: string): boolean; triggerFatalErrorForTesting(): void;