summaryrefslogtreecommitdiff
path: root/deps/v8/src/inspector/v8-console.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/inspector/v8-console.cc')
-rw-r--r--deps/v8/src/inspector/v8-console.cc301
1 files changed, 176 insertions, 125 deletions
diff --git a/deps/v8/src/inspector/v8-console.cc b/deps/v8/src/inspector/v8-console.cc
index 0d3c03a4da..4d71adfd47 100644
--- a/deps/v8/src/inspector/v8-console.cc
+++ b/deps/v8/src/inspector/v8-console.cc
@@ -23,11 +23,20 @@ namespace v8_inspector {
namespace {
+String16 consoleContextToString(
+ const v8::debug::ConsoleContext& consoleContext) {
+ if (consoleContext.id() == 0) return String16();
+ return toProtocolString(consoleContext.name()) + "#" +
+ String16::fromInteger(consoleContext.id());
+}
+
class ConsoleHelper {
public:
ConsoleHelper(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext,
V8InspectorImpl* inspector)
: m_info(info),
+ m_consoleContext(consoleContext),
m_isolate(inspector->isolate()),
m_context(m_isolate->GetCurrentContext()),
m_inspector(inspector),
@@ -37,10 +46,14 @@ class ConsoleHelper {
int contextId() const { return m_contextId; }
int groupId() const { return m_groupId; }
- InjectedScript* injectedScript() {
+ InjectedScript* injectedScript(int sessionId) {
InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId);
if (!context) return nullptr;
- return context->getInjectedScript();
+ return context->getInjectedScript(sessionId);
+ }
+
+ V8InspectorSessionImpl* session(int sessionId) {
+ return m_inspector->sessionById(m_groupId, sessionId);
}
V8ConsoleMessageStorage* consoleMessageStorage() {
@@ -75,6 +88,7 @@ class ConsoleHelper {
V8ConsoleMessage::createForConsoleAPI(
m_context, m_contextId, m_groupId, m_inspector,
m_inspector->client()->currentTimeMS(), type, arguments,
+ consoleContextToString(m_consoleContext),
m_inspector->debugger()->captureStackTrace(false));
consoleMessageStorage()->addMessage(std::move(message));
}
@@ -98,6 +112,7 @@ class ConsoleHelper {
String16 firstArgToString(const String16& defaultValue) {
if (m_info.Length() < 1) return defaultValue;
v8::Local<v8::String> titleValue;
+ v8::TryCatch tryCatch(m_context->GetIsolate());
if (m_info[0]->IsObject()) {
if (!m_info[0].As<v8::Object>()->ObjectProtoToString(m_context).ToLocal(
&titleValue))
@@ -124,28 +139,13 @@ class ConsoleHelper {
return func;
}
- V8ProfilerAgentImpl* profilerAgent() {
- if (V8InspectorSessionImpl* session = currentSession()) {
- if (session && session->profilerAgent()->enabled())
- return session->profilerAgent();
- }
- return nullptr;
- }
-
- V8DebuggerAgentImpl* debuggerAgent() {
- if (V8InspectorSessionImpl* session = currentSession()) {
- if (session && session->debuggerAgent()->enabled())
- return session->debuggerAgent();
- }
- return nullptr;
- }
-
- V8InspectorSessionImpl* currentSession() {
- return m_inspector->sessionForContextGroup(m_groupId);
+ void forEachSession(std::function<void(V8InspectorSessionImpl*)> callback) {
+ m_inspector->forEachSession(m_groupId, callback);
}
private:
const v8::debug::ConsoleCallArguments& m_info;
+ const v8::debug::ConsoleContext& m_consoleContext;
v8::Isolate* m_isolate;
v8::Local<v8::Context> m_context;
V8InspectorImpl* m_inspector = nullptr;
@@ -190,72 +190,95 @@ void createBoundFunctionProperty(v8::Local<v8::Context> context,
V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {}
-void V8Console::Debug(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug);
+void V8Console::Debug(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
+ .reportCall(ConsoleAPIType::kDebug);
}
-void V8Console::Error(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError);
+void V8Console::Error(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
+ .reportCall(ConsoleAPIType::kError);
}
-void V8Console::Info(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo);
+void V8Console::Info(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
+ .reportCall(ConsoleAPIType::kInfo);
}
-void V8Console::Log(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog);
+void V8Console::Log(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
+ .reportCall(ConsoleAPIType::kLog);
}
-void V8Console::Warn(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning);
+void V8Console::Warn(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
+ .reportCall(ConsoleAPIType::kWarning);
}
-void V8Console::Dir(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir);
+void V8Console::Dir(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
+ .reportCall(ConsoleAPIType::kDir);
}
-void V8Console::DirXml(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML);
+void V8Console::DirXml(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
+ .reportCall(ConsoleAPIType::kDirXML);
}
-void V8Console::Table(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable);
+void V8Console::Table(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
+ .reportCall(ConsoleAPIType::kTable);
}
-void V8Console::Trace(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector)
+void V8Console::Trace(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kTrace,
String16("console.trace"));
}
-void V8Console::Group(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector)
+void V8Console::Group(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup,
String16("console.group"));
}
-void V8Console::GroupCollapsed(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector)
+void V8Console::GroupCollapsed(
+ const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed,
String16("console.groupCollapsed"));
}
-void V8Console::GroupEnd(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector)
+void V8Console::GroupEnd(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup,
String16("console.groupEnd"));
}
-void V8Console::Clear(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper helper(info, m_inspector);
+void V8Console::Clear(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper helper(info, consoleContext, m_inspector);
if (!helper.groupId()) return;
m_inspector->client()->consoleClear(helper.groupId());
helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear,
String16("console.clear"));
}
-void V8Console::Count(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper helper(info, m_inspector);
+void V8Console::Count(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper helper(info, consoleContext, m_inspector);
String16 title = helper.firstArgToString(String16());
String16 identifier;
if (title.isEmpty()) {
@@ -268,6 +291,7 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info) {
} else {
identifier = title + "@";
}
+ identifier = consoleContextToString(consoleContext) + "@" + identifier;
int count =
helper.consoleMessageStorage()->count(helper.contextId(), identifier);
@@ -277,8 +301,9 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info) {
title.isEmpty() ? countString : (title + ": " + countString));
}
-void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper helper(info, m_inspector);
+void V8Console::Assert(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper helper(info, consoleContext, m_inspector);
DCHECK(!helper.firstArgToBoolean(false));
std::vector<v8::Local<v8::Value>> arguments;
@@ -287,82 +312,96 @@ void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) {
arguments.push_back(
toV8String(m_inspector->isolate(), String16("console.assert")));
helper.reportCall(ConsoleAPIType::kAssert, arguments);
-
- if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent())
- debuggerAgent->breakProgramOnException(
- protocol::Debugger::Paused::ReasonEnum::Assert, nullptr);
+ m_inspector->debugger()->breakProgramOnAssert(helper.groupId());
}
-void V8Console::MarkTimeline(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector)
+void V8Console::MarkTimeline(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
.reportDeprecatedCall("V8Console#markTimelineDeprecated",
"'console.markTimeline' is "
"deprecated. Please use "
"'console.timeStamp' instead.");
- TimeStamp(info);
+ TimeStamp(info, consoleContext);
}
-void V8Console::Profile(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper helper(info, m_inspector);
- if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
- profilerAgent->consoleProfile(helper.firstArgToString(String16()));
+void V8Console::Profile(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper helper(info, consoleContext, m_inspector);
+ helper.forEachSession([&helper](V8InspectorSessionImpl* session) {
+ session->profilerAgent()->consoleProfile(
+ helper.firstArgToString(String16()));
+ });
}
-void V8Console::ProfileEnd(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper helper(info, m_inspector);
- if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
- profilerAgent->consoleProfileEnd(helper.firstArgToString(String16()));
+void V8Console::ProfileEnd(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper helper(info, consoleContext, m_inspector);
+ helper.forEachSession([&helper](V8InspectorSessionImpl* session) {
+ session->profilerAgent()->consoleProfileEnd(
+ helper.firstArgToString(String16()));
+ });
}
static void timeFunction(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext,
bool timelinePrefix, V8InspectorImpl* inspector) {
- ConsoleHelper helper(info, inspector);
+ ConsoleHelper helper(info, consoleContext, inspector);
String16 protocolTitle = helper.firstArgToString("default");
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
inspector->client()->consoleTime(toStringView(protocolTitle));
- helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle);
+ helper.consoleMessageStorage()->time(
+ helper.contextId(),
+ protocolTitle + "@" + consoleContextToString(consoleContext));
}
static void timeEndFunction(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext,
bool timelinePrefix, V8InspectorImpl* inspector) {
- ConsoleHelper helper(info, inspector);
+ ConsoleHelper helper(info, consoleContext, inspector);
String16 protocolTitle = helper.firstArgToString("default");
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
- double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(),
- protocolTitle);
+ double elapsed = helper.consoleMessageStorage()->timeEnd(
+ helper.contextId(),
+ protocolTitle + "@" + consoleContextToString(consoleContext));
String16 message =
protocolTitle + ": " + String16::fromDouble(elapsed) + "ms";
helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
}
-void V8Console::Timeline(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector)
+void V8Console::Timeline(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
.reportDeprecatedCall("V8Console#timeline",
"'console.timeline' is deprecated. Please use "
"'console.time' instead.");
- timeFunction(info, true, m_inspector);
+ timeFunction(info, consoleContext, true, m_inspector);
}
-void V8Console::TimelineEnd(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper(info, m_inspector)
+void V8Console::TimelineEnd(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper(info, consoleContext, m_inspector)
.reportDeprecatedCall("V8Console#timelineEnd",
"'console.timelineEnd' is "
"deprecated. Please use "
"'console.timeEnd' instead.");
- timeEndFunction(info, true, m_inspector);
+ timeEndFunction(info, consoleContext, true, m_inspector);
}
-void V8Console::Time(const v8::debug::ConsoleCallArguments& info) {
- timeFunction(info, false, m_inspector);
+void V8Console::Time(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ timeFunction(info, consoleContext, false, m_inspector);
}
-void V8Console::TimeEnd(const v8::debug::ConsoleCallArguments& info) {
- timeEndFunction(info, false, m_inspector);
+void V8Console::TimeEnd(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ timeEndFunction(info, consoleContext, false, m_inspector);
}
-void V8Console::TimeStamp(const v8::debug::ConsoleCallArguments& info) {
- ConsoleHelper helper(info, m_inspector);
+void V8Console::TimeStamp(const v8::debug::ConsoleCallArguments& info,
+ const v8::debug::ConsoleContext& consoleContext) {
+ ConsoleHelper helper(info, consoleContext, m_inspector);
String16 title = helper.firstArgToString(String16());
m_inspector->client()->consoleTimeStamp(toStringView(title));
}
@@ -385,12 +424,13 @@ void V8Console::memorySetterCallback(
// setter just ignores the passed value. http://crbug.com/468611
}
-void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
+void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
+ int sessionId) {
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Array::New(isolate));
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, m_inspector);
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
v8::Local<v8::Object> obj;
if (!helper.firstArgAsObject().ToLocal(&obj)) return;
v8::Local<v8::Array> names;
@@ -399,13 +439,13 @@ void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(names);
}
-void V8Console::valuesCallback(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
+void V8Console::valuesCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
+ int sessionId) {
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Array::New(isolate));
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, m_inspector);
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
v8::Local<v8::Object> obj;
if (!helper.firstArgAsObject().ToLocal(&obj)) return;
v8::Local<v8::Array> names;
@@ -422,52 +462,55 @@ void V8Console::valuesCallback(
info.GetReturnValue().Set(values);
}
-static void setFunctionBreakpoint(ConsoleHelper& helper,
+static void setFunctionBreakpoint(ConsoleHelper& helper, int sessionId,
v8::Local<v8::Function> function,
V8DebuggerAgentImpl::BreakpointSource source,
const String16& condition, bool enable) {
- V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent();
- if (!debuggerAgent) return;
String16 scriptId = String16::fromInteger(function->ScriptId());
int lineNumber = function->GetScriptLineNumber();
int columnNumber = function->GetScriptColumnNumber();
if (lineNumber == v8::Function::kLineOffsetNotFound ||
columnNumber == v8::Function::kLineOffsetNotFound)
return;
- if (enable)
- debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source,
- condition);
- else
- debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber,
- source);
+
+ if (V8InspectorSessionImpl* session = helper.session(sessionId)) {
+ if (!session->debuggerAgent()->enabled()) return;
+ if (enable) {
+ session->debuggerAgent()->setBreakpointAt(
+ scriptId, lineNumber, columnNumber, source, condition);
+ } else {
+ session->debuggerAgent()->removeBreakpointAt(scriptId, lineNumber,
+ columnNumber, source);
+ }
+ }
}
void V8Console::debugFunctionCallback(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) {
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, m_inspector);
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
- setFunctionBreakpoint(helper, function,
+ setFunctionBreakpoint(helper, sessionId, function,
V8DebuggerAgentImpl::DebugCommandBreakpointSource,
String16(), true);
}
void V8Console::undebugFunctionCallback(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) {
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, m_inspector);
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
- setFunctionBreakpoint(helper, function,
+ setFunctionBreakpoint(helper, sessionId, function,
V8DebuggerAgentImpl::DebugCommandBreakpointSource,
String16(), false);
}
void V8Console::monitorFunctionCallback(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) {
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, m_inspector);
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
v8::Local<v8::Value> name = function->GetName();
@@ -483,39 +526,40 @@ void V8Console::monitorFunctionCallback(
builder.append(
" called\" + (arguments.length > 0 ? \" with arguments: \" + "
"Array.prototype.join.call(arguments, \", \") : \"\")) && false");
- setFunctionBreakpoint(helper, function,
+ setFunctionBreakpoint(helper, sessionId, function,
V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
builder.toString(), true);
}
void V8Console::unmonitorFunctionCallback(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) {
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, m_inspector);
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
- setFunctionBreakpoint(helper, function,
+ setFunctionBreakpoint(helper, sessionId, function,
V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
String16(), false);
}
void V8Console::lastEvaluationResultCallback(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) {
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, m_inspector);
- InjectedScript* injectedScript = helper.injectedScript();
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
+ InjectedScript* injectedScript = helper.injectedScript(sessionId);
if (!injectedScript) return;
info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
}
static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
- bool copyToClipboard, V8InspectorImpl* inspector) {
+ int sessionId, bool copyToClipboard,
+ V8InspectorImpl* inspector) {
if (info.Length() < 1) return;
if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, inspector);
- InjectedScript* injectedScript = helper.injectedScript();
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), inspector);
+ InjectedScript* injectedScript = helper.injectedScript(sessionId);
if (!injectedScript) return;
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
protocol::Response response =
@@ -526,27 +570,28 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
std::unique_ptr<protocol::DictionaryValue> hints =
protocol::DictionaryValue::create();
if (copyToClipboard) hints->setBoolean("copyToClipboard", true);
- if (V8InspectorSessionImpl* session = helper.currentSession()) {
+ if (V8InspectorSessionImpl* session = helper.session(sessionId)) {
session->runtimeAgent()->inspect(std::move(wrappedObject),
std::move(hints));
}
}
-void V8Console::inspectCallback(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- inspectImpl(info, false, m_inspector);
+void V8Console::inspectCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
+ int sessionId) {
+ inspectImpl(info, sessionId, false, m_inspector);
}
-void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- inspectImpl(info, true, m_inspector);
+void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
+ int sessionId) {
+ inspectImpl(info, sessionId, true, m_inspector);
}
void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
- unsigned num) {
+ int sessionId, unsigned num) {
DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize);
v8::debug::ConsoleCallArguments args(info);
- ConsoleHelper helper(args, m_inspector);
- if (V8InspectorSessionImpl* session = helper.currentSession()) {
+ ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
+ if (V8InspectorSessionImpl* session = helper.session(sessionId)) {
V8InspectorSession::Inspectable* object = session->inspectedObject(num);
v8::Isolate* isolate = info.GetIsolate();
if (object)
@@ -574,7 +619,7 @@ void V8Console::installMemoryGetter(v8::Local<v8::Context> context,
}
v8::Local<v8::Object> V8Console::createCommandLineAPI(
- v8::Local<v8::Context> context) {
+ v8::Local<v8::Context> context, int sessionId) {
v8::Isolate* isolate = context->GetIsolate();
v8::MicrotasksScope microtasksScope(isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
@@ -585,7 +630,9 @@ v8::Local<v8::Object> V8Console::createCommandLineAPI(
DCHECK(success);
USE(success);
- v8::Local<v8::External> data = v8::External::New(isolate, this);
+ // TODO(dgozman): this CommandLineAPIData instance leaks. Use PodArray maybe?
+ v8::Local<v8::External> data =
+ v8::External::New(isolate, new CommandLineAPIData(this, sessionId));
createBoundFunctionProperty(context, commandLineAPI, data, "dir",
&V8Console::call<&V8Console::Dir>,
"function dir(value) { [Command Line API] }");
@@ -715,6 +762,8 @@ V8Console::CommandLineAPIScope::CommandLineAPIScope(
m_global(global),
m_installedMethods(v8::Set::New(context->GetIsolate())),
m_cleanup(false) {
+ v8::MicrotasksScope microtasksScope(context->GetIsolate(),
+ v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Array> names;
if (!m_commandLineAPI->GetOwnPropertyNames(context).ToLocal(&names)) return;
v8::Local<v8::External> externalThis =
@@ -740,6 +789,8 @@ V8Console::CommandLineAPIScope::CommandLineAPIScope(
}
V8Console::CommandLineAPIScope::~CommandLineAPIScope() {
+ v8::MicrotasksScope microtasksScope(m_context->GetIsolate(),
+ v8::MicrotasksScope::kDoNotRunMicrotasks);
m_cleanup = true;
v8::Local<v8::Array> names = m_installedMethods->AsArray();
for (uint32_t i = 0; i < names->Length(); ++i) {