fix: values return from the ctx bridge with dynamic property support should themselves support dynamic properties (#27899)
This commit is contained in:
parent
4d5e0cf2c4
commit
e406ba9558
2 changed files with 45 additions and 2 deletions
|
@ -485,13 +485,15 @@ v8::MaybeLocal<v8::Object> CreateProxyForAPI(
|
||||||
v8::Local<v8::Value> setter_proxy;
|
v8::Local<v8::Value> setter_proxy;
|
||||||
if (!getter.IsEmpty()) {
|
if (!getter.IsEmpty()) {
|
||||||
if (!PassValueToOtherContext(source_context, destination_context,
|
if (!PassValueToOtherContext(source_context, destination_context,
|
||||||
getter, object_cache, false, 1)
|
getter, object_cache,
|
||||||
|
support_dynamic_properties, 1)
|
||||||
.ToLocal(&getter_proxy))
|
.ToLocal(&getter_proxy))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!setter.IsEmpty()) {
|
if (!setter.IsEmpty()) {
|
||||||
if (!PassValueToOtherContext(source_context, destination_context,
|
if (!PassValueToOtherContext(source_context, destination_context,
|
||||||
setter, object_cache, false, 1)
|
setter, object_cache,
|
||||||
|
support_dynamic_properties, 1)
|
||||||
.ToLocal(&setter_proxy))
|
.ToLocal(&setter_proxy))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1082,6 +1082,24 @@ describe('contextBridge', () => {
|
||||||
expect(result).to.equal('hi there');
|
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 () => {
|
it('should work with setters', async () => {
|
||||||
await makeBindingWindow(() => {
|
await makeBindingWindow(() => {
|
||||||
let a: any = null;
|
let a: any = null;
|
||||||
|
@ -1101,6 +1119,29 @@ describe('contextBridge', () => {
|
||||||
expect(result).to.equal(124);
|
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 () => {
|
it('should work with deep properties', async () => {
|
||||||
await makeBindingWindow(() => {
|
await makeBindingWindow(() => {
|
||||||
contextBridge.internalContextBridge!.overrideGlobalValueWithDynamicPropsFromIsolatedWorld(['thing'], {
|
contextBridge.internalContextBridge!.overrideGlobalValueWithDynamicPropsFromIsolatedWorld(['thing'], {
|
||||||
|
|
Loading…
Reference in a new issue