Skip to content
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

Remote object should be referenced by its members #4981

Merged
merged 4 commits into from
Apr 1, 2016

Conversation

zcbenz
Copy link
Member

@zcbenz zcbenz commented Apr 1, 2016

This fixes another case that would cause the exception in #4733. In JS when you store a method of an object, the object will not be referenced, so in the following case calling stringify would throw exception because the remote.getGlobal('JSON') gets garbage collected.

let stringify = remote.getGlobal('JSON').stringify
stringify({})

In normal JS this is not a problem because the methods are objects themselves and rely on this pointer when being called. However in Electron the problem is the member methods of remote objects are not real functions, they just only records the object and the method's name, and send them to the main process when being called.

This PR works around it by referencing the remote object in its remote member methods, so as long as the methods are stored by user the remote object would never be garbage collected.

A real solution should be treating member methods as real functions, and get the remote object from the this pointer. But let's try it in another PR.

Close #4733.

@zcbenz zcbenz merged commit 6f7a98d into master Apr 1, 2016
@zcbenz zcbenz deleted the member-object-reference branch April 1, 2016 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception in objects-registry when doing remote work
1 participant