Skip to content

Commit

Permalink
handle recursive objects
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-marechal committed Apr 20, 2023
1 parent fd5adcf commit 4c9753c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
}
Expand Down Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4c9753c

Please sign in to comment.