Remote object should be referenced by its members #4981
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theremote.getGlobal('JSON')
gets garbage collected.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.