Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Unified Diff: src/inspector/v8-console.cc

Issue 2771413009: [inspector] get rid of ConsoleHelper (Closed)
Patch Set: rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector/v8-console.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/inspector/v8-console.cc
diff --git a/src/inspector/v8-console.cc b/src/inspector/v8-console.cc
index 69e58dfabd03fd64fb8d4bd741bee9e62c36e5ab..6d0433a7a44f67ddf252622c05e9cd62c83ec669 100644
--- a/src/inspector/v8-console.cc
+++ b/src/inspector/v8-console.cc
@@ -23,137 +23,22 @@ namespace v8_inspector {
namespace {
-class ConsoleHelper {
- public:
- explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info,
- V8InspectorImpl* inspector)
- : m_info(info),
- m_isolate(info.GetIsolate()),
- m_context(info.GetIsolate()->GetCurrentContext()),
- m_inspector(inspector),
- m_contextId(InspectedContext::contextId(m_context)),
- m_groupId(m_inspector->contextGroupId(m_contextId)) {}
-
- int contextId() const { return m_contextId; }
- int groupId() const { return m_groupId; }
-
- InjectedScript* injectedScript() {
- InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId);
- if (!context) return nullptr;
- return context->getInjectedScript();
- }
-
- V8ConsoleMessageStorage* consoleMessageStorage() {
- return m_inspector->ensureConsoleMessageStorage(m_groupId);
- }
-
- void reportCall(ConsoleAPIType type) {
- if (!m_info.Length()) return;
- std::vector<v8::Local<v8::Value>> arguments;
- for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]);
- reportCall(type, arguments);
- }
-
- void reportCallWithDefaultArgument(ConsoleAPIType type,
- const String16& message) {
- std::vector<v8::Local<v8::Value>> arguments;
- for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]);
- if (!m_info.Length()) arguments.push_back(toV8String(m_isolate, message));
- reportCall(type, arguments);
- }
-
- void reportCallWithArgument(ConsoleAPIType type, const String16& message) {
- std::vector<v8::Local<v8::Value>> arguments(1,
- toV8String(m_isolate, message));
- reportCall(type, arguments);
- }
-
- void reportCall(ConsoleAPIType type,
- const std::vector<v8::Local<v8::Value>>& arguments) {
- if (!m_groupId) return;
- std::unique_ptr<V8ConsoleMessage> message =
- V8ConsoleMessage::createForConsoleAPI(
- m_context, m_contextId, m_groupId, m_inspector,
- m_inspector->client()->currentTimeMS(), type, arguments,
- m_inspector->debugger()->captureStackTrace(false));
- consoleMessageStorage()->addMessage(std::move(message));
- }
-
- void reportDeprecatedCall(const char* id, const String16& message) {
- if (!consoleMessageStorage()->shouldReportDeprecationMessage(m_contextId,
- id)) {
- return;
- }
- std::vector<v8::Local<v8::Value>> arguments(1,
- toV8String(m_isolate, message));
- reportCall(ConsoleAPIType::kWarning, arguments);
- }
-
- bool firstArgToBoolean(bool defaultValue) {
- if (m_info.Length() < 1) return defaultValue;
- if (m_info[0]->IsBoolean()) return m_info[0].As<v8::Boolean>()->Value();
- return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue);
- }
-
- String16 firstArgToString(const String16& defaultValue) {
- if (m_info.Length() < 1) return defaultValue;
- v8::Local<v8::String> titleValue;
- if (m_info[0]->IsObject()) {
- if (!m_info[0].As<v8::Object>()->ObjectProtoToString(m_context).ToLocal(
- &titleValue))
- return defaultValue;
- } else {
- if (!m_info[0]->ToString(m_context).ToLocal(&titleValue))
- return defaultValue;
- }
- return toProtocolString(titleValue);
- }
-
- v8::MaybeLocal<v8::Object> firstArgAsObject() {
- if (m_info.Length() < 1 || !m_info[0]->IsObject())
- return v8::MaybeLocal<v8::Object>();
- return m_info[0].As<v8::Object>();
- }
-
- v8::MaybeLocal<v8::Function> firstArgAsFunction() {
- if (m_info.Length() < 1 || !m_info[0]->IsFunction())
- return v8::MaybeLocal<v8::Function>();
- v8::Local<v8::Function> func = m_info[0].As<v8::Function>();
- while (func->GetBoundFunction()->IsFunction())
- func = func->GetBoundFunction().As<v8::Function>();
- 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);
- }
-
- private:
- const v8::FunctionCallbackInfo<v8::Value>& m_info;
- v8::Isolate* m_isolate;
- v8::Local<v8::Context> m_context;
- V8InspectorImpl* m_inspector = nullptr;
- int m_contextId;
- int m_groupId;
+v8::MaybeLocal<v8::Function> firstArgAsFunction(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ if (info.Length() < 1 || !info[0]->IsFunction())
+ return v8::MaybeLocal<v8::Function>();
+ v8::Local<v8::Function> func = info[0].As<v8::Function>();
+ while (func->GetBoundFunction()->IsFunction())
+ func = func->GetBoundFunction().As<v8::Function>();
+ return func;
+}
- DISALLOW_COPY_AND_ASSIGN(ConsoleHelper);
-};
+v8::MaybeLocal<v8::Object> firstArgAsObject(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ if (info.Length() < 1 || !info[0]->IsObject())
+ return v8::MaybeLocal<v8::Object>();
+ return info[0].As<v8::Object>();
+}
void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(info.Data());
@@ -178,10 +63,11 @@ void createBoundFunctionProperty(v8::Local<v8::Context> context,
v8::Local<v8::Function> toStringFunction;
if (v8::Function::New(context, returnDataCallback, returnValue, 0,
v8::ConstructorBehavior::kThrow)
- .ToLocal(&toStringFunction))
+ .ToLocal(&toStringFunction)) {
createDataProperty(context, func, toV8StringInternalized(
context->GetIsolate(), "toString"),
toStringFunction);
+ }
}
createDataProperty(context, console, funcName, func);
}
@@ -190,76 +76,194 @@ void createBoundFunctionProperty(v8::Local<v8::Context> context,
V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {}
+int V8Console::currentContextId() {
+ return InspectedContext::contextId(
+ m_inspector->isolate()->GetCurrentContext());
+}
+
+V8InspectorSessionImpl* V8Console::currentSession() {
+ int groupId = m_inspector->contextGroupId(currentContextId());
+ return groupId ? m_inspector->sessionForContextGroup(groupId) : nullptr;
+}
+
+V8ProfilerAgentImpl* V8Console::profilerAgent() {
+ V8InspectorSessionImpl* session = currentSession();
+ if (!session) return nullptr;
+ if (!session || !session->profilerAgent()->enabled()) return nullptr;
+ return session->profilerAgent();
+}
+
+V8DebuggerAgentImpl* V8Console::debuggerAgent() {
+ V8InspectorSessionImpl* session = currentSession();
+ if (!session) return nullptr;
+ if (!session || !session->debuggerAgent()->enabled()) return nullptr;
+ return session->debuggerAgent();
+}
+
+V8RuntimeAgentImpl* V8Console::runtimeAgent() {
+ V8InspectorSessionImpl* session = currentSession();
+ if (!session) return nullptr;
+ if (!session || !session->runtimeAgent()->enabled()) return nullptr;
+ return session->runtimeAgent();
+}
+
+InjectedScript* V8Console::injectedScript() {
+ int contextId = currentContextId();
+ int groupId = m_inspector->contextGroupId(contextId);
+ InspectedContext* context = m_inspector->getContext(groupId, contextId);
+ if (!context) return nullptr;
+ return context->getInjectedScript();
+}
+
+V8ConsoleMessageStorage* V8Console::messageStorage() {
+ int contextId =
+ InspectedContext::contextId(m_inspector->isolate()->GetCurrentContext());
+ int groupId = m_inspector->contextGroupId(contextId);
+ if (!groupId) return nullptr;
+ return m_inspector->ensureConsoleMessageStorage(groupId);
+}
+
+void V8Console::reportCall(ConsoleAPIType type,
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ if (!info.Length()) return;
+ std::vector<v8::Local<v8::Value>> arguments;
+ for (int i = 0; i < info.Length(); ++i) arguments.push_back(info[i]);
+ reportCall(type, arguments);
+}
+
+void V8Console::reportCallWithDefaultArgument(
+ ConsoleAPIType type, const v8::FunctionCallbackInfo<v8::Value>& info,
+ const String16& message) {
+ std::vector<v8::Local<v8::Value>> arguments;
+ for (int i = 0; i < info.Length(); ++i) arguments.push_back(info[i]);
+ if (!info.Length())
+ arguments.push_back(toV8String(m_inspector->isolate(), message));
+ reportCall(type, arguments);
+}
+
+void V8Console::reportCallWithArgument(ConsoleAPIType type,
+ const String16& message) {
+ std::vector<v8::Local<v8::Value>> arguments(
+ 1, toV8String(m_inspector->isolate(), message));
+ reportCall(type, arguments);
+}
+
+void V8Console::reportDeprecatedCall(const char* id, const String16& message) {
+ V8ConsoleMessageStorage* storage = messageStorage();
+ if (!storage) return;
+ int contextId = currentContextId();
+ if (!contextId) return;
+ if (!storage->shouldReportDeprecationMessage(contextId, id)) return;
+ reportCallWithArgument(ConsoleAPIType::kWarning, message);
+}
+
+void V8Console::reportCall(ConsoleAPIType type,
+ const std::vector<v8::Local<v8::Value>>& arguments) {
+ int contextId = currentContextId();
+ if (!contextId) return;
+ V8ConsoleMessageStorage* storage = messageStorage();
+ if (!storage) return;
+ int groupId = m_inspector->contextGroupId(contextId);
+ if (!groupId) return;
+ if (type == ConsoleAPIType::kClear) {
+ m_inspector->client()->consoleClear(groupId);
+ }
+ v8::Local<v8::Context> context = m_inspector->isolate()->GetCurrentContext();
+ std::unique_ptr<V8ConsoleMessage> message =
+ V8ConsoleMessage::createForConsoleAPI(
+ context, contextId, groupId, m_inspector,
+ m_inspector->client()->currentTimeMS(), type, arguments,
+ m_inspector->debugger()->captureStackTrace(false));
+ storage->addMessage(std::move(message));
+}
+
+String16 V8Console::firstArgToString(
+ const v8::FunctionCallbackInfo<v8::Value>& info,
+ const String16& defaultValue) {
+ if (info.Length() < 1) return defaultValue;
+ v8::Local<v8::Context> context = m_inspector->isolate()->GetCurrentContext();
+ v8::Local<v8::String> titleValue;
+ if (info[0]->IsObject()) {
+ if (!info[0].As<v8::Object>()->ObjectProtoToString(context).ToLocal(
+ &titleValue))
+ return defaultValue;
+ } else {
+ if (!info[0]->ToString(context).ToLocal(&titleValue)) return defaultValue;
+ }
+ return toProtocolString(titleValue);
+}
+
+bool V8Console::firstArgToBoolean(
+ const v8::FunctionCallbackInfo<v8::Value>& info, bool defaultValue) {
+ if (info.Length() < 1) return defaultValue;
+ if (info[0]->IsBoolean()) return info[0].As<v8::Boolean>()->Value();
+ return info[0]
+ ->BooleanValue(m_inspector->isolate()->GetCurrentContext())
+ .FromMaybe(defaultValue);
+}
+
void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug);
+ reportCall(ConsoleAPIType::kDebug, info);
}
void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError);
+ reportCall(ConsoleAPIType::kError, info);
}
void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo);
+ reportCall(ConsoleAPIType::kInfo, info);
}
void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog);
+ reportCall(ConsoleAPIType::kLog, info);
}
void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning);
+ reportCall(ConsoleAPIType::kWarning, info);
}
void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir);
+ reportCall(ConsoleAPIType::kDir, info);
}
void V8Console::dirxmlCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML);
+ reportCall(ConsoleAPIType::kDirXML, info);
}
void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable);
+ reportCall(ConsoleAPIType::kTable, info);
}
void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector)
- .reportCallWithDefaultArgument(ConsoleAPIType::kTrace,
- String16("console.trace"));
+ reportCallWithDefaultArgument(ConsoleAPIType::kTrace, info,
+ String16("console.trace"));
}
void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector)
- .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup,
- String16("console.group"));
+ reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, info,
+ String16("console.group"));
}
void V8Console::groupCollapsedCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector)
- .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed,
- String16("console.groupCollapsed"));
+ reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed, info,
+ String16("console.groupCollapsed"));
}
void V8Console::groupEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector)
- .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup,
- String16("console.groupEnd"));
+ reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup, info,
+ String16("console.groupEnd"));
}
void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
- if (!helper.groupId()) return;
- m_inspector->client()->consoleClear(helper.groupId());
- helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear,
- String16("console.clear"));
+ reportCallWithDefaultArgument(ConsoleAPIType::kClear, info,
+ String16("console.clear"));
}
void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
- String16 title = helper.firstArgToString(String16());
+ String16 title = firstArgToString(info, String16());
String16 identifier;
if (title.isEmpty()) {
std::unique_ptr<V8StackTraceImpl> stackTrace =
@@ -272,109 +276,106 @@ void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
identifier = title + "@";
}
- int count =
- helper.consoleMessageStorage()->count(helper.contextId(), identifier);
+ V8ConsoleMessageStorage* storage = messageStorage();
+ if (!storage) return;
+ int count = storage->count(currentContextId(), identifier);
String16 countString = String16::fromInteger(count);
- helper.reportCallWithArgument(
+ reportCallWithArgument(
ConsoleAPIType::kCount,
title.isEmpty() ? countString : (title + ": " + countString));
}
void V8Console::assertCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
- if (helper.firstArgToBoolean(false)) return;
+ if (firstArgToBoolean(info, false)) return;
std::vector<v8::Local<v8::Value>> arguments;
for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]);
if (info.Length() < 2)
arguments.push_back(
- toV8String(info.GetIsolate(), String16("console.assert")));
- helper.reportCall(ConsoleAPIType::kAssert, arguments);
-
- if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent())
- debuggerAgent->breakProgramOnException(
- protocol::Debugger::Paused::ReasonEnum::Assert, nullptr);
+ toV8String(m_inspector->isolate(), String16("console.assert")));
+ reportCall(ConsoleAPIType::kAssert, arguments);
+ V8DebuggerAgentImpl* agent = debuggerAgent();
+ if (!agent) return;
+ agent->breakProgramOnException(protocol::Debugger::Paused::ReasonEnum::Assert,
+ nullptr);
}
void V8Console::markTimelineCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector)
- .reportDeprecatedCall("V8Console#markTimelineDeprecated",
- "'console.markTimeline' is "
- "deprecated. Please use "
- "'console.timeStamp' instead.");
+ reportDeprecatedCall("V8Console#markTimelineDeprecated",
+ "'console.markTimeline' is "
+ "deprecated. Please use "
+ "'console.timeStamp' instead.");
timeStampCallback(info);
}
void V8Console::profileCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
- if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
- profilerAgent->consoleProfile(helper.firstArgToString(String16()));
+ if (V8ProfilerAgentImpl* agent = profilerAgent()) {
+ agent->consoleProfile(firstArgToString(info, String16()));
+ }
}
void V8Console::profileEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
- if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
- profilerAgent->consoleProfileEnd(helper.firstArgToString(String16()));
+ if (V8ProfilerAgentImpl* agent = profilerAgent()) {
+ agent->consoleProfileEnd(firstArgToString(info, String16()));
+ }
}
-static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
- bool timelinePrefix, V8InspectorImpl* inspector) {
- ConsoleHelper helper(info, inspector);
- String16 protocolTitle = helper.firstArgToString("default");
+void V8Console::time(const v8::FunctionCallbackInfo<v8::Value>& info,
+ bool timelinePrefix) {
+ String16 protocolTitle = firstArgToString(info, "default");
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
- inspector->client()->consoleTime(toStringView(protocolTitle));
- helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle);
+ m_inspector->client()->consoleTime(toStringView(protocolTitle));
+ if (V8ConsoleMessageStorage* storage = messageStorage()) {
+ storage->time(currentContextId(), protocolTitle);
+ }
}
-static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
- bool timelinePrefix, V8InspectorImpl* inspector) {
- ConsoleHelper helper(info, inspector);
- String16 protocolTitle = helper.firstArgToString("default");
+void V8Console::timeEnd(const v8::FunctionCallbackInfo<v8::Value>& info,
+ bool timelinePrefix) {
+ String16 protocolTitle = firstArgToString(info, "default");
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
- inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
- double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(),
- protocolTitle);
+ m_inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
+ V8ConsoleMessageStorage* storage = messageStorage();
+ if (!storage) return;
+ double elapsed = storage->timeEnd(currentContextId(), protocolTitle);
String16 message =
protocolTitle + ": " + String16::fromDouble(elapsed) + "ms";
- helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
+ reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
}
void V8Console::timelineCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector)
- .reportDeprecatedCall("V8Console#timeline",
- "'console.timeline' is deprecated. Please use "
- "'console.time' instead.");
- timeFunction(info, true, m_inspector);
+ reportDeprecatedCall("V8Console#timeline",
+ "'console.timeline' is deprecated. Please use "
+ "'console.time' instead.");
+ time(info, true);
}
void V8Console::timelineEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper(info, m_inspector)
- .reportDeprecatedCall("V8Console#timelineEnd",
- "'console.timelineEnd' is "
- "deprecated. Please use "
- "'console.timeEnd' instead.");
- timeEndFunction(info, true, m_inspector);
+ reportDeprecatedCall("V8Console#timelineEnd",
+ "'console.timelineEnd' is "
+ "deprecated. Please use "
+ "'console.timeEnd' instead.");
+ timeEnd(info, true);
}
void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- timeFunction(info, false, m_inspector);
+ time(info, false);
}
void V8Console::timeEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- timeEndFunction(info, false, m_inspector);
+ timeEnd(info, false);
}
void V8Console::timeStampCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
- String16 title = helper.firstArgToString(String16());
+ String16 title = firstArgToString(info, String16());
m_inspector->client()->consoleTimeStamp(toStringView(title));
}
@@ -399,10 +400,8 @@ void V8Console::memorySetterCallback(
void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Array::New(isolate));
-
- ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Object> obj;
- if (!helper.firstArgAsObject().ToLocal(&obj)) return;
+ if (!firstArgAsObject(info).ToLocal(&obj)) return;
v8::Local<v8::Array> names;
if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names))
return;
@@ -413,10 +412,8 @@ void V8Console::valuesCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Array::New(isolate));
-
- ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Object> obj;
- if (!helper.firstArgAsObject().ToLocal(&obj)) return;
+ if (!firstArgAsObject(info).ToLocal(&obj)) return;
v8::Local<v8::Array> names;
v8::Local<v8::Context> context = isolate->GetCurrentContext();
if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return;
@@ -431,12 +428,10 @@ void V8Console::valuesCallback(
info.GetReturnValue().Set(values);
}
-static void setFunctionBreakpoint(ConsoleHelper& helper,
+static void setFunctionBreakpoint(V8DebuggerAgentImpl* agent,
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();
@@ -444,38 +439,40 @@ static void setFunctionBreakpoint(ConsoleHelper& helper,
columnNumber == v8::Function::kLineOffsetNotFound)
return;
if (enable)
- debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source,
- condition);
+ agent->setBreakpointAt(scriptId, lineNumber, columnNumber, source,
+ condition);
else
- debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber,
- source);
+ agent->removeBreakpointAt(scriptId, lineNumber, columnNumber, source);
}
void V8Console::debugFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
- if (!helper.firstArgAsFunction().ToLocal(&function)) return;
- setFunctionBreakpoint(helper, function,
+ if (!firstArgAsFunction(info).ToLocal(&function)) return;
+ V8DebuggerAgentImpl* agent = debuggerAgent();
+ if (!agent) return;
+ setFunctionBreakpoint(agent, function,
V8DebuggerAgentImpl::DebugCommandBreakpointSource,
String16(), true);
}
void V8Console::undebugFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
- if (!helper.firstArgAsFunction().ToLocal(&function)) return;
- setFunctionBreakpoint(helper, function,
+ if (!firstArgAsFunction(info).ToLocal(&function)) return;
+ V8DebuggerAgentImpl* agent = debuggerAgent();
+ if (!agent) return;
+ setFunctionBreakpoint(agent, function,
V8DebuggerAgentImpl::DebugCommandBreakpointSource,
String16(), false);
}
void V8Console::monitorFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
- if (!helper.firstArgAsFunction().ToLocal(&function)) return;
+ if (!firstArgAsFunction(info).ToLocal(&function)) return;
+ V8DebuggerAgentImpl* agent = debuggerAgent();
+ if (!agent) return;
v8::Local<v8::Value> name = function->GetName();
if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length())
name = function->GetInferredName();
@@ -489,37 +486,34 @@ void V8Console::monitorFunctionCallback(
builder.append(
" called\" + (arguments.length > 0 ? \" with arguments: \" + "
"Array.prototype.join.call(arguments, \", \") : \"\")) && false");
- setFunctionBreakpoint(helper, function,
+ setFunctionBreakpoint(agent, function,
V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
builder.toString(), true);
}
void V8Console::unmonitorFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
- if (!helper.firstArgAsFunction().ToLocal(&function)) return;
- setFunctionBreakpoint(helper, function,
+ if (!firstArgAsFunction(info).ToLocal(&function)) return;
+ V8DebuggerAgentImpl* agent = debuggerAgent();
+ setFunctionBreakpoint(agent, function,
V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
String16(), false);
}
void V8Console::lastEvaluationResultCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- ConsoleHelper helper(info, m_inspector);
- InjectedScript* injectedScript = helper.injectedScript();
- if (!injectedScript) return;
- info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
+ InjectedScript* injected = injectedScript();
+ if (!injected) return;
+ info.GetReturnValue().Set(injected->lastEvaluationResult());
}
static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
- bool copyToClipboard, V8InspectorImpl* inspector) {
- if (info.Length() < 1) return;
+ bool copyToClipboard, V8InspectorImpl* inspector,
+ V8RuntimeAgentImpl* agent,
+ InjectedScript* injectedScript) {
if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
- ConsoleHelper helper(info, inspector);
- InjectedScript* injectedScript = helper.injectedScript();
- if (!injectedScript) return;
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
protocol::Response response =
injectedScript->wrapObject(info[0], "", false /** forceValueType */,
@@ -529,26 +523,32 @@ 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()) {
- session->runtimeAgent()->inspect(std::move(wrappedObject),
- std::move(hints));
- }
+ agent->inspect(std::move(wrappedObject), std::move(hints));
}
void V8Console::inspectCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
- inspectImpl(info, false, m_inspector);
+ if (info.Length() < 1) return;
+ V8RuntimeAgentImpl* agent = runtimeAgent();
+ if (!agent) return;
+ InjectedScript* injected = injectedScript();
+ if (!injected) return;
+ inspectImpl(info, false, m_inspector, agent, injected);
}
void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- inspectImpl(info, true, m_inspector);
+ if (info.Length() < 1) return;
+ V8RuntimeAgentImpl* agent = runtimeAgent();
+ if (!agent) return;
+ InjectedScript* injected = injectedScript();
+ if (!injected) return;
+ inspectImpl(info, true, m_inspector, agent, injected);
}
void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
unsigned num) {
DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize);
- ConsoleHelper helper(info, m_inspector);
- if (V8InspectorSessionImpl* session = helper.currentSession()) {
+ if (V8InspectorSessionImpl* session = currentSession()) {
V8InspectorSession::Inspectable* object = session->inspectedObject(num);
v8::Isolate* isolate = info.GetIsolate();
if (object)
« no previous file with comments | « src/inspector/v8-console.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698