mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 09:29:07 +08:00
Add Page, Runtime, Debugger agents
Summary: Runtime and Debugger agents are shipped with JSC so we reuse them. Messages are routed to them through the `LegacyDispatcher` which also handles translating their events. The Page agent emits the `Page.getResourceTree` method that the Chrome inspector expects. Reviewed By: michalgr Differential Revision: D4021499 fbshipit-source-id: a93d0add01cee732401f8e8db1d43205bfbd4cd4
This commit is contained in:
committed by
Facebook Github Bot
parent
156e5d9837
commit
0ac7bf29af
64
ReactCommon/inspector/LegacyScriptDebugServer.cpp
Normal file
64
ReactCommon/inspector/LegacyScriptDebugServer.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#include "LegacyScriptDebugServer.h"
|
||||
|
||||
#include <JavaScriptCore/JSGlobalObject.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
using namespace Inspector;
|
||||
|
||||
LegacyScriptDebugServer::LegacyScriptDebugServer(JSC::JSGlobalObject& globalObject)
|
||||
: Inspector::ScriptDebugServer(false)
|
||||
, globalObject_(globalObject) {}
|
||||
|
||||
void LegacyScriptDebugServer::addListener(ScriptDebugListener* listener)
|
||||
{
|
||||
if (!listener) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool wasEmpty = listeners_.isEmpty();
|
||||
listeners_.add(listener);
|
||||
|
||||
// First listener. Attach the debugger to the JSGlobalObject.
|
||||
if (wasEmpty) {
|
||||
attach(&globalObject_);
|
||||
recompileAllJSFunctions();
|
||||
}
|
||||
}
|
||||
|
||||
void LegacyScriptDebugServer::removeListener(ScriptDebugListener* listener, bool isBeingDestroyed) {
|
||||
if (!listener) {
|
||||
return;
|
||||
}
|
||||
|
||||
listeners_.remove(listener);
|
||||
|
||||
// Last listener. Detach the debugger from the JSGlobalObject.
|
||||
if (listeners_.isEmpty()) {
|
||||
detach(&globalObject_, isBeingDestroyed ? Debugger::GlobalObjectIsDestructing : Debugger::TerminatingDebuggingSession);
|
||||
if (!isBeingDestroyed) {
|
||||
recompileAllJSFunctions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LegacyScriptDebugServer::recompileAllJSFunctions() {
|
||||
JSC::Debugger::recompileAllJSFunctions(&globalObject_.vm());
|
||||
}
|
||||
|
||||
void LegacyScriptDebugServer::runEventLoopWhilePaused() {
|
||||
// Drop all locks so another thread can work in the VM while we are nested.
|
||||
JSC::JSLock::DropAllLocks dropAllLocks(&globalObject_.vm());
|
||||
|
||||
// Spinning here is our best option, we could override the method
|
||||
// notifyDoneProcessingDebuggerEvents but it's marked as final :(
|
||||
while (!m_doneProcessingDebuggerEvents) {
|
||||
usleep(10 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user