8000 fix: values return from the ctx bridge with dynamic property support should themselves support dynamic properties by VerteDinde · Pull Request #28160 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: values return from the ctx bridge with dynamic property support should themselves support dynamic properties #28160

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions shell/renderer/api/electron_api_context_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,15 @@ v8::MaybeLocal<v8::Object> CreateProxyForAPI(
v8::Local<v8::Value> 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;
}
Expand Down
41 changes: 41 additions & 0 deletions spec-main/api-context-bridge-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,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;
Expand All @@ -746,6 +764,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'], {
Expand Down
0