Skip to content

Commit e406ba9

Browse files
fix: values return from the ctx bridge with dynamic property support should themselves support dynamic properties (electron#27899)
1 parent 4d5e0cf commit e406ba9

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

shell/renderer/api/electron_api_context_bridge.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,15 @@ v8::MaybeLocal<v8::Object> CreateProxyForAPI(
485485
v8::Local<v8::Value> setter_proxy;
486486
if (!getter.IsEmpty()) {
487487
if (!PassValueToOtherContext(source_context, destination_context,
488-
getter, object_cache, false, 1)
488+
getter, object_cache,
489+
support_dynamic_properties, 1)
489490
.ToLocal(&getter_proxy))
490491
continue;
491492
}
492493
if (!setter.IsEmpty()) {
493494
if (!PassValueToOtherContext(source_context, destination_context,
494-
setter, object_cache, false, 1)
495+
setter, object_cache,
496+
support_dynamic_properties, 1)
495497
.ToLocal(&setter_proxy))
496498
continue;
497499
}

spec-main/api-context-bridge-spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,24 @@ describe('contextBridge', () => {
10821082
expect(result).to.equal('hi there');
10831083
});
10841084

1085+
it('should work with nested getters', async () => {
1086+
await makeBindingWindow(() => {
1087+
contextBridge.internalContextBridge!.overrideGlobalValueWithDynamicPropsFromIsolatedWorld(['thing'], {
1088+
get foo () {
1089+
return {
1090+
get bar () {
1091+
return 'hi there';
1092+
}
1093+
};
1094+
}
1095+
});
1096+
});
1097+
const result = await callWithBindings(async (root: any) => {
1098+
return root.thing.foo.bar;
1099+
});
1100+
expect(result).to.equal('hi there');
1101+
});
1102+
10851103
it('should work with setters', async () => {
10861104
await makeBindingWindow(() => {
10871105
let a: any = null;
@@ -1101,6 +1119,29 @@ describe('contextBridge', () => {
11011119
expect(result).to.equal(124);
11021120
});
11031121

1122+
it('should work with nested getter / setter combos', async () => {
1123+
await makeBindingWindow(() => {
1124+
let a: any = null;
1125+
contextBridge.internalContextBridge!.overrideGlobalValueWithDynamicPropsFromIsolatedWorld(['thing'], {
1126+
get thingy () {
1127+
return {
1128+
get foo () {
1129+
return a;
1130+
},
1131+
set foo (arg: any) {
1132+
a = arg + 1;
1133+
}
1134+
};
1135+
}
1136+
});
1137+
});
1138+
const result = await callWithBindings(async (root: any) => {
1139+
root.thing.thingy.foo = 123;
1140+
return root.thing.thingy.foo;
1141+
});
1142+
expect(result).to.equal(124);
1143+
});
1144+
11041145
it('should work with deep properties', async () => {
11051146
await makeBindingWindow(() => {
11061147
contextBridge.internalContextBridge!.overrideGlobalValueWithDynamicPropsFromIsolatedWorld(['thing'], {

0 commit comments

Comments
 (0)