Closed AlexTrotsenko closed 5 years ago
I'm fine to merge this and I think I agree with your motivation, but one thing to call out: this will be fragile and fairly hard to maintain as a real API into the future. I'm sympathetic to your use case and want to support you, but I'm not necessarily confident that directly reaching into the Runtime module is the best contract for us to maintain. Is your integration open sourced somewhere I can see so at least Stetho can track this as a major customer to support and make sure we don't accidentally break?
@jasta sorry for delay with the answer - I have missed your reply somehow. The project is available on github: https://github.com/AlexTrotsenko/j2v8-debugger
The exact place where V8 variable is added to Runtime is following (in Kotlin).
Concerning you notes about regarding fragility of such API:
According to what I see in the doc of the Session you have faced with similar leaks issues in the past for UI elements.
remove()
method - I would be happy to use it as well.
E.g. I can imaging using concept of additional , but optional grouping of mapped objects- something like "sub-session" or "tag" etc.
The resulting code might looks like following then:
public static int mapObject(JsonRpcPeer peer, Object object, @Nullable SubSession subSession) { final Session session = getSession(peer);
if (subSession != null) { subSession.registerOnSubSessionEnded(new OnEndedReceiver() { @Override public void onDisconnect() { session.removeSubSession(subSession); } }); }
return session.getObjects(subSession).putObject(object); }
public static int mapObject(JsonRpcPeer peer, Object object) { return mapObject(peer, object, null); }
Then my client code might looks like following:
private class V8ToChromeDevToolsBreakHandler(private val currentPeerProvider: () -> JsonRpcPeer?) : BreakHandler {
val subSession = SubSession()
...
override fun onBreak(event: DebugHandler.DebugEvent?, state: ExecutionState?, eventData: EventData?, data: V8Object?) {
...
val storedVariablesId = Runtime.mapObject(currentPeerProvider(), knowVariables, subSession)
....
}
....
/**
* Resumes V8 execution. Called from Stetho thread.
*/
fun resume() {
subSession.onSubSessionEnded()
resumeWith(null)
}
}
P.S. Thanks taking time and merging all my pull requests - I will integrate the latest version of Stetho into j2v8-debugger
project.
I am developing debugger for J2V8, which uses Stetho for communication over Chrome DevTools protocol. Besides implementing Debugger domain I need to add local v8 variables to
Runtime
by static.mapObject()
in order them to be visible in the Chrome Debugger UI.The problem, that
@ChromeDevtoolsMethod
.releaseObject()
method is not called by Chrome DevTools and I want to remove objects stored in the session manually in order to avoid memory leaks and possible OOM errors. That's why I would like to have static method to remove them from session. Some work-around are possible already now, but it makes sense for me to have it becausestatic
counter-part for adding object is exists -.mapObject()
.