Commit 545f99d0 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] convert V8Console static methods into members

This step is required to implement console as builtin which calls console delegate methods.

BUG=v8:6175
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2783073002
Cr-Original-Commit-Position: refs/heads/master@{#44283}
Committed: https://chromium.googlesource.com/v8/v8/+/fe27dccd873024213b16d1e9810dda6a6c705571
Review-Url: https://codereview.chromium.org/2783073002
Cr-Commit-Position: refs/heads/master@{#44285}
parent 5b306f72
......@@ -406,9 +406,12 @@ Response InjectedScript::wrapEvaluateResult(
}
v8::Local<v8::Object> InjectedScript::commandLineAPI() {
if (m_commandLineAPI.IsEmpty())
m_commandLineAPI.Reset(m_context->isolate(),
V8Console::createCommandLineAPI(m_context));
if (m_commandLineAPI.IsEmpty()) {
m_commandLineAPI.Reset(
m_context->isolate(),
m_context->inspector()->console()->createCommandLineAPI(
m_context->context()));
}
return m_commandLineAPI.Get(m_context->isolate());
}
......
......@@ -28,9 +28,10 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
v8::Int32::New(isolate, contextId));
v8::Local<v8::Object> global = info.context->Global();
v8::Local<v8::Object> console = V8Console::createConsole(this);
v8::Local<v8::Object> console =
m_inspector->console()->createConsole(info.context);
if (info.hasMemoryOnConsole) {
V8Console::installMemoryGetter(m_inspector, info.context, console);
m_inspector->console()->installMemoryGetter(info.context, console);
}
if (!global
->Set(info.context, toV8StringInternalized(isolate, "console"),
......
......@@ -25,17 +25,14 @@ namespace {
class ConsoleHelper {
public:
explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info)
explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info,
V8InspectorImpl* inspector)
: m_info(info),
m_isolate(info.GetIsolate()),
m_context(info.GetIsolate()->GetCurrentContext()),
m_contextId(InspectedContext::contextId(m_context)) {
m_inspector = static_cast<V8InspectorImpl*>(
m_info.Data().As<v8::External>()->Value());
m_groupId = m_inspector->contextGroupId(m_contextId);
}
V8InspectorImpl* inspector() { return m_inspector; }
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; }
......@@ -47,7 +44,7 @@ class ConsoleHelper {
}
V8ConsoleMessageStorage* consoleMessageStorage() {
return inspector()->ensureConsoleMessageStorage(m_groupId);
return m_inspector->ensureConsoleMessageStorage(m_groupId);
}
void reportCall(ConsoleAPIType type) {
......@@ -151,7 +148,6 @@ class ConsoleHelper {
const v8::FunctionCallbackInfo<v8::Value>& m_info;
v8::Isolate* m_isolate;
v8::Local<v8::Context> m_context;
v8::Local<v8::Object> m_console;
V8InspectorImpl* m_inspector = nullptr;
int m_contextId;
int m_groupId;
......@@ -192,76 +188,82 @@ void createBoundFunctionProperty(v8::Local<v8::Context> context,
} // namespace
V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {}
void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCall(ConsoleAPIType::kDebug);
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug);
}
void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCall(ConsoleAPIType::kError);
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError);
}
void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCall(ConsoleAPIType::kInfo);
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo);
}
void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCall(ConsoleAPIType::kLog);
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog);
}
void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCall(ConsoleAPIType::kWarning);
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning);
}
void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCall(ConsoleAPIType::kDir);
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir);
}
void V8Console::dirxmlCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCall(ConsoleAPIType::kDirXML);
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML);
}
void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCall(ConsoleAPIType::kTable);
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable);
}
void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCallWithDefaultArgument(ConsoleAPIType::kTrace,
String16("console.trace"));
ConsoleHelper(info, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kTrace,
String16("console.trace"));
}
void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup,
String16("console.group"));
ConsoleHelper(info, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup,
String16("console.group"));
}
void V8Console::groupCollapsedCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCallWithDefaultArgument(
ConsoleAPIType::kStartGroupCollapsed, String16("console.groupCollapsed"));
ConsoleHelper(info, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed,
String16("console.groupCollapsed"));
}
void V8Console::groupEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportCallWithDefaultArgument(
ConsoleAPIType::kEndGroup, String16("console.groupEnd"));
ConsoleHelper(info, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup,
String16("console.groupEnd"));
}
void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
if (!helper.groupId()) return;
helper.inspector()->client()->consoleClear(helper.groupId());
m_inspector->client()->consoleClear(helper.groupId());
helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear,
String16("console.clear"));
}
void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
String16 title = helper.firstArgToString(String16());
String16 identifier;
if (title.isEmpty()) {
std::unique_ptr<V8StackTraceImpl> stackTrace =
V8StackTraceImpl::capture(helper.inspector()->debugger(), 0, 1);
V8StackTraceImpl::capture(m_inspector->debugger(), 0, 1);
if (stackTrace && !stackTrace->isEmpty()) {
identifier = toString16(stackTrace->topSourceURL()) + ":" +
String16::fromInteger(stackTrace->topLineNumber());
......@@ -280,7 +282,7 @@ void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
void V8Console::assertCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
if (helper.firstArgToBoolean(false)) return;
std::vector<v8::Local<v8::Value>> arguments;
......@@ -297,44 +299,43 @@ void V8Console::assertCallback(
void V8Console::markTimelineCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportDeprecatedCall("V8Console#markTimelineDeprecated",
"'console.markTimeline' is "
"deprecated. Please use "
"'console.timeStamp' instead.");
ConsoleHelper(info, m_inspector)
.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);
ConsoleHelper helper(info, m_inspector);
if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
profilerAgent->consoleProfile(helper.firstArgToString(String16()));
}
void V8Console::profileEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
profilerAgent->consoleProfileEnd(helper.firstArgToString(String16()));
}
static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
bool timelinePrefix) {
ConsoleHelper helper(info);
V8InspectorClient* client = helper.inspector()->client();
bool timelinePrefix, V8InspectorImpl* inspector) {
ConsoleHelper helper(info, inspector);
String16 protocolTitle = helper.firstArgToString("default");
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
client->consoleTime(toStringView(protocolTitle));
inspector->client()->consoleTime(toStringView(protocolTitle));
helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle);
}
static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
bool timelinePrefix) {
ConsoleHelper helper(info);
V8InspectorClient* client = helper.inspector()->client();
bool timelinePrefix, V8InspectorImpl* inspector) {
ConsoleHelper helper(info, inspector);
String16 protocolTitle = helper.firstArgToString("default");
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
client->consoleTimeEnd(toStringView(protocolTitle));
inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(),
protocolTitle);
String16 message =
......@@ -344,42 +345,43 @@ static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
void V8Console::timelineCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportDeprecatedCall(
"V8Console#timeline",
"'console.timeline' is deprecated. Please use 'console.time' instead.");
timeFunction(info, true);
ConsoleHelper(info, m_inspector)
.reportDeprecatedCall("V8Console#timeline",
"'console.timeline' is deprecated. Please use "
"'console.time' instead.");
timeFunction(info, true, m_inspector);
}
void V8Console::timelineEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info).reportDeprecatedCall("V8Console#timelineEnd",
"'console.timelineEnd' is "
"deprecated. Please use "
"'console.timeEnd' instead.");
timeEndFunction(info, true);
ConsoleHelper(info, m_inspector)
.reportDeprecatedCall("V8Console#timelineEnd",
"'console.timelineEnd' is "
"deprecated. Please use "
"'console.timeEnd' instead.");
timeEndFunction(info, true, m_inspector);
}
void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
timeFunction(info, false);
timeFunction(info, false, m_inspector);
}
void V8Console::timeEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
timeEndFunction(info, false);
timeEndFunction(info, false, m_inspector);
}
void V8Console::timeStampCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
String16 title = helper.firstArgToString(String16());
helper.inspector()->client()->consoleTimeStamp(toStringView(title));
m_inspector->client()->consoleTimeStamp(toStringView(title));
}
void V8Console::memoryGetterCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
V8InspectorClient* client = ConsoleHelper(info).inspector()->client();
v8::Local<v8::Value> memoryValue;
if (!client
if (!m_inspector->client()
->memoryInfo(info.GetIsolate(),
info.GetIsolate()->GetCurrentContext())
.ToLocal(&memoryValue))
......@@ -398,7 +400,7 @@ void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Array::New(isolate));
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Object> obj;
if (!helper.firstArgAsObject().ToLocal(&obj)) return;
v8::Local<v8::Array> names;
......@@ -412,7 +414,7 @@ void V8Console::valuesCallback(
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Array::New(isolate));
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Object> obj;
if (!helper.firstArgAsObject().ToLocal(&obj)) return;
v8::Local<v8::Array> names;
......@@ -451,7 +453,7 @@ static void setFunctionBreakpoint(ConsoleHelper& helper,
void V8Console::debugFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
setFunctionBreakpoint(helper, function,
......@@ -461,7 +463,7 @@ void V8Console::debugFunctionCallback(
void V8Console::undebugFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
setFunctionBreakpoint(helper, function,
......@@ -471,7 +473,7 @@ void V8Console::undebugFunctionCallback(
void V8Console::monitorFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
v8::Local<v8::Value> name = function->GetName();
......@@ -494,7 +496,7 @@ void V8Console::monitorFunctionCallback(
void V8Console::unmonitorFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
setFunctionBreakpoint(helper, function,
......@@ -504,18 +506,18 @@ void V8Console::unmonitorFunctionCallback(
void V8Console::lastEvaluationResultCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
InjectedScript* injectedScript = helper.injectedScript();
if (!injectedScript) return;
info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
}
static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
bool copyToClipboard) {
bool copyToClipboard, V8InspectorImpl* inspector) {
if (info.Length() < 1) return;
if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
ConsoleHelper helper(info);
ConsoleHelper helper(info, inspector);
InjectedScript* injectedScript = helper.injectedScript();
if (!injectedScript) return;
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
......@@ -535,17 +537,17 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
void V8Console::inspectCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
inspectImpl(info, false);
inspectImpl(info, false, m_inspector);
}
void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
inspectImpl(info, true);
inspectImpl(info, true, m_inspector);
}
void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
unsigned num) {
DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize);
ConsoleHelper helper(info);
ConsoleHelper helper(info, m_inspector);
if (V8InspectorSessionImpl* session = helper.currentSession()) {
V8InspectorSession::Inspectable* object = session->inspectedObject(num);
v8::Isolate* isolate = info.GetIsolate();
......@@ -556,9 +558,7 @@ void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
}
}
v8::Local<v8::Object> V8Console::createConsole(
InspectedContext* inspectedContext) {
v8::Local<v8::Context> context = inspectedContext->context();
v8::Local<v8::Object> V8Console::createConsole(v8::Local<v8::Context> context) {
v8::Context::Scope contextScope(context);
v8::Isolate* isolate = context->GetIsolate();
v8::MicrotasksScope microtasksScope(isolate,
......@@ -570,76 +570,78 @@ v8::Local<v8::Object> V8Console::createConsole(
DCHECK(success);
USE(success);
v8::Local<v8::External> data =
v8::External::New(isolate, inspectedContext->inspector());
v8::Local<v8::External> data = v8::External::New(isolate, this);
createBoundFunctionProperty(context, console, data, "debug",
V8Console::debugCallback);
&V8Console::call<&V8Console::debugCallback>);
createBoundFunctionProperty(context, console, data, "error",
V8Console::errorCallback);
&V8Console::call<&V8Console::errorCallback>);
createBoundFunctionProperty(context, console, data, "info",
V8Console::infoCallback);
&V8Console::call<&V8Console::infoCallback>);
createBoundFunctionProperty(context, console, data, "log",
V8Console::logCallback);
&V8Console::call<&V8Console::logCallback>);
createBoundFunctionProperty(context, console, data, "warn",
V8Console::warnCallback);
&V8Console::call<&V8Console::warnCallback>);
createBoundFunctionProperty(context, console, data, "dir",
V8Console::dirCallback);
&V8Console::call<&V8Console::dirCallback>);
createBoundFunctionProperty(context, console, data, "dirxml",
V8Console::dirxmlCallback);
&V8Console::call<&V8Console::dirxmlCallback>);
createBoundFunctionProperty(context, console, data, "table",
V8Console::tableCallback);
&V8Console::call<&V8Console::tableCallback>);
createBoundFunctionProperty(context, console, data, "trace",
V8Console::traceCallback);
&V8Console::call<&V8Console::traceCallback>);
createBoundFunctionProperty(context, console, data, "group",
V8Console::groupCallback);
createBoundFunctionProperty(context, console, data, "groupCollapsed",
V8Console::groupCollapsedCallback);
&V8Console::call<&V8Console::groupCallback>);
createBoundFunctionProperty(
context, console, data, "groupCollapsed",
&V8Console::call<&V8Console::groupCollapsedCallback>);
createBoundFunctionProperty(context, console, data, "groupEnd",
V8Console::groupEndCallback);
&V8Console::call<&V8Console::groupEndCallback>);
createBoundFunctionProperty(context, console, data, "clear",
V8Console::clearCallback);
&V8Console::call<&V8Console::clearCallback>);
createBoundFunctionProperty(context, console, data, "count",
V8Console::countCallback);
&V8Console::call<&V8Console::countCallback>);
createBoundFunctionProperty(context, console, data, "assert",
V8Console::assertCallback);
createBoundFunctionProperty(context, console, data, "markTimeline",
V8Console::markTimelineCallback);
&V8Console::call<&V8Console::assertCallback>);
createBoundFunctionProperty(
context, console, data, "markTimeline",
&V8Console::call<&V8Console::markTimelineCallback>);
createBoundFunctionProperty(context, console, data, "profile",
V8Console::profileCallback);
&V8Console::call<&V8Console::profileCallback>);
createBoundFunctionProperty(context, console, data, "profileEnd",
V8Console::profileEndCallback);
&V8Console::call<&V8Console::profileEndCallback>);
createBoundFunctionProperty(context, console, data, "timeline",
V8Console::timelineCallback);
createBoundFunctionProperty(context, console, data, "timelineEnd",
V8Console::timelineEndCallback);
&V8Console::call<&V8Console::timelineCallback>);
createBoundFunctionProperty(
context, console, data, "timelineEnd",
&V8Console::call<&V8Console::timelineEndCallback>);
createBoundFunctionProperty(context, console, data, "time",
V8Console::timeCallback);
&V8Console::call<&V8Console::timeCallback>);
createBoundFunctionProperty(context, console, data, "timeEnd",
V8Console::timeEndCallback);
&V8Console::call<&V8Console::timeEndCallback>);
createBoundFunctionProperty(context, console, data, "timeStamp",
V8Console::timeStampCallback);
&V8Console::call<&V8Console::timeStampCallback>);
return console;
}
void V8Console::installMemoryGetter(V8InspectorImpl* inspector,
v8::Local<v8::Context> context,
void V8Console::installMemoryGetter(v8::Local<v8::Context> context,
v8::Local<v8::Object> console) {
v8::Local<v8::External> data =
v8::External::New(inspector->isolate(), inspector);
v8::Isolate* isolate = context->GetIsolate();
v8::Local<v8::External> data = v8::External::New(isolate, this);
console->SetAccessorProperty(
toV8StringInternalized(inspector->isolate(), "memory"),
v8::Function::New(context, V8Console::memoryGetterCallback, data, 0,
v8::ConstructorBehavior::kThrow)
toV8StringInternalized(isolate, "memory"),
v8::Function::New(context,
&V8Console::call<&V8Console::memoryGetterCallback>,
data, 0, v8::ConstructorBehavior::kThrow)
.ToLocalChecked(),
v8::Function::New(context, V8Console::memorySetterCallback, data, 0,
v8::ConstructorBehavior::kThrow)
v8::Function::New(context,
&V8Console::call<&V8Console::memorySetterCallback>,
data, 0, v8::ConstructorBehavior::kThrow)
.ToLocalChecked(),
static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT);
}
v8::Local<v8::Object> V8Console::createCommandLineAPI(
InspectedContext* inspectedContext) {
v8::Local<v8::Context> context = inspectedContext->context();
v8::Local<v8::Context> context) {
v8::Isolate* isolate = context->GetIsolate();
v8::MicrotasksScope microtasksScope(isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
......@@ -650,70 +652,73 @@ v8::Local<v8::Object> V8Console::createCommandLineAPI(
DCHECK(success);
USE(success);
v8::Local<v8::External> data =
v8::External::New(isolate, inspectedContext->inspector());
v8::Local<v8::External> data = v8::External::New(isolate, this);
createBoundFunctionProperty(context, commandLineAPI, data, "dir",
V8Console::dirCallback,
&V8Console::call<&V8Console::dirCallback>,
"function dir(value) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "dirxml",
V8Console::dirxmlCallback,
&V8Console::call<&V8Console::dirxmlCallback>,
"function dirxml(value) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "profile",
V8Console::profileCallback,
&V8Console::call<&V8Console::profileCallback>,
"function profile(title) { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "profileEnd",
V8Console::profileEndCallback,
&V8Console::call<&V8Console::profileEndCallback>,
"function profileEnd(title) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "clear",
V8Console::clearCallback,
&V8Console::call<&V8Console::clearCallback>,
"function clear() { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "table", V8Console::tableCallback,
context, commandLineAPI, data, "table",
&V8Console::call<&V8Console::tableCallback>,
"function table(data, [columns]) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "keys",
V8Console::keysCallback,
&V8Console::call<&V8Console::keysCallback>,
"function keys(object) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "values",
V8Console::valuesCallback,
&V8Console::call<&V8Console::valuesCallback>,
"function values(object) { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "debug", V8Console::debugFunctionCallback,
context, commandLineAPI, data, "debug",
&V8Console::call<&V8Console::debugFunctionCallback>,
"function debug(function) { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "undebug",
V8Console::undebugFunctionCallback,
&V8Console::call<&V8Console::undebugFunctionCallback>,
"function undebug(function) { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "monitor",
V8Console::monitorFunctionCallback,
&V8Console::call<&V8Console::monitorFunctionCallback>,
"function monitor(function) { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "unmonitor",
V8Console::unmonitorFunctionCallback,
&V8Console::call<&V8Console::unmonitorFunctionCallback>,
"function unmonitor(function) { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "inspect", V8Console::inspectCallback,
context, commandLineAPI, data, "inspect",
&V8Console::call<&V8Console::inspectCallback>,
"function inspect(object) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "copy",
V8Console::copyCallback,
&V8Console::call<&V8Console::copyCallback>,
"function copy(value) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "$_",
V8Console::lastEvaluationResultCallback);
createBoundFunctionProperty(
context, commandLineAPI, data, "$_",
&V8Console::call<&V8Console::lastEvaluationResultCallback>);
createBoundFunctionProperty(context, commandLineAPI, data, "$0",
V8Console::inspectedObject0);
&V8Console::call<&V8Console::inspectedObject0>);
createBoundFunctionProperty(context, commandLineAPI, data, "$1",
V8Console::inspectedObject1);
&V8Console::call<&V8Console::inspectedObject1>);
createBoundFunctionProperty(context, commandLineAPI, data, "$2",
V8Console::inspectedObject2);
&V8Console::call<&V8Console::inspectedObject2>);
createBoundFunctionProperty(context, commandLineAPI, data, "$3",
V8Console::inspectedObject3);
&V8Console::call<&V8Console::inspectedObject3>);
createBoundFunctionProperty(context, commandLineAPI, data, "$4",
V8Console::inspectedObject4);
&V8Console::call<&V8Console::inspectedObject4>);
inspectedContext->inspector()->client()->installAdditionalCommandLineAPI(
context, commandLineAPI);
m_inspector->client()->installAdditionalCommandLineAPI(context,
commandLineAPI);
return commandLineAPI;
}
......
......@@ -18,11 +18,10 @@ class V8InspectorImpl;
// https://console.spec.whatwg.org/#console-interface
class V8Console {
public:
static v8::Local<v8::Object> createConsole(InspectedContext*);
static v8::Local<v8::Object> createCommandLineAPI(InspectedContext*);
static void installMemoryGetter(V8InspectorImpl* inspector,
v8::Local<v8::Context> context,
v8::Local<v8::Object> console);
v8::Local<v8::Object> createConsole(v8::Local<v8::Context> context);
v8::Local<v8::Object> createCommandLineAPI(v8::Local<v8::Context> context);
void installMemoryGetter(v8::Local<v8::Context> context,
v8::Local<v8::Object> console);
class CommandLineAPIScope {
public:
......@@ -47,72 +46,74 @@ class V8Console {
DISALLOW_COPY_AND_ASSIGN(CommandLineAPIScope);
};
explicit V8Console(V8InspectorImpl* inspector);
private:
static void debugCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void errorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void infoCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void logCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void warnCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void dirCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void dirxmlCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void tableCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void traceCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void groupCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void groupCollapsedCallback(
const v8::FunctionCallbackInfo<v8::Value>&);
static void groupEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void clearCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void countCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void assertCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void markTimelineCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void profileCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void profileEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void timelineCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void timelineEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void timeCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void timeStampCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void debugCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void errorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void infoCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void logCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void warnCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void dirCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void dirxmlCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void tableCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void traceCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void groupCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void groupCollapsedCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void groupEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void clearCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void countCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void assertCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void markTimelineCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void profileCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void profileEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timelineCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timelineEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timeCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timeStampCallback(const v8::FunctionCallbackInfo<v8::Value>&);
template <void (V8Console::*func)(const v8::FunctionCallbackInfo<v8::Value>&)>
static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
V8Console* console =
static_cast<V8Console*>(info.Data().As<v8::External>()->Value());
(console->*func)(info);
}
// TODO(foolip): There is no spec for the Memory Info API, see blink-dev:
// https://groups.google.com/a/chromium.org/d/msg/blink-dev/g5YRCGpC9vs/b4OJz71NmPwJ
static void memoryGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void memorySetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void memoryGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void memorySetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
// CommandLineAPI
static void keysCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void valuesCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void debugFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void undebugFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>&);
static void monitorFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>&);
static void unmonitorFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>&);
static void lastEvaluationResultCallback(
const v8::FunctionCallbackInfo<v8::Value>&);
static void inspectCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void copyCallback(const v8::FunctionCallbackInfo<v8::Value>&);
static void inspectedObject(const v8::FunctionCallbackInfo<v8::Value>&,
unsigned num);
static void inspectedObject0(
const v8::FunctionCallbackInfo<v8::Value>& info) {
void keysCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void valuesCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void debugFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void undebugFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void monitorFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void unmonitorFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void lastEvaluationResultCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void inspectCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void copyCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void inspectedObject(const v8::FunctionCallbackInfo<v8::Value>&,
unsigned num);
void inspectedObject0(const v8::FunctionCallbackInfo<v8::Value>& info) {
inspectedObject(info, 0);
}
static void inspectedObject1(
const v8::FunctionCallbackInfo<v8::Value>& info) {
void inspectedObject1(const v8::FunctionCallbackInfo<v8::Value>& info) {
inspectedObject(info, 1);
}
static void inspectedObject2(
const v8::FunctionCallbackInfo<v8::Value>& info) {
void inspectedObject2(const v8::FunctionCallbackInfo<v8::Value>& info) {
inspectedObject(info, 2);
}
static void inspectedObject3(
const v8::FunctionCallbackInfo<v8::Value>& info) {
void inspectedObject3(const v8::FunctionCallbackInfo<v8::Value>& info) {
inspectedObject(info, 3);
}
static void inspectedObject4(
const v8::FunctionCallbackInfo<v8::Value>& info) {
void inspectedObject4(const v8::FunctionCallbackInfo<v8::Value>& info) {
inspectedObject(info, 4);
}
V8InspectorImpl* m_inspector;
};
} // namespace v8_inspector
......
......@@ -34,6 +34,7 @@
#include "src/inspector/string-util.h"
#include "src/inspector/v8-console-agent-impl.h"
#include "src/inspector/v8-console-message.h"
#include "src/inspector/v8-console.h"
#include "src/inspector/v8-debugger-agent-impl.h"
#include "src/inspector/v8-debugger.h"
#include "src/inspector/v8-inspector-session-impl.h"
......@@ -335,4 +336,9 @@ V8InspectorSessionImpl* V8InspectorImpl::sessionForContextGroup(
return iter == m_sessions.end() ? nullptr : iter->second;
}
V8Console* V8InspectorImpl::console() {
if (!m_console) m_console.reset(new V8Console(this));
return m_console.get();
}
} // namespace v8_inspector
......@@ -41,6 +41,7 @@
namespace v8_inspector {
class InspectedContext;
class V8Console;
class V8ConsoleMessageStorage;
class V8Debugger;
class V8DebuggerAgentImpl;
......@@ -111,6 +112,7 @@ class V8InspectorImpl : public V8Inspector {
V8DebuggerAgentImpl* enabledDebuggerAgentForGroup(int contextGroupId);
V8RuntimeAgentImpl* enabledRuntimeAgentForGroup(int contextGroupId);
V8ProfilerAgentImpl* enabledProfilerAgentForGroup(int contextGroupId);
V8Console* console();
private:
v8::Isolate* m_isolate;
......@@ -137,6 +139,8 @@ class V8InspectorImpl : public V8Inspector {
protocol::HashMap<int, int> m_contextIdToGroupIdMap;
std::unique_ptr<V8Console> m_console;
DISALLOW_COPY_AND_ASSIGN(V8InspectorImpl);
};
......
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