| Index: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerImpl.cpp
|
| diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerImpl.cpp
|
| index 387bc4b86693a1bf760088886c40ecfb7fc43dd3..7841ce4d6a78563d0b19ba03498dc9a742dae51b 100644
|
| --- a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerImpl.cpp
|
| +++ b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerImpl.cpp
|
| @@ -36,6 +36,8 @@
|
| #include "platform/v8_inspector/InspectedContext.h"
|
| #include "platform/v8_inspector/ScriptBreakpoint.h"
|
| #include "platform/v8_inspector/V8Compat.h"
|
| +#include "platform/v8_inspector/V8ConsoleAgentImpl.h"
|
| +#include "platform/v8_inspector/V8ConsoleMessage.h"
|
| #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
|
| #include "platform/v8_inspector/V8InspectorSessionImpl.h"
|
| #include "platform/v8_inspector/V8RuntimeAgentImpl.h"
|
| @@ -77,6 +79,9 @@ std::unique_ptr<V8Debugger> V8Debugger::create(v8::Isolate* isolate, V8DebuggerC
|
| V8DebuggerImpl::V8DebuggerImpl(v8::Isolate* isolate, V8DebuggerClient* client)
|
| : m_isolate(isolate)
|
| , m_client(client)
|
| + , m_capturingStackTracesCount(0)
|
| + , m_muteConsoleCount(0)
|
| + , m_lastConsoleMessageId(0)
|
| , m_enabledAgentsCount(0)
|
| , m_breakpointsActivated(true)
|
| , m_runningNestedMessageLoop(false)
|
| @@ -110,7 +115,7 @@ bool V8DebuggerImpl::enabled() const
|
| return !m_debuggerScript.IsEmpty();
|
| }
|
|
|
| -int V8Debugger::contextId(v8::Local<v8::Context> context)
|
| +int V8DebuggerImpl::contextId(v8::Local<v8::Context> context)
|
| {
|
| v8::Local<v8::Value> data = context->GetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex));
|
| if (data.IsEmpty() || !data->IsString())
|
| @@ -725,10 +730,30 @@ v8::Local<v8::Script> V8DebuggerImpl::compileInternalScript(v8::Local<v8::Contex
|
| return script;
|
| }
|
|
|
| +void V8DebuggerImpl::enableStackCapturingIfNeeded()
|
| +{
|
| + if (!m_capturingStackTracesCount)
|
| + V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions(m_isolate, true);
|
| + ++m_capturingStackTracesCount;
|
| +}
|
| +
|
| +void V8DebuggerImpl::disableStackCapturingIfNeeded()
|
| +{
|
| + if (!(--m_capturingStackTracesCount))
|
| + V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions(m_isolate, false);
|
| +}
|
| +
|
| +V8ConsoleMessageStorage* V8DebuggerImpl::ensureConsoleMessageStorage(int contextGroupId)
|
| +{
|
| + if (!m_consoleStorageMap.contains(contextGroupId))
|
| + m_consoleStorageMap.set(contextGroupId, wrapUnique(new V8ConsoleMessageStorage(this, contextGroupId)));
|
| + return m_consoleStorageMap.get(contextGroupId);
|
| +}
|
| +
|
| std::unique_ptr<V8StackTrace> V8DebuggerImpl::createStackTrace(v8::Local<v8::StackTrace> stackTrace)
|
| {
|
| V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(m_isolate->GetCurrentContext());
|
| - return V8StackTraceImpl::create(agent, stackTrace, V8StackTrace::maxCallStackSizeToCapture);
|
| + return V8StackTraceImpl::create(agent, stackTrace, V8StackTraceImpl::maxCallStackSizeToCapture);
|
| }
|
|
|
| std::unique_ptr<V8InspectorSession> V8DebuggerImpl::connect(int contextGroupId, protocol::FrontendChannel* channel, V8InspectorSessionClient* client, const String16* state)
|
| @@ -769,8 +794,11 @@ void V8DebuggerImpl::contextCreated(const V8ContextInfo& info)
|
|
|
| void V8DebuggerImpl::contextDestroyed(v8::Local<v8::Context> context)
|
| {
|
| - int contextId = V8Debugger::contextId(context);
|
| + int contextId = V8DebuggerImpl::contextId(context);
|
| int contextGroupId = getGroupId(context);
|
| + if (m_consoleStorageMap.contains(contextGroupId))
|
| + m_consoleStorageMap.get(contextGroupId)->contextDestroyed(contextId);
|
| +
|
| if (!m_contexts.contains(contextGroupId) || !m_contexts.get(contextGroupId)->contains(contextId))
|
| return;
|
|
|
| @@ -785,6 +813,7 @@ void V8DebuggerImpl::contextDestroyed(v8::Local<v8::Context> context)
|
|
|
| void V8DebuggerImpl::resetContextGroup(int contextGroupId)
|
| {
|
| + m_consoleStorageMap.remove(contextGroupId);
|
| if (V8InspectorSessionImpl* session = m_sessions.get(contextGroupId))
|
| session->reset();
|
| m_contexts.remove(contextGroupId);
|
| @@ -812,10 +841,94 @@ void V8DebuggerImpl::idleFinished()
|
| m_isolate->GetCpuProfiler()->SetIdle(false);
|
| }
|
|
|
| -std::unique_ptr<V8StackTrace> V8DebuggerImpl::captureStackTrace(size_t maxStackSize)
|
| +bool V8DebuggerImpl::addConsoleMessage(int contextGroupId, MessageSource source, MessageLevel level, const String16& message, const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId, const String16& requestIdentifier)
|
| {
|
| - V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(m_isolate->GetCurrentContext());
|
| - return V8StackTraceImpl::capture(agent, maxStackSize);
|
| + if (m_muteConsoleCount)
|
| + return false;
|
| + ensureConsoleMessageStorage(contextGroupId)->addMessage(wrapUnique(new V8ConsoleMessage(m_client->currentTimeMS(), source, level, message, url, lineNumber, columnNumber, std::move(stackTrace), scriptId, requestIdentifier)));
|
| + return true;
|
| +}
|
| +
|
| +void V8DebuggerImpl::logToConsole(v8::Local<v8::Context> context, const String16& message, protocol::Vector<v8::Local<v8::Value>>* arguments)
|
| +{
|
| + int contextGroupId = getGroupId(context);
|
| + if (!contextGroupId || !m_contexts.contains(contextGroupId))
|
| + return;
|
| + InspectedContext* inspectedContext = m_contexts.get(contextGroupId)->get(contextId(context));
|
| + if (!inspectedContext)
|
| + return;
|
| + ensureConsoleMessageStorage(contextGroupId)->addMessage(V8ConsoleMessage::createForConsoleAPI(m_client->currentTimeMS(), LogMessageType, LogMessageLevel, message, arguments, captureStackTrace(false), inspectedContext));
|
| +}
|
| +
|
| +unsigned V8DebuggerImpl::promiseRejected(v8::Local<v8::Context> context, const String16& errorMessage, v8::Local<v8::Value> reason, const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId)
|
| +{
|
| + if (m_muteConsoleCount)
|
| + return 0;
|
| + int contextGroupId = getGroupId(context);
|
| + if (!contextGroupId)
|
| + return 0;
|
| +
|
| + const String16 defaultMessage = "Uncaught (in promise)";
|
| + String16 message = errorMessage;
|
| + if (message.isEmpty())
|
| + message = defaultMessage;
|
| + else if (message.startWith("Uncaught "))
|
| + message = message.substring(0, 8) + " (in promise)" + message.substring(8);
|
| +
|
| + m_client->messageAddedToConsole(contextGroupId, JSMessageSource, ErrorMessageLevel, message, url, lineNumber, columnNumber, stackTrace.get());
|
| + std::unique_ptr<V8ConsoleMessage> consoleMessage = wrapUnique(new V8ConsoleMessage(m_client->currentTimeMS(), JSMessageSource, ErrorMessageLevel, message, url, lineNumber, columnNumber, std::move(stackTrace), scriptId, String16()));
|
| + unsigned id = ++m_lastConsoleMessageId;
|
| + consoleMessage->assignId(id);
|
| +
|
| + protocol::Vector<v8::Local<v8::Value>> arguments;
|
| + arguments.append(toV8String(m_isolate, defaultMessage));
|
| + arguments.append(reason);
|
| + consoleMessage->addArguments(m_isolate, contextId(context), &arguments);
|
| +
|
| + ensureConsoleMessageStorage(contextGroupId)->addMessage(std::move(consoleMessage));
|
| + return id;
|
| +}
|
| +
|
| +void V8DebuggerImpl::promiseRejectionRevoked(v8::Local<v8::Context> context, unsigned promiseRejectionId)
|
| +{
|
| + if (m_muteConsoleCount)
|
| + return;
|
| + int contextGroupId = getGroupId(context);
|
| + if (!contextGroupId)
|
| + return;
|
| +
|
| + const String16 message = "Handler added to rejected promise";
|
| + m_client->messageAddedToConsole(contextGroupId, JSMessageSource, RevokedErrorMessageLevel, message, String16(), 0, 0, nullptr);
|
| + std::unique_ptr<V8ConsoleMessage> consoleMessage = wrapUnique(new V8ConsoleMessage(m_client->currentTimeMS(), JSMessageSource, RevokedErrorMessageLevel, message, String16(), 0, 0, nullptr, 0, String16()));
|
| + consoleMessage->assignRelatedId(promiseRejectionId);
|
| + ensureConsoleMessageStorage(contextGroupId)->addMessage(std::move(consoleMessage));
|
| +}
|
| +
|
| +protocol::Vector<unsigned> V8DebuggerImpl::consoleMessageArgumentCounts(int contextGroupId)
|
| +{
|
| + if (!m_consoleStorageMap.contains(contextGroupId))
|
| + return protocol::Vector<unsigned>();
|
| + return m_consoleStorageMap.get(contextGroupId)->consoleMessageArgumentCounts();
|
| +}
|
| +
|
| +std::unique_ptr<V8StackTrace> V8DebuggerImpl::captureStackTrace(bool fullStack)
|
| +{
|
| + if (!m_isolate->InContext())
|
| + return nullptr;
|
| +
|
| + v8::HandleScope handles(m_isolate);
|
| + v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
|
| + int contextGroupId = getGroupId(context);
|
| + if (!contextGroupId)
|
| + return nullptr;
|
| +
|
| + V8InspectorSessionImpl* session = m_sessions.get(contextGroupId);
|
| + size_t stackSize = fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1;
|
| + if (session && session->consoleAgent()->enabled())
|
| + stackSize = V8StackTraceImpl::maxCallStackSizeToCapture;
|
| +
|
| + V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(context);
|
| + return V8StackTraceImpl::capture(agent, stackSize);
|
| }
|
|
|
| v8::Local<v8::Context> V8DebuggerImpl::regexContext()
|
|
|