positron icon indicating copy to clipboard operation
positron copied to clipboard

support Electron's JavaScript destructor callbacks

Open mykmelez opened this issue 9 years ago • 4 comments

Electron uses a native API to register JavaScript callbacks on destruction of certain objects:

https://github.com/mozilla/positron/search?l=javascript&q=setDestructor&utf8=%E2%9C%93

Electron uses these callbacks to destroy objects in another process that are proxies or callbacks for the objects being destroyed in this process. We'll need to support these callbacks too, or find another way to ensure that the objects in the other process are destroyed, or else we'll leak the objects in the other process.

mykmelez avatar May 19 '16 17:05 mykmelez

"this process", "other process" … I'm confused.

Could you rephrase using "process A" and "process B", @mykmelez?

Ryuno-Ki avatar May 19 '16 20:05 Ryuno-Ki

Could you rephrase using "process A" and "process B", @mykmelez?

I can, but there are actually two (related) use cases, one in process A and the other in process B, so perhaps it would be better to get more specific:

Use Case 1:

When a "renderer" process creates a "delegate object" to represent an object in the "main" (a.k.a. "browser") process, it calls v8Utils.setDestructor to register a JavaScript callback on the delegate:

https://github.com/mozilla/positron/blob/6f0f638402d5d71751c2225272dece28f58ad5f9/positron/electron/lib/renderer/api/remote.js#L204-L208

Upon destruction of the delegate, that callback sends a message to the main process, which removes the object from a registry of objects:

https://github.com/mozilla/positron/blob/6f0f638402d5d71751c2225272dece28f58ad5f9/positron/electron/lib/browser/rpc-server.js#L344-L346

Use Case 2:

When the main process creates a "callIntoRenderer function" to represent a function in a renderer process, it calls v8Utils.setDestructor to register a JavaScript callback on the function:

https://github.com/mozilla/positron/blob/6f0f638402d5d71751c2225272dece28f58ad5f9/positron/electron/lib/browser/rpc-server.js#L203-L206

Upon destruction of the function, that callback sends a message to the renderer process, which removes the object from a registry of callbacks:

https://github.com/mozilla/positron/blob/6f0f638402d5d71751c2225272dece28f58ad5f9/positron/electron/lib/renderer/api/remote.js#L241-L244

mykmelez avatar May 19 '16 21:05 mykmelez

Thanks for clarifying!

Ryuno-Ki avatar May 20 '16 19:05 Ryuno-Ki

As discussed in IRC, setDestructor has been removed from electron https://github.com/electron/electron/commit/06cf0406fe8ddcef3a500a689952c77fdfb9c9a8#diff-695530a8eced1fbb2c784d6a52a4290f

Though we'll likely need to support setRemoteCallbackFreer and setRemoteObjectFreer

brendandahl avatar May 27 '16 21:05 brendandahl