10000 Guard against missing remote function properties by kevinsawicki · Pull Request #7209 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Guard against missing remote function properties #7209

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 4 commits into from
Sep 16, 2016
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
9 changes: 8 additions & 1 deletion lib/renderer/api/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,17 @@ const proxyFunctionProperties = function (remoteMemberFunction, metaId, name) {
if (loaded) return
loaded = true
const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_GET', metaId, name)
setObjectMembers(remoteMemberFunction, remoteMemberFunction, meta.id, meta.members)
if (Array.isArray(meta.members)) {
setObjectMembers(remoteMemberFunction, remoteMemberFunction, meta.id, meta.members)
}
}

return new Proxy(remoteMemberFunction, {
set: (target, property, value, receiver) => {
if (property !== 'ref') loadRemoteProperties()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents eagerly loading the function properties when the function is accessed or invoked.

target[property] = value
return true
},
get: (target, property, receiver) => {
if (!target.hasOwnProperty(property)) loadRemoteProperties()
return target[property]
Expand Down
4 changes: 4 additions & 0 deletions spec/api-ipc-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ describe('ipc module', function () {
assert.ok(Object.keys(a.foo).includes('bar'))
assert.ok(Object.keys(a.foo).includes('nested'))
assert.ok(Object.keys(a.foo).includes('method1'))

a = remote.require(path.join(fixtures, 'module', 'function-with-missing-properties.js')).setup()
assert.equal(a.bar(), true)
assert.equal(a.bar.baz, undefined)
})

it('should work with static class members', function () {
Expand Down
13 changes: 13 additions & 0 deletions spec/fixtures/module/function-with-missing-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports.setup = function () {
const foo = {}

foo.bar = function () {
return delete foo.bar.baz && delete foo.bar
}

foo.bar.baz = function () {
return 3
}

return foo
}
0