From e406ba9558cc6a44da5fbc329ba1afee4d1679ad Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 25 Feb 2021 13:09:00 -0800 Subject: [PATCH] fix: values return from the ctx bridge with dynamic property support should themselves support dynamic properties (#27899) --- .../api/electron_api_context_bridge.cc | 6 ++- spec-main/api-context-bridge-spec.ts | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/shell/renderer/api/electron_api_context_bridge.cc b/shell/renderer/api/electron_api_context_bridge.cc index 0b9569ef2a01..0af41c50ecd1 100644 --- a/shell/renderer/api/electron_api_context_bridge.cc +++ b/shell/renderer/api/electron_api_context_bridge.cc @@ -485,13 +485,15 @@ v8::MaybeLocal CreateProxyForAPI( v8::Local setter_proxy; if (!getter.IsEmpty()) { if (!PassValueToOtherContext(source_context, destination_context, - getter, object_cache, false, 1) + getter, object_cache, + support_dynamic_properties, 1) .ToLocal(&getter_proxy)) continue; } if (!setter.IsEmpty()) { if (!PassValueToOtherContext(source_context, destination_context, - setter, object_cache, false, 1) + setter, object_cache, + support_dynamic_properties, 1) .ToLocal(&setter_proxy)) continue; } diff --git a/spec-main/api-context-bridge-spec.ts b/spec-main/api-context-bridge-spec.ts index c3224ea99a49..743a6609020c 100644 --- a/spec-main/api-context-bridge-spec.ts +++ b/spec-main/api-context-bridge-spec.ts @@ -1082,6 +1082,24 @@ describe('contextBridge', () => { expect(result).to.equal('hi there'); }); + it('should work with nested getters', async () => { + await makeBindingWindow(() => { + contextBridge.internalContextBridge!.overrideGlobalValueWithDynamicPropsFromIsolatedWorld(['thing'], { + get foo () { + return { + get bar () { + return 'hi there'; + } + }; + } + }); + }); + const result = await callWithBindings(async (root: any) => { + return root.thing.foo.bar; + }); + expect(result).to.equal('hi there'); + }); + it('should work with setters', async () => { await makeBindingWindow(() => { let a: any = null; @@ -1101,6 +1119,29 @@ describe('contextBridge', () => { expect(result).to.equal(124); }); + it('should work with nested getter / setter combos', async () => { + await makeBindingWindow(() => { + let a: any = null; + contextBridge.internalContextBridge!.overrideGlobalValueWithDynamicPropsFromIsolatedWorld(['thing'], { + get thingy () { + return { + get foo () { + return a; + }, + set foo (arg: any) { + a = arg + 1; + } + }; + } + }); + }); + const result = await callWithBindings(async (root: any) => { + root.thing.thingy.foo = 123; + return root.thing.thingy.foo; + }); + expect(result).to.equal(124); + }); + it('should work with deep properties', async () => { await makeBindingWindow(() => { contextBridge.internalContextBridge!.overrideGlobalValueWithDynamicPropsFromIsolatedWorld(['thing'], {