X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/40a37d088818fc2fbeba2ef850dbcaaf294befbf..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/inspector/JSGlobalObjectInspectorController.cpp diff --git a/inspector/JSGlobalObjectInspectorController.cpp b/inspector/JSGlobalObjectInspectorController.cpp index ebdd180..11d86ed 100644 --- a/inspector/JSGlobalObjectInspectorController.cpp +++ b/inspector/JSGlobalObjectInspectorController.cpp @@ -26,27 +26,30 @@ #include "config.h" #include "JSGlobalObjectInspectorController.h" -#if ENABLE(INSPECTOR) - #include "Completion.h" +#include "ConsoleMessage.h" #include "ErrorHandlingScope.h" +#include "Exception.h" #include "InjectedScriptHost.h" #include "InjectedScriptManager.h" #include "InspectorAgent.h" #include "InspectorBackendDispatcher.h" #include "InspectorFrontendChannel.h" -#include "JSConsoleClient.h" #include "JSGlobalObject.h" #include "JSGlobalObjectConsoleAgent.h" +#include "JSGlobalObjectConsoleClient.h" #include "JSGlobalObjectDebuggerAgent.h" -#include "JSGlobalObjectProfilerAgent.h" #include "JSGlobalObjectRuntimeAgent.h" #include "ScriptArguments.h" #include "ScriptCallStack.h" #include "ScriptCallStackFactory.h" +#include + #include +#if OS(DARWIN) || (OS(LINUX) && !PLATFORM(GTK)) #include #include +#endif #if ENABLE(REMOTE_INSPECTOR) #include "JSGlobalObjectDebuggable.h" @@ -60,24 +63,32 @@ namespace Inspector { JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSGlobalObject& globalObject) : m_globalObject(globalObject) , m_injectedScriptManager(std::make_unique(*this, InjectedScriptHost::create())) - , m_inspectorFrontendChannel(nullptr) + , m_frontendChannel(nullptr) + , m_executionStopwatch(Stopwatch::create()) , m_includeNativeCallStackWithExceptions(true) + , m_isAutomaticInspection(false) +#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) + , m_augmentingClient(nullptr) +#endif { + auto inspectorAgent = std::make_unique(*this); auto runtimeAgent = std::make_unique(m_injectedScriptManager.get(), m_globalObject); auto consoleAgent = std::make_unique(m_injectedScriptManager.get()); auto debuggerAgent = std::make_unique(m_injectedScriptManager.get(), m_globalObject, consoleAgent.get()); - auto profilerAgent = std::make_unique(m_globalObject); + m_inspectorAgent = inspectorAgent.get(); + m_debuggerAgent = debuggerAgent.get(); m_consoleAgent = consoleAgent.get(); - m_consoleClient = std::make_unique(m_consoleAgent, profilerAgent.get()); + m_consoleClient = std::make_unique(m_consoleAgent); runtimeAgent->setScriptDebugServer(&debuggerAgent->scriptDebugServer()); - profilerAgent->setScriptDebugServer(&debuggerAgent->scriptDebugServer()); - m_agents.append(std::make_unique()); + m_agents.append(WTF::move(inspectorAgent)); m_agents.append(WTF::move(runtimeAgent)); m_agents.append(WTF::move(consoleAgent)); m_agents.append(WTF::move(debuggerAgent)); + + m_executionStopwatch->start(); } JSGlobalObjectInspectorController::~JSGlobalObjectInspectorController() @@ -87,42 +98,69 @@ JSGlobalObjectInspectorController::~JSGlobalObjectInspectorController() void JSGlobalObjectInspectorController::globalObjectDestroyed() { - disconnectFrontend(InspectorDisconnectReason::InspectedTargetDestroyed); + disconnectFrontend(DisconnectReason::InspectedTargetDestroyed); m_injectedScriptManager->disconnect(); } -void JSGlobalObjectInspectorController::connectFrontend(InspectorFrontendChannel* frontendChannel) +void JSGlobalObjectInspectorController::connectFrontend(FrontendChannel* frontendChannel, bool isAutomaticInspection) { - ASSERT(!m_inspectorFrontendChannel); - ASSERT(!m_inspectorBackendDispatcher); + ASSERT(!m_frontendChannel); + ASSERT(!m_backendDispatcher); - m_inspectorFrontendChannel = frontendChannel; - m_inspectorBackendDispatcher = InspectorBackendDispatcher::create(frontendChannel); + m_isAutomaticInspection = isAutomaticInspection; - m_agents.didCreateFrontendAndBackend(frontendChannel, m_inspectorBackendDispatcher.get()); + m_frontendChannel = frontendChannel; + m_backendDispatcher = BackendDispatcher::create(frontendChannel); + + m_agents.didCreateFrontendAndBackend(frontendChannel, m_backendDispatcher.get()); + +#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) + m_inspectorAgent->activateExtraDomains(m_agents.extraDomains()); + + if (m_augmentingClient) + m_augmentingClient->inspectorConnected(); +#endif } -void JSGlobalObjectInspectorController::disconnectFrontend(InspectorDisconnectReason reason) +void JSGlobalObjectInspectorController::disconnectFrontend(DisconnectReason reason) { - if (!m_inspectorFrontendChannel) + if (!m_frontendChannel) return; m_agents.willDestroyFrontendAndBackend(reason); - m_inspectorBackendDispatcher->clearFrontend(); - m_inspectorBackendDispatcher.clear(); - m_inspectorFrontendChannel = nullptr; + m_backendDispatcher->clearFrontend(); + m_backendDispatcher = nullptr; + m_frontendChannel = nullptr; + + m_isAutomaticInspection = false; + +#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) + if (m_augmentingClient) + m_augmentingClient->inspectorDisconnected(); +#endif } void JSGlobalObjectInspectorController::dispatchMessageFromFrontend(const String& message) { - if (m_inspectorBackendDispatcher) - m_inspectorBackendDispatcher->dispatch(message); + if (m_backendDispatcher) + m_backendDispatcher->dispatch(message); +} + +void JSGlobalObjectInspectorController::pause() +{ + if (!m_frontendChannel) + return; + + ErrorString dummyError; + m_debuggerAgent->enable(dummyError); + m_debuggerAgent->pause(dummyError); } void JSGlobalObjectInspectorController::appendAPIBacktrace(ScriptCallStack* callStack) { +#if OS(DARWIN) || (OS(LINUX) && !PLATFORM(GTK)) static const int framesToShow = 31; static const int framesToSkip = 3; // WTFGetBacktrace, appendAPIBacktrace, reportAPIException. @@ -146,9 +184,12 @@ void JSGlobalObjectInspectorController::appendAPIBacktrace(ScriptCallStack* call callStack->append(ScriptCallFrame(ASCIILiteral("?"), ASCIILiteral("[native code]"), 0, 0)); free(cxaDemangled); } +#else + UNUSED_PARAM(callStack); +#endif } -void JSGlobalObjectInspectorController::reportAPIException(ExecState* exec, JSValue exception) +void JSGlobalObjectInspectorController::reportAPIException(ExecState* exec, Exception* exception) { if (isTerminatedExecutionException(exception)) return; @@ -161,10 +202,10 @@ void JSGlobalObjectInspectorController::reportAPIException(ExecState* exec, JSVa // FIXME: Web Inspector: Should not evaluate JavaScript handling exceptions // If this is a custom exception object, call toString on it to try and get a nice string representation for the exception. - String errorMessage = exception.toString(exec)->value(exec); + String errorMessage = exception->value().toString(exec)->value(exec); exec->clearException(); - if (JSConsoleClient::logToSystemConsole()) { + if (JSGlobalObjectConsoleClient::logToSystemConsole()) { if (callStack->size()) { const ScriptCallFrame& callFrame = callStack->at(0); ConsoleClient::printConsoleMessage(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, callFrame.sourceURL(), callFrame.lineNumber(), callFrame.columnNumber()); @@ -172,7 +213,7 @@ void JSGlobalObjectInspectorController::reportAPIException(ExecState* exec, JSVa ConsoleClient::printConsoleMessage(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, String(), 0, 0); } - m_consoleAgent->addMessageToConsole(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, callStack); + m_consoleAgent->addMessageToConsole(std::make_unique(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, callStack)); } ConsoleClient* JSGlobalObjectInspectorController::consoleClient() const @@ -183,7 +224,7 @@ ConsoleClient* JSGlobalObjectInspectorController::consoleClient() const bool JSGlobalObjectInspectorController::developerExtrasEnabled() const { #if ENABLE(REMOTE_INSPECTOR) - if (!RemoteInspector::shared().enabled()) + if (!RemoteInspector::singleton().enabled()) return false; if (!m_globalObject.inspectorDebuggable().remoteDebuggingAllowed()) @@ -203,6 +244,33 @@ InspectorEvaluateHandler JSGlobalObjectInspectorController::evaluateHandler() co return JSC::evaluate; } +void JSGlobalObjectInspectorController::frontendInitialized() +{ +#if ENABLE(REMOTE_INSPECTOR) + if (m_isAutomaticInspection) + m_globalObject.inspectorDebuggable().unpauseForInitializedInspector(); +#endif +} + +Ref JSGlobalObjectInspectorController::executionStopwatch() +{ + return m_executionStopwatch.copyRef(); +} + +#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) +void JSGlobalObjectInspectorController::appendExtraAgent(std::unique_ptr agent) +{ + String domainName = agent->domainName(); + + if (m_frontendChannel) + agent->didCreateFrontendAndBackend(m_frontendChannel, m_backendDispatcher.get()); + + m_agents.appendExtraAgent(WTF::move(agent)); + + if (m_frontendChannel) + m_inspectorAgent->activateExtraDomain(domainName); +} +#endif + } // namespace Inspector -#endif // ENABLE(INSPECTOR)