Commit 2bdd0feb authored by dgozman's avatar dgozman Committed by Commit bot

[inspector] Store interger in context embedder data instead of a string.

This is to improve the performance of common operation of
extracting contextId or contextGroupId out of Context.

BUG=none

Review-Url: https://codereview.chromium.org/2558913004
Cr-Commit-Position: refs/heads/master@{#41657}
parent bb753b6d
......@@ -8983,14 +8983,12 @@ MaybeLocal<String> debug::Script::SourceMappingURL() const {
handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
}
MaybeLocal<String> debug::Script::ContextData() const {
MaybeLocal<Value> debug::Script::ContextData() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
i::HandleScope handle_scope(isolate);
i::Handle<i::Script> script = Utils::OpenHandle(this);
i::Handle<i::Object> value(script->context_data(), isolate);
if (!value->IsString()) return MaybeLocal<String>();
return Utils::ToLocal(
handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
return Utils::ToLocal(handle_scope.CloseAndEscape(value));
}
MaybeLocal<String> debug::Script::Source() const {
......
......@@ -154,7 +154,7 @@ class Script {
MaybeLocal<String> Name() const;
MaybeLocal<String> SourceURL() const;
MaybeLocal<String> SourceMappingURL() const;
MaybeLocal<String> ContextData() const;
MaybeLocal<Value> ContextData() const;
MaybeLocal<String> Source() const;
bool IsWasm() const;
bool GetPossibleBreakpoints(const debug::Location& start,
......
......@@ -143,20 +143,6 @@ DebuggerScript.getCollectionEntries = function(object)
}
}
/**
* @param {string|undefined} contextData
* @return {number}
*/
DebuggerScript._executionContextId = function(contextData)
{
if (!contextData)
return 0;
var match = contextData.match(/^[^,]*,([^,]*),.*$/);
if (!match)
return 0;
return parseInt(match[1], 10) || 0;
}
/**
* @param {!ExecutionState} execState
* @param {!BreakpointInfo} info
......@@ -485,12 +471,9 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror)
function contextId()
{
var mirror = ensureFuncMirror();
// Old V8 do not have context() function on these objects
if (!mirror.context)
return DebuggerScript._executionContextId(mirror.script().value().context_data);
var context = mirror.context();
if (context)
return DebuggerScript._executionContextId(context.data());
if (context && context.data())
return Number(context.data());
return 0;
}
......
......@@ -32,6 +32,7 @@ var JavaScriptCallFrameDetails;
sourceID: function():(number),
line: function():number,
column: function():number,
contextId: function():number,
thisObject: !Object,
evaluate: function(string):*,
restart: function():undefined,
......
......@@ -41,10 +41,12 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
m_humanReadableName(toString16(info.humanReadableName)),
m_auxData(toString16(info.auxData)),
m_reported(false) {
v8::Isolate* isolate = m_inspector->isolate();
info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
v8::Int32::New(isolate, contextId));
m_context.SetWeak(&m_context, &clearContext,
v8::WeakCallbackType::kParameter);
v8::Isolate* isolate = m_inspector->isolate();
v8::Local<v8::Object> global = info.context->Global();
v8::Local<v8::Object> console =
V8Console::createConsole(this, info.hasMemoryOnConsole);
......@@ -65,6 +67,14 @@ InspectedContext::~InspectedContext() {
}
}
// static
int InspectedContext::contextId(v8::Local<v8::Context> context) {
v8::Local<v8::Value> data =
context->GetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex));
if (data.IsEmpty() || !data->IsInt32()) return 0;
return static_cast<int>(data.As<v8::Int32>()->Value());
}
v8::Local<v8::Context> InspectedContext::context() const {
return m_context.Get(isolate());
}
......
......@@ -21,6 +21,8 @@ class InspectedContext {
public:
~InspectedContext();
static int contextId(v8::Local<v8::Context>);
v8::Local<v8::Context> context() const;
int contextId() const { return m_contextId; }
int contextGroupId() const { return m_contextGroupId; }
......
......@@ -1050,10 +1050,17 @@ void V8DebuggerAgentImpl::didParseSource(
if (!success)
script->setSourceMappingURL(findSourceMapURL(scriptSource, false));
int contextId = script->executionContextId();
int contextGroupId = m_inspector->contextGroupId(contextId);
InspectedContext* inspected =
m_inspector->getContext(contextGroupId, contextId);
std::unique_ptr<protocol::DictionaryValue> executionContextAuxData;
if (!script->executionContextAuxData().isEmpty())
if (inspected) {
// Script reused between different groups/sessions can have a stale
// execution context id.
executionContextAuxData = protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(script->executionContextAuxData()));
protocol::StringUtil::parseJSON(inspected->auxData()));
}
bool isLiveEdit = script->isLiveEdit();
bool hasSourceURL = script->hasSourceURL();
String16 scriptId = script->scriptId();
......@@ -1073,17 +1080,15 @@ void V8DebuggerAgentImpl::didParseSource(
if (success)
m_frontend.scriptParsed(
scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(),
scriptRef->endLine(), scriptRef->endColumn(),
scriptRef->executionContextId(), scriptRef->hash(m_isolate),
std::move(executionContextAuxDataParam), isLiveEditParam,
std::move(sourceMapURLParam), hasSourceURLParam);
scriptRef->endLine(), scriptRef->endColumn(), contextId,
scriptRef->hash(m_isolate), std::move(executionContextAuxDataParam),
isLiveEditParam, std::move(sourceMapURLParam), hasSourceURLParam);
else
m_frontend.scriptFailedToParse(
scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(),
scriptRef->endLine(), scriptRef->endColumn(),
scriptRef->executionContextId(), scriptRef->hash(m_isolate),
std::move(executionContextAuxDataParam), std::move(sourceMapURLParam),
hasSourceURLParam);
scriptRef->endLine(), scriptRef->endColumn(), contextId,
scriptRef->hash(m_isolate), std::move(executionContextAuxDataParam),
std::move(sourceMapURLParam), hasSourceURLParam);
if (scriptURL.isEmpty() || !success) return;
......@@ -1150,7 +1155,7 @@ V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::didPause(
if (!exception.IsEmpty()) {
InjectedScript* injectedScript = nullptr;
m_session->findInjectedScript(V8Debugger::contextId(context),
m_session->findInjectedScript(InspectedContext::contextId(context),
injectedScript);
if (injectedScript) {
m_breakReason =
......
......@@ -4,6 +4,7 @@
#include "src/inspector/v8-debugger-script.h"
#include "src/inspector/inspected-context.h"
#include "src/inspector/string-util.h"
namespace v8_inspector {
......@@ -98,20 +99,10 @@ class ActualScript : public V8DebuggerScript {
m_endColumn = m_startColumn;
}
if (script->ContextData().ToLocal(&tmp)) {
String16 contextData = toProtocolString(tmp);
size_t firstComma = contextData.find(",", 0);
size_t secondComma = firstComma != String16::kNotFound
? contextData.find(",", firstComma + 1)
: String16::kNotFound;
if (secondComma != String16::kNotFound) {
String16 executionContextId =
contextData.substring(firstComma + 1, secondComma - firstComma - 1);
bool isOk = false;
m_executionContextId = executionContextId.toInteger(&isOk);
if (!isOk) m_executionContextId = 0;
m_executionContextAuxData = contextData.substring(secondComma + 1);
}
v8::Local<v8::Value> contextData;
if (script->ContextData().ToLocal(&contextData) && contextData->IsInt32()) {
m_executionContextId =
static_cast<int>(contextData.As<v8::Int32>()->Value());
}
if (script->Source().ToLocal(&tmp)) {
......@@ -129,10 +120,6 @@ class ActualScript : public V8DebuggerScript {
bool isLiveEdit() const override { return m_isLiveEdit; }
const String16& executionContextAuxData() const override {
return m_executionContextAuxData;
}
const String16& sourceMappingURL() const override {
return m_sourceMappingURL;
}
......@@ -171,7 +158,6 @@ class ActualScript : public V8DebuggerScript {
String16 m_sourceMappingURL;
v8::Global<v8::String> m_sourceObj;
String16 m_executionContextAuxData;
bool m_isLiveEdit = false;
v8::Global<v8::debug::Script> m_script;
};
......@@ -199,9 +185,6 @@ class WasmVirtualScript : public V8DebuggerScript {
}
const String16& sourceMappingURL() const override { return emptyString(); }
const String16& executionContextAuxData() const override {
return emptyString();
}
bool isLiveEdit() const override { return false; }
void setSourceMappingURL(const String16&) override {}
......
......@@ -62,7 +62,6 @@ class V8DebuggerScript {
int endLine() const { return m_endLine; }
int endColumn() const { return m_endColumn; }
int executionContextId() const { return m_executionContextId; }
virtual const String16& executionContextAuxData() const = 0;
virtual bool isLiveEdit() const = 0;
void setSourceURL(const String16&);
......
......@@ -5,6 +5,7 @@
#include "src/inspector/v8-debugger.h"
#include "src/inspector/debugger-script.h"
#include "src/inspector/inspected-context.h"
#include "src/inspector/protocol/Protocol.h"
#include "src/inspector/script-breakpoint.h"
#include "src/inspector/string-util.h"
......@@ -50,7 +51,6 @@ v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod(
V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector)
: m_isolate(isolate),
m_inspector(inspector),
m_lastContextId(0),
m_enableCount(0),
m_breakpointsActivated(true),
m_runningNestedMessageLoop(false),
......@@ -86,47 +86,20 @@ void V8Debugger::disable() {
bool V8Debugger::enabled() const { return !m_debuggerScript.IsEmpty(); }
// static
int V8Debugger::contextId(v8::Local<v8::Context> context) {
v8::Local<v8::Value> data =
context->GetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex));
if (data.IsEmpty() || !data->IsString()) return 0;
String16 dataString = toProtocolString(data.As<v8::String>());
if (dataString.isEmpty()) return 0;
size_t commaPos = dataString.find(",");
if (commaPos == String16::kNotFound) return 0;
size_t commaPos2 = dataString.find(",", commaPos + 1);
if (commaPos2 == String16::kNotFound) return 0;
return dataString.substring(commaPos + 1, commaPos2 - commaPos - 1)
.toInteger();
}
// static
int V8Debugger::getGroupId(v8::Local<v8::Context> context) {
v8::Local<v8::Value> data =
context->GetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex));
if (data.IsEmpty() || !data->IsString()) return 0;
String16 dataString = toProtocolString(data.As<v8::String>());
if (dataString.isEmpty()) return 0;
size_t commaPos = dataString.find(",");
if (commaPos == String16::kNotFound) return 0;
return dataString.substring(0, commaPos).toInteger();
}
void V8Debugger::getCompiledScripts(
int contextGroupId,
std::vector<std::unique_ptr<V8DebuggerScript>>& result) {
v8::HandleScope scope(m_isolate);
v8::PersistentValueVector<v8::debug::Script> scripts(m_isolate);
v8::debug::GetLoadedScripts(m_isolate, scripts);
String16 contextPrefix = String16::fromInteger(contextGroupId) + ",";
for (size_t i = 0; i < scripts.Size(); ++i) {
v8::Local<v8::debug::Script> script = scripts.Get(i);
if (!script->WasCompiled()) continue;
v8::Local<v8::String> v8ContextData;
if (!script->ContextData().ToLocal(&v8ContextData)) continue;
String16 contextData = toProtocolString(v8ContextData);
if (contextData.find(contextPrefix) != 0) continue;
v8::Local<v8::Value> contextData;
if (!script->ContextData().ToLocal(&contextData) || !contextData->IsInt32())
continue;
int contextId = static_cast<int>(contextData.As<v8::Int32>()->Value());
if (m_inspector->contextGroupId(contextId) != contextGroupId) continue;
result.push_back(V8DebuggerScript::Create(m_isolate, script, false));
}
}
......@@ -483,8 +456,8 @@ void V8Debugger::handleProgramBreak(v8::Local<v8::Context> pausedContext,
// Don't allow nested breaks.
if (m_runningNestedMessageLoop) return;
V8DebuggerAgentImpl* agent =
m_inspector->enabledDebuggerAgentForGroup(getGroupId(pausedContext));
V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup(
m_inspector->contextGroupId(pausedContext));
if (!agent) return;
std::vector<String16> breakpointIds;
......@@ -505,12 +478,12 @@ void V8Debugger::handleProgramBreak(v8::Local<v8::Context> pausedContext,
pausedContext, exception, breakpointIds, isPromiseRejection, isUncaught);
if (result == V8DebuggerAgentImpl::RequestNoSkip) {
m_runningNestedMessageLoop = true;
int groupId = getGroupId(pausedContext);
int groupId = m_inspector->contextGroupId(pausedContext);
DCHECK(groupId);
m_inspector->client()->runMessageLoopOnPause(groupId);
// The agent may have been removed in the nested loop.
agent =
m_inspector->enabledDebuggerAgentForGroup(getGroupId(pausedContext));
agent = m_inspector->enabledDebuggerAgentForGroup(
m_inspector->contextGroupId(pausedContext));
if (agent) agent->didContinue();
m_runningNestedMessageLoop = false;
}
......@@ -566,8 +539,8 @@ void V8Debugger::handleV8DebugEvent(
return;
}
V8DebuggerAgentImpl* agent =
m_inspector->enabledDebuggerAgentForGroup(getGroupId(eventContext));
V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup(
m_inspector->contextGroupId(eventContext));
if (!agent) return;
v8::HandleScope scope(m_isolate);
......@@ -884,23 +857,13 @@ bool V8Debugger::isPaused() { return !m_pausedContext.IsEmpty(); }
std::unique_ptr<V8StackTraceImpl> V8Debugger::createStackTrace(
v8::Local<v8::StackTrace> stackTrace) {
int contextGroupId =
m_isolate->InContext() ? getGroupId(m_isolate->GetCurrentContext()) : 0;
m_isolate->InContext()
? m_inspector->contextGroupId(m_isolate->GetCurrentContext())
: 0;
return V8StackTraceImpl::create(this, contextGroupId, stackTrace,
V8StackTraceImpl::maxCallStackSizeToCapture);
}
int V8Debugger::markContext(const V8ContextInfo& info) {
DCHECK(info.context->GetIsolate() == m_isolate);
int contextId = ++m_lastContextId;
String16 debugData = String16::fromInteger(info.contextGroupId) + "," +
String16::fromInteger(contextId) + "," +
toString16(info.auxData);
v8::Context::Scope contextScope(info.context);
info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
toV8String(m_isolate, debugData));
return contextId;
}
void V8Debugger::setAsyncCallStackDepth(V8DebuggerAgentImpl* agent, int depth) {
if (depth <= 0)
m_maxAsyncCallStackDepthMap.erase(agent);
......@@ -929,7 +892,9 @@ void V8Debugger::asyncTaskScheduled(const String16& taskName, void* task,
if (!m_maxAsyncCallStackDepth) return;
v8::HandleScope scope(m_isolate);
int contextGroupId =
m_isolate->InContext() ? getGroupId(m_isolate->GetCurrentContext()) : 0;
m_isolate->InContext()
? m_inspector->contextGroupId(m_isolate->GetCurrentContext())
: 0;
std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(
this, contextGroupId, V8StackTraceImpl::maxCallStackSizeToCapture,
taskName);
......@@ -996,7 +961,8 @@ std::unique_ptr<V8StackTraceImpl> V8Debugger::captureStackTrace(
if (!m_isolate->InContext()) return nullptr;
v8::HandleScope handles(m_isolate);
int contextGroupId = getGroupId(m_isolate->GetCurrentContext());
int contextGroupId =
m_inspector->contextGroupId(m_isolate->GetCurrentContext());
if (!contextGroupId) return nullptr;
size_t stackSize =
......
......@@ -31,10 +31,6 @@ class V8Debugger {
V8Debugger(v8::Isolate*, V8InspectorImpl*);
~V8Debugger();
static int contextId(v8::Local<v8::Context>);
static int getGroupId(v8::Local<v8::Context>);
int markContext(const V8ContextInfo&);
bool enabled() const;
String16 setBreakpoint(const ScriptBreakpoint&, int* actualLineNumber,
......@@ -142,7 +138,6 @@ class V8Debugger {
v8::Isolate* m_isolate;
V8InspectorImpl* m_inspector;
int m_lastContextId;
int m_enableCount;
bool m_breakpointsActivated;
v8::Global<v8::Object> m_debuggerScript;
......
......@@ -30,6 +30,7 @@
#include "src/inspector/v8-function-call.h"
#include "src/inspector/inspected-context.h"
#include "src/inspector/string-util.h"
#include "src/inspector/v8-debugger.h"
#include "src/inspector/v8-inspector-impl.h"
......@@ -89,7 +90,7 @@ v8::Local<v8::Value> V8FunctionCall::callWithoutExceptionHandling() {
DCHECK(!info[i].IsEmpty());
}
int contextGroupId = V8Debugger::getGroupId(m_context);
int contextGroupId = m_inspector->contextGroupId(m_context);
if (contextGroupId) {
m_inspector->client()->muteMetrics(contextGroupId);
m_inspector->muteExceptions(contextGroupId);
......
......@@ -5,6 +5,7 @@
#include "src/inspector/v8-heap-profiler-agent-impl.h"
#include "src/inspector/injected-script.h"
#include "src/inspector/inspected-context.h"
#include "src/inspector/protocol/Protocol.h"
#include "src/inspector/string-util.h"
#include "src/inspector/v8-debugger.h"
......@@ -55,7 +56,7 @@ class GlobalObjectNameResolver final
const char* GetName(v8::Local<v8::Object> object) override {
InspectedContext* context = m_session->inspector()->getContext(
m_session->contextGroupId(),
V8Debugger::contextId(object->CreationContext()));
InspectedContext::contextId(object->CreationContext()));
if (!context) return "";
String16 name = context->origin();
size_t length = name.length();
......
......@@ -54,10 +54,21 @@ V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate,
m_client(client),
m_debugger(new V8Debugger(isolate, this)),
m_capturingStackTracesCount(0),
m_lastExceptionId(0) {}
m_lastExceptionId(0),
m_lastContextId(0) {}
V8InspectorImpl::~V8InspectorImpl() {}
int V8InspectorImpl::contextGroupId(v8::Local<v8::Context> context) {
return contextGroupId(InspectedContext::contextId(context));
}
int V8InspectorImpl::contextGroupId(int contextId) {
protocol::HashMap<int, int>::iterator it =
m_contextIdToGroupIdMap.find(contextId);
return it != m_contextIdToGroupIdMap.end() ? it->second : 0;
}
V8DebuggerAgentImpl* V8InspectorImpl::enabledDebuggerAgentForGroup(
int contextGroupId) {
V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId);
......@@ -83,7 +94,7 @@ v8::MaybeLocal<v8::Value> V8InspectorImpl::runCompiledScript(
v8::Local<v8::Context> context, v8::Local<v8::Script> script) {
v8::MicrotasksScope microtasksScope(m_isolate,
v8::MicrotasksScope::kRunMicrotasks);
int groupId = V8Debugger::getGroupId(context);
int groupId = contextGroupId(context);
if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
agent->willExecuteScript(script->GetUnboundScript()->GetId());
v8::MaybeLocal<v8::Value> result = script->Run(context);
......@@ -113,7 +124,7 @@ v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction(
v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[],
v8::MicrotasksScope::Type runMicrotasks) {
v8::MicrotasksScope microtasksScope(m_isolate, runMicrotasks);
int groupId = V8Debugger::getGroupId(context);
int groupId = contextGroupId(context);
if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
agent->willExecuteScript(function->ScriptId());
v8::MaybeLocal<v8::Value> result =
......@@ -226,7 +237,9 @@ InspectedContext* V8InspectorImpl::getContext(int groupId,
}
void V8InspectorImpl::contextCreated(const V8ContextInfo& info) {
int contextId = m_debugger->markContext(info);
int contextId = ++m_lastContextId;
InspectedContext* context = new InspectedContext(this, info, contextId);
m_contextIdToGroupIdMap[contextId] = info.contextGroupId;
ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId);
if (contextIt == m_contexts.end())
......@@ -235,11 +248,9 @@ void V8InspectorImpl::contextCreated(const V8ContextInfo& info) {
info.contextGroupId,
std::unique_ptr<ContextByIdMap>(new ContextByIdMap())))
.first;
const auto& contextById = contextIt->second;
DCHECK(contextById->find(contextId) == contextById->cend());
InspectedContext* context = new InspectedContext(this, info, contextId);
(*contextById)[contextId].reset(context);
SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId);
if (sessionIt != m_sessions.end())
......@@ -247,22 +258,22 @@ void V8InspectorImpl::contextCreated(const V8ContextInfo& info) {
}
void V8InspectorImpl::contextDestroyed(v8::Local<v8::Context> context) {
int contextId = V8Debugger::contextId(context);
int contextGroupId = V8Debugger::getGroupId(context);
int contextId = InspectedContext::contextId(context);
int groupId = contextGroupId(context);
m_contextIdToGroupIdMap.erase(contextId);
ConsoleStorageMap::iterator storageIt =
m_consoleStorageMap.find(contextGroupId);
ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(groupId);
if (storageIt != m_consoleStorageMap.end())
storageIt->second->contextDestroyed(contextId);
InspectedContext* inspectedContext = getContext(contextGroupId, contextId);
InspectedContext* inspectedContext = getContext(groupId, contextId);
if (!inspectedContext) return;
SessionMap::iterator iter = m_sessions.find(contextGroupId);
SessionMap::iterator iter = m_sessions.find(groupId);
if (iter != m_sessions.end())
iter->second->runtimeAgent()->reportExecutionContextDestroyed(
inspectedContext);
discardInspectedContext(contextGroupId, contextId);
discardInspectedContext(groupId, contextId);
}
void V8InspectorImpl::resetContextGroup(int contextGroupId) {
......@@ -277,14 +288,16 @@ void V8InspectorImpl::resetContextGroup(int contextGroupId) {
void V8InspectorImpl::willExecuteScript(v8::Local<v8::Context> context,
int scriptId) {
if (V8DebuggerAgentImpl* agent =
enabledDebuggerAgentForGroup(V8Debugger::getGroupId(context)))
enabledDebuggerAgentForGroup(contextGroupId(context))) {
agent->willExecuteScript(scriptId);
}
}
void V8InspectorImpl::didExecuteScript(v8::Local<v8::Context> context) {
if (V8DebuggerAgentImpl* agent =
enabledDebuggerAgentForGroup(V8Debugger::getGroupId(context)))
enabledDebuggerAgentForGroup(contextGroupId(context))) {
agent->didExecuteScript();
}
}
void V8InspectorImpl::idleStarted() {
......@@ -304,8 +317,8 @@ unsigned V8InspectorImpl::exceptionThrown(
v8::Local<v8::Value> exception, const StringView& detailedMessage,
const StringView& url, unsigned lineNumber, unsigned columnNumber,
std::unique_ptr<V8StackTrace> stackTrace, int scriptId) {
int contextGroupId = V8Debugger::getGroupId(context);
if (!contextGroupId || m_muteExceptionsMap[contextGroupId]) return 0;
int groupId = contextGroupId(context);
if (!groupId || m_muteExceptionsMap[groupId]) return 0;
std::unique_ptr<V8StackTraceImpl> stackTraceImpl(
static_cast<V8StackTraceImpl*>(stackTrace.release()));
unsigned exceptionId = nextExceptionId();
......@@ -314,23 +327,21 @@ unsigned V8InspectorImpl::exceptionThrown(
m_client->currentTimeMS(), toString16(detailedMessage),
toString16(url), lineNumber, columnNumber, std::move(stackTraceImpl),
scriptId, m_isolate, toString16(message),
V8Debugger::contextId(context), exception, exceptionId);
ensureConsoleMessageStorage(contextGroupId)
->addMessage(std::move(consoleMessage));
InspectedContext::contextId(context), exception, exceptionId);
ensureConsoleMessageStorage(groupId)->addMessage(std::move(consoleMessage));
return exceptionId;
}
void V8InspectorImpl::exceptionRevoked(v8::Local<v8::Context> context,
unsigned exceptionId,
const StringView& message) {
int contextGroupId = V8Debugger::getGroupId(context);
if (!contextGroupId) return;
int groupId = contextGroupId(context);
if (!groupId) return;
std::unique_ptr<V8ConsoleMessage> consoleMessage =
V8ConsoleMessage::createForRevokedException(
m_client->currentTimeMS(), toString16(message), exceptionId);
ensureConsoleMessageStorage(contextGroupId)
->addMessage(std::move(consoleMessage));
ensureConsoleMessageStorage(groupId)->addMessage(std::move(consoleMessage));
}
std::unique_ptr<V8StackTrace> V8InspectorImpl::captureStackTrace(
......
......@@ -58,6 +58,8 @@ class V8InspectorImpl : public V8Inspector {
v8::Isolate* isolate() const { return m_isolate; }
V8InspectorClient* client() { return m_client; }
V8Debugger* debugger() { return m_debugger.get(); }
int contextGroupId(v8::Local<v8::Context>);
int contextGroupId(int contextId);
v8::MaybeLocal<v8::Value> runCompiledScript(v8::Local<v8::Context>,
v8::Local<v8::Script>);
......@@ -136,6 +138,7 @@ class V8InspectorImpl : public V8Inspector {
v8::Global<v8::Context> m_regexContext;
int m_capturingStackTracesCount;
unsigned m_lastExceptionId;
int m_lastContextId;
using MuteExceptionsMap = protocol::HashMap<int, int>;
MuteExceptionsMap m_muteExceptionsMap;
......@@ -151,6 +154,8 @@ class V8InspectorImpl : public V8Inspector {
protocol::HashMap<int, std::unique_ptr<V8ConsoleMessageStorage>>;
ConsoleStorageMap m_consoleStorageMap;
protocol::HashMap<int, int> m_contextIdToGroupIdMap;
DISALLOW_COPY_AND_ASSIGN(V8InspectorImpl);
};
......
......@@ -295,7 +295,7 @@ V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context,
const String16& groupName,
bool generatePreview) {
InjectedScript* injectedScript = nullptr;
findInjectedScript(V8Debugger::contextId(context), injectedScript);
findInjectedScript(InspectedContext::contextId(context), injectedScript);
if (!injectedScript) return nullptr;
std::unique_ptr<protocol::Runtime::RemoteObject> result;
injectedScript->wrapObject(value, groupName, false, generatePreview, &result);
......@@ -307,7 +307,7 @@ V8InspectorSessionImpl::wrapTable(v8::Local<v8::Context> context,
v8::Local<v8::Value> table,
v8::Local<v8::Value> columns) {
InjectedScript* injectedScript = nullptr;
findInjectedScript(V8Debugger::contextId(context), injectedScript);
findInjectedScript(InspectedContext::contextId(context), injectedScript);
if (!injectedScript) return nullptr;
return injectedScript->wrapTable(table, columns);
}
......
......@@ -241,7 +241,7 @@ Response ensureContext(V8InspectorImpl* inspector, int contextGroupId,
inspector->client()->ensureDefaultContextInGroup(contextGroupId);
if (defaultContext.IsEmpty())
return Response::Error("Cannot find default execution context");
*contextId = V8Debugger::contextId(defaultContext);
*contextId = InspectedContext::contextId(defaultContext);
}
return Response::OK();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment