From 4c9753cd7d06938caf67bfff41424f354a64b396 Mon Sep 17 00:00:00 2001 From: Paul Marechal Date: Thu, 20 Apr 2023 15:36:09 -0400 Subject: [PATCH] handle recursive objects --- .../electron-ipc-handle-converter-impl.spec.ts | 14 ++++++++++++-- .../preload/electron-ipc-handle-converter-impl.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/core/src/electron-browser/preload/electron-ipc-handle-converter-impl.spec.ts b/packages/core/src/electron-browser/preload/electron-ipc-handle-converter-impl.spec.ts index 4bf10cd848ac4..633b3f76b721e 100644 --- a/packages/core/src/electron-browser/preload/electron-ipc-handle-converter-impl.spec.ts +++ b/packages/core/src/electron-browser/preload/electron-ipc-handle-converter-impl.spec.ts @@ -158,11 +158,11 @@ describe('IpcHandleConverterImpl', () => { }); keys.forEach(property => { if (typeof handle[property] === 'function') { - it(property, () => { + it(`handle.${property}() === instance.${property}()`, () => { assert.deepStrictEqual(handle[property](), instance[property]()); }); } else { - it(property, () => { + it(`handle.${property} === instance.${property}`, () => { assert.deepStrictEqual(handle[property], instance[property]); }); } @@ -204,5 +204,15 @@ describe('IpcHandleConverterImpl', () => { 'publicFieldA', 'publicMethodA' ]); + + it('recursive object', () => { + const ipcHandleConverter = createIpcHandleConverter(); + const instance: any = {}; + instance.self = instance; + instance.method = () => 2; + const handle = ipcHandleConverter.getIpcHandle(instance); + assert.strictEqual(handle, handle.self); + assert.strictEqual(handle.self.method(), 2); + }); }); }); diff --git a/packages/core/src/electron-browser/preload/electron-ipc-handle-converter-impl.ts b/packages/core/src/electron-browser/preload/electron-ipc-handle-converter-impl.ts index 5aaf14e5b9d4b..a41b6bcd4456d 100644 --- a/packages/core/src/electron-browser/preload/electron-ipc-handle-converter-impl.ts +++ b/packages/core/src/electron-browser/preload/electron-ipc-handle-converter-impl.ts @@ -57,7 +57,7 @@ export class ElectronIpcHandleConverterImpl implements IpcHandleConverter { console.error('invalid value: not a proxyable instance'); return null; } - // We don't need to walk the prototype chain if the prototype is already Object's or null + // We don't need to walk the prototype chain if the prototype is already Object or null const prototype = getPrototypeOf(value); if (prototype === null || prototype === Object.prototype) { return value;