[inspector] introduced console.context
console.context(name:string) method returns console instance, this console instance fully implements console interface (including fact that any method can be called without console as receiver). Protocol.Runtime.consoleAPICalled notification contains additional context:string field: - "anonymous#unique-id" for any method call on unnamed console context, - "name#unique-id" for any method call on named console context. console.count and console.timeEnd have context as a scope. console.clear clear all messages regardless on what context instance it was called. console calls is ~10% slower with this CL since we need to store and then fetch console_context_id and console_context_name from function object. We recently (in April) made console calls twice faster so 10% doesn't sound critical and existing of console.log call in hot code is problem by itself. R=pfeldman@chromium.org Bug: chromium:728767 Change-Id: I5fc73216fb8b28bfe1e8c2c1b393ebfbe43cd02e Reviewed-on: https://chromium-review.googlesource.com/522128 Reviewed-by: Igor Sheludko <ishell@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#45864}
This commit is contained in:
parent
33871053cd
commit
701d79d08a
@ -2627,6 +2627,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
||||
false, NONE);
|
||||
SimpleInstallFunction(console, "timeStamp", Builtins::kConsoleTimeStamp, 1,
|
||||
false, NONE);
|
||||
SimpleInstallFunction(console, "context", Builtins::kConsoleContext, 1,
|
||||
true, NONE);
|
||||
JSObject::AddProperty(
|
||||
console, factory->to_string_tag_symbol(),
|
||||
factory->NewStringFromAsciiChecked("Object"),
|
||||
|
@ -14,45 +14,113 @@ namespace internal {
|
||||
// -----------------------------------------------------------------------------
|
||||
// Console
|
||||
|
||||
#define CONSOLE_METHOD_LIST(V) \
|
||||
V(Debug) \
|
||||
V(Error) \
|
||||
V(Info) \
|
||||
V(Log) \
|
||||
V(Warn) \
|
||||
V(Dir) \
|
||||
V(DirXml) \
|
||||
V(Table) \
|
||||
V(Trace) \
|
||||
V(Group) \
|
||||
V(GroupCollapsed) \
|
||||
V(GroupEnd) \
|
||||
V(Clear) \
|
||||
V(Count) \
|
||||
V(Assert) \
|
||||
V(MarkTimeline) \
|
||||
V(Profile) \
|
||||
V(ProfileEnd) \
|
||||
V(Timeline) \
|
||||
V(TimelineEnd) \
|
||||
V(Time) \
|
||||
V(TimeEnd) \
|
||||
V(TimeStamp)
|
||||
#define CONSOLE_METHOD_LIST(V) \
|
||||
V(Debug, debug) \
|
||||
V(Error, error) \
|
||||
V(Info, info) \
|
||||
V(Log, log) \
|
||||
V(Warn, warn) \
|
||||
V(Dir, dir) \
|
||||
V(DirXml, dirXml) \
|
||||
V(Table, table) \
|
||||
V(Trace, trace) \
|
||||
V(Group, group) \
|
||||
V(GroupCollapsed, groupCollapsed) \
|
||||
V(GroupEnd, groupEnd) \
|
||||
V(Clear, clear) \
|
||||
V(Count, count) \
|
||||
V(Assert, assert) \
|
||||
V(MarkTimeline, markTimeline) \
|
||||
V(Profile, profile) \
|
||||
V(ProfileEnd, profileEnd) \
|
||||
V(Timeline, timeline) \
|
||||
V(TimelineEnd, timelineEnd) \
|
||||
V(Time, time) \
|
||||
V(TimeEnd, timeEnd) \
|
||||
V(TimeStamp, timeStamp)
|
||||
|
||||
#define CONSOLE_BUILTIN_IMPLEMENTATION(name) \
|
||||
BUILTIN(Console##name) { \
|
||||
HandleScope scope(isolate); \
|
||||
if (isolate->console_delegate()) { \
|
||||
debug::ConsoleCallArguments wrapper(args); \
|
||||
isolate->console_delegate()->name(wrapper); \
|
||||
CHECK(!isolate->has_pending_exception()); \
|
||||
CHECK(!isolate->has_scheduled_exception()); \
|
||||
} \
|
||||
return isolate->heap()->undefined_value(); \
|
||||
namespace {
|
||||
void ConsoleCall(
|
||||
Isolate* isolate, internal::BuiltinArguments& args,
|
||||
void (debug::ConsoleDelegate::*func)(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext&)) {
|
||||
HandleScope scope(isolate);
|
||||
if (!isolate->console_delegate()) return;
|
||||
debug::ConsoleCallArguments wrapper(args);
|
||||
Handle<Object> context_id_obj = JSObject::GetDataProperty(
|
||||
args.target(), isolate->factory()->console_context_id_symbol());
|
||||
int context_id =
|
||||
context_id_obj->IsSmi() ? Handle<Smi>::cast(context_id_obj)->value() : 0;
|
||||
Handle<Object> context_name_obj = JSObject::GetDataProperty(
|
||||
args.target(), isolate->factory()->console_context_name_symbol());
|
||||
Handle<String> context_name = context_name_obj->IsString()
|
||||
? Handle<String>::cast(context_name_obj)
|
||||
: isolate->factory()->anonymous_string();
|
||||
(isolate->console_delegate()->*func)(
|
||||
wrapper,
|
||||
v8::debug::ConsoleContext(context_id, Utils::ToLocal(context_name)));
|
||||
CHECK(!isolate->has_pending_exception());
|
||||
CHECK(!isolate->has_scheduled_exception());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#define CONSOLE_BUILTIN_IMPLEMENTATION(call, name) \
|
||||
BUILTIN(Console##call) { \
|
||||
ConsoleCall(isolate, args, &debug::ConsoleDelegate::call); \
|
||||
return isolate->heap()->undefined_value(); \
|
||||
}
|
||||
CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_IMPLEMENTATION)
|
||||
#undef CONSOLE_BUILTIN_IMPLEMENTATION
|
||||
|
||||
namespace {
|
||||
void InstallContextFunction(Handle<JSObject> target, const char* name,
|
||||
Builtins::Name call, int context_id,
|
||||
Object* context_name) {
|
||||
Factory* const factory = target->GetIsolate()->factory();
|
||||
|
||||
Handle<Code> call_code(target->GetIsolate()->builtins()->builtin(call));
|
||||
|
||||
Handle<String> name_string =
|
||||
Name::ToFunctionName(factory->InternalizeUtf8String(name))
|
||||
.ToHandleChecked();
|
||||
Handle<JSFunction> fun =
|
||||
factory->NewFunctionWithoutPrototype(name_string, call_code, false);
|
||||
fun->shared()->set_native(true);
|
||||
fun->shared()->DontAdaptArguments();
|
||||
fun->shared()->set_length(1);
|
||||
|
||||
JSObject::AddProperty(fun, factory->console_context_id_symbol(),
|
||||
handle(Smi::FromInt(context_id), target->GetIsolate()),
|
||||
NONE);
|
||||
if (context_name->IsString()) {
|
||||
JSObject::AddProperty(fun, factory->console_context_name_symbol(),
|
||||
handle(context_name, target->GetIsolate()), NONE);
|
||||
}
|
||||
JSObject::AddProperty(target, name_string, fun, NONE);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BUILTIN(ConsoleContext) {
|
||||
HandleScope scope(isolate);
|
||||
|
||||
Factory* const factory = isolate->factory();
|
||||
Handle<String> name = factory->InternalizeUtf8String("Context");
|
||||
Handle<JSFunction> cons = factory->NewFunction(name);
|
||||
Handle<JSObject> empty = factory->NewJSObject(isolate->object_function());
|
||||
JSFunction::SetPrototype(cons, empty);
|
||||
Handle<JSObject> context = factory->NewJSObject(cons, TENURED);
|
||||
DCHECK(context->IsJSObject());
|
||||
int id = isolate->last_console_context_id() + 1;
|
||||
isolate->set_last_console_context_id(id);
|
||||
|
||||
#define CONSOLE_BUILTIN_SETUP(call, name) \
|
||||
InstallContextFunction(context, #name, Builtins::kConsole##call, id, args[1]);
|
||||
CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_SETUP)
|
||||
#undef CONSOLE_BUILTIN_SETUP
|
||||
|
||||
return *context;
|
||||
}
|
||||
|
||||
#undef CONSOLE_METHOD_LIST
|
||||
|
||||
} // namespace internal
|
||||
|
@ -405,6 +405,7 @@ namespace internal {
|
||||
CPP(ConsoleTime) \
|
||||
CPP(ConsoleTimeEnd) \
|
||||
CPP(ConsoleTimeStamp) \
|
||||
CPP(ConsoleContext) \
|
||||
\
|
||||
/* DataView */ \
|
||||
CPP(DataViewConstructor) \
|
||||
|
@ -40,27 +40,33 @@ D8Console::D8Console(Isolate* isolate) : isolate_(isolate) {
|
||||
default_timer_ = base::TimeTicks::HighResolutionNow();
|
||||
}
|
||||
|
||||
void D8Console::Log(const debug::ConsoleCallArguments& args) {
|
||||
void D8Console::Log(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) {
|
||||
WriteToFile(stdout, isolate_, args);
|
||||
}
|
||||
|
||||
void D8Console::Error(const debug::ConsoleCallArguments& args) {
|
||||
void D8Console::Error(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) {
|
||||
WriteToFile(stderr, isolate_, args);
|
||||
}
|
||||
|
||||
void D8Console::Warn(const debug::ConsoleCallArguments& args) {
|
||||
void D8Console::Warn(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) {
|
||||
WriteToFile(stdout, isolate_, args);
|
||||
}
|
||||
|
||||
void D8Console::Info(const debug::ConsoleCallArguments& args) {
|
||||
void D8Console::Info(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) {
|
||||
WriteToFile(stdout, isolate_, args);
|
||||
}
|
||||
|
||||
void D8Console::Debug(const debug::ConsoleCallArguments& args) {
|
||||
void D8Console::Debug(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) {
|
||||
WriteToFile(stdout, isolate_, args);
|
||||
}
|
||||
|
||||
void D8Console::Time(const debug::ConsoleCallArguments& args) {
|
||||
void D8Console::Time(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) {
|
||||
if (args.Length() == 0) {
|
||||
default_timer_ = base::TimeTicks::HighResolutionNow();
|
||||
} else {
|
||||
@ -83,7 +89,8 @@ void D8Console::Time(const debug::ConsoleCallArguments& args) {
|
||||
}
|
||||
}
|
||||
|
||||
void D8Console::TimeEnd(const debug::ConsoleCallArguments& args) {
|
||||
void D8Console::TimeEnd(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) {
|
||||
base::TimeDelta delta;
|
||||
base::TimeTicks now = base::TimeTicks::HighResolutionNow();
|
||||
if (args.Length() == 0) {
|
||||
|
@ -16,13 +16,20 @@ class D8Console : public debug::ConsoleDelegate {
|
||||
explicit D8Console(Isolate* isolate);
|
||||
|
||||
private:
|
||||
void Log(const debug::ConsoleCallArguments& args) override;
|
||||
void Error(const debug::ConsoleCallArguments& args) override;
|
||||
void Warn(const debug::ConsoleCallArguments& args) override;
|
||||
void Info(const debug::ConsoleCallArguments& args) override;
|
||||
void Debug(const debug::ConsoleCallArguments& args) override;
|
||||
void Time(const debug::ConsoleCallArguments& args) override;
|
||||
void TimeEnd(const debug::ConsoleCallArguments& args) override;
|
||||
void Log(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) override;
|
||||
void Error(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) override;
|
||||
void Warn(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) override;
|
||||
void Info(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) override;
|
||||
void Debug(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) override;
|
||||
void Time(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) override;
|
||||
void TimeEnd(const debug::ConsoleCallArguments& args,
|
||||
const v8::debug::ConsoleContext&) override;
|
||||
|
||||
Isolate* isolate_;
|
||||
std::map<std::string, base::TimeTicks> timers_;
|
||||
|
@ -106,33 +106,67 @@ class ConsoleCallArguments : private v8::FunctionCallbackInfo<v8::Value> {
|
||||
explicit ConsoleCallArguments(internal::BuiltinArguments&);
|
||||
};
|
||||
|
||||
// v8::FunctionCallbackInfo could be used for getting arguments only. Calling
|
||||
// of any other getter will produce a crash.
|
||||
class ConsoleContext {
|
||||
public:
|
||||
ConsoleContext(int id, v8::Local<v8::String> name) : id_(id), name_(name) {}
|
||||
ConsoleContext() : id_(0) {}
|
||||
|
||||
int id() const { return id_; }
|
||||
v8::Local<v8::String> name() const { return name_; }
|
||||
|
||||
private:
|
||||
int id_;
|
||||
v8::Local<v8::String> name_;
|
||||
};
|
||||
|
||||
class ConsoleDelegate {
|
||||
public:
|
||||
virtual void Debug(const ConsoleCallArguments& args) {}
|
||||
virtual void Error(const ConsoleCallArguments& args) {}
|
||||
virtual void Info(const ConsoleCallArguments& args) {}
|
||||
virtual void Log(const ConsoleCallArguments& args) {}
|
||||
virtual void Warn(const ConsoleCallArguments& args) {}
|
||||
virtual void Dir(const ConsoleCallArguments& args) {}
|
||||
virtual void DirXml(const ConsoleCallArguments& args) {}
|
||||
virtual void Table(const ConsoleCallArguments& args) {}
|
||||
virtual void Trace(const ConsoleCallArguments& args) {}
|
||||
virtual void Group(const ConsoleCallArguments& args) {}
|
||||
virtual void GroupCollapsed(const ConsoleCallArguments& args) {}
|
||||
virtual void GroupEnd(const ConsoleCallArguments& args) {}
|
||||
virtual void Clear(const ConsoleCallArguments& args) {}
|
||||
virtual void Count(const ConsoleCallArguments& args) {}
|
||||
virtual void Assert(const ConsoleCallArguments& args) {}
|
||||
virtual void MarkTimeline(const ConsoleCallArguments& args) {}
|
||||
virtual void Profile(const ConsoleCallArguments& args) {}
|
||||
virtual void ProfileEnd(const ConsoleCallArguments& args) {}
|
||||
virtual void Timeline(const ConsoleCallArguments& args) {}
|
||||
virtual void TimelineEnd(const ConsoleCallArguments& args) {}
|
||||
virtual void Time(const ConsoleCallArguments& args) {}
|
||||
virtual void TimeEnd(const ConsoleCallArguments& args) {}
|
||||
virtual void TimeStamp(const ConsoleCallArguments& args) {}
|
||||
virtual void Debug(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Error(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Info(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Log(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Warn(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Dir(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void DirXml(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Table(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Trace(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Group(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void GroupCollapsed(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void GroupEnd(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Clear(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Count(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Assert(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void MarkTimeline(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Profile(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void ProfileEnd(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Timeline(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void TimelineEnd(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void Time(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void TimeEnd(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual void TimeStamp(const ConsoleCallArguments& args,
|
||||
const ConsoleContext& context) {}
|
||||
virtual ~ConsoleDelegate() = default;
|
||||
};
|
||||
|
||||
|
@ -201,6 +201,8 @@
|
||||
V(array_iterator_object_symbol) \
|
||||
V(call_site_frame_array_symbol) \
|
||||
V(call_site_frame_index_symbol) \
|
||||
V(console_context_id_symbol) \
|
||||
V(console_context_name_symbol) \
|
||||
V(class_end_position_symbol) \
|
||||
V(class_start_position_symbol) \
|
||||
V(detailed_stack_trace_symbol) \
|
||||
|
@ -388,7 +388,8 @@
|
||||
{ "name": "args", "type": "array", "items": { "$ref": "RemoteObject" }, "description": "Call arguments." },
|
||||
{ "name": "executionContextId", "$ref": "ExecutionContextId", "description": "Identifier of the context where the call was made." },
|
||||
{ "name": "timestamp", "$ref": "Timestamp", "description": "Call timestamp." },
|
||||
{ "name": "stackTrace", "$ref": "StackTrace", "optional": true, "description": "Stack trace captured when the call was made." }
|
||||
{ "name": "stackTrace", "$ref": "StackTrace", "optional": true, "description": "Stack trace captured when the call was made." },
|
||||
{ "name": "context", "type": "string", "optional": true, "experimental": true, "description": "Console context descriptor for calls on non-default console context (not console.*): 'anonymous#unique-logger-id' for call on unnamed context, 'name#unique-logger-id' for call on named context." }
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -321,10 +321,13 @@ void V8ConsoleMessage::reportToFrontend(protocol::Runtime::Frontend* frontend,
|
||||
arguments->addItem(std::move(messageArg));
|
||||
}
|
||||
}
|
||||
Maybe<String16> consoleContext;
|
||||
if (!m_consoleContext.isEmpty()) consoleContext = m_consoleContext;
|
||||
frontend->consoleAPICalled(
|
||||
consoleAPITypeValue(m_type), std::move(arguments), m_contextId,
|
||||
m_timestamp,
|
||||
m_stackTrace ? m_stackTrace->buildInspectorObjectImpl() : nullptr);
|
||||
m_stackTrace ? m_stackTrace->buildInspectorObjectImpl() : nullptr,
|
||||
std::move(consoleContext));
|
||||
return;
|
||||
}
|
||||
UNREACHABLE();
|
||||
@ -356,6 +359,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
|
||||
v8::Local<v8::Context> v8Context, int contextId, int groupId,
|
||||
V8InspectorImpl* inspector, double timestamp, ConsoleAPIType type,
|
||||
const std::vector<v8::Local<v8::Value>>& arguments,
|
||||
const String16& consoleContext,
|
||||
std::unique_ptr<V8StackTraceImpl> stackTrace) {
|
||||
v8::Isolate* isolate = v8Context->GetIsolate();
|
||||
|
||||
@ -367,6 +371,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
|
||||
message->m_columnNumber = stackTrace->topColumnNumber();
|
||||
}
|
||||
message->m_stackTrace = std::move(stackTrace);
|
||||
message->m_consoleContext = consoleContext;
|
||||
message->m_type = type;
|
||||
message->m_contextId = contextId;
|
||||
for (size_t i = 0; i < arguments.size(); ++i) {
|
||||
|
@ -49,7 +49,7 @@ class V8ConsoleMessage {
|
||||
v8::Local<v8::Context> v8Context, int contextId, int groupId,
|
||||
V8InspectorImpl* inspector, double timestamp, ConsoleAPIType,
|
||||
const std::vector<v8::Local<v8::Value>>& arguments,
|
||||
std::unique_ptr<V8StackTraceImpl>);
|
||||
const String16& consoleContext, std::unique_ptr<V8StackTraceImpl>);
|
||||
|
||||
static std::unique_ptr<V8ConsoleMessage> createForException(
|
||||
double timestamp, const String16& detailedMessage, const String16& url,
|
||||
@ -99,6 +99,7 @@ class V8ConsoleMessage {
|
||||
int m_v8Size = 0;
|
||||
Arguments m_arguments;
|
||||
String16 m_detailedMessage;
|
||||
String16 m_consoleContext;
|
||||
};
|
||||
|
||||
class V8ConsoleMessageStorage {
|
||||
|
@ -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),
|
||||
@ -79,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));
|
||||
}
|
||||
@ -134,6 +144,7 @@ class ConsoleHelper {
|
||||
|
||||
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;
|
||||
@ -178,72 +189,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()) {
|
||||
@ -256,6 +290,7 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info) {
|
||||
} else {
|
||||
identifier = title + "@";
|
||||
}
|
||||
identifier = consoleContextToString(consoleContext) + "@" + identifier;
|
||||
|
||||
int count =
|
||||
helper.consoleMessageStorage()->count(helper.contextId(), identifier);
|
||||
@ -265,8 +300,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;
|
||||
@ -278,25 +314,28 @@ void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) {
|
||||
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);
|
||||
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);
|
||||
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()));
|
||||
@ -304,54 +343,64 @@ void V8Console::ProfileEnd(const v8::debug::ConsoleCallArguments& info) {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
@ -380,7 +429,7 @@ void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
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;
|
||||
@ -395,7 +444,7 @@ void V8Console::valuesCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
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;
|
||||
@ -438,7 +487,7 @@ static void setFunctionBreakpoint(ConsoleHelper& helper, int sessionId,
|
||||
void V8Console::debugFunctionCallback(
|
||||
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, sessionId, function,
|
||||
@ -449,7 +498,7 @@ void V8Console::debugFunctionCallback(
|
||||
void V8Console::undebugFunctionCallback(
|
||||
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, sessionId, function,
|
||||
@ -460,7 +509,7 @@ void V8Console::undebugFunctionCallback(
|
||||
void V8Console::monitorFunctionCallback(
|
||||
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();
|
||||
@ -484,7 +533,7 @@ void V8Console::monitorFunctionCallback(
|
||||
void V8Console::unmonitorFunctionCallback(
|
||||
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, sessionId, function,
|
||||
@ -495,7 +544,7 @@ void V8Console::unmonitorFunctionCallback(
|
||||
void V8Console::lastEvaluationResultCallback(
|
||||
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);
|
||||
InjectedScript* injectedScript = helper.injectedScript(sessionId);
|
||||
if (!injectedScript) return;
|
||||
info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
|
||||
@ -508,7 +557,7 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
|
||||
|
||||
v8::debug::ConsoleCallArguments args(info);
|
||||
ConsoleHelper helper(args, inspector);
|
||||
ConsoleHelper helper(args, v8::debug::ConsoleContext(), inspector);
|
||||
InjectedScript* injectedScript = helper.injectedScript(sessionId);
|
||||
if (!injectedScript) return;
|
||||
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
|
||||
@ -540,7 +589,7 @@ void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
int sessionId, unsigned num) {
|
||||
DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize);
|
||||
v8::debug::ConsoleCallArguments args(info);
|
||||
ConsoleHelper helper(args, m_inspector);
|
||||
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();
|
||||
|
@ -50,29 +50,52 @@ class V8Console : public v8::debug::ConsoleDelegate {
|
||||
explicit V8Console(V8InspectorImpl* inspector);
|
||||
|
||||
private:
|
||||
void Debug(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Error(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Info(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Log(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Warn(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Dir(const v8::debug::ConsoleCallArguments&) override;
|
||||
void DirXml(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Table(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Trace(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Group(const v8::debug::ConsoleCallArguments&) override;
|
||||
void GroupCollapsed(const v8::debug::ConsoleCallArguments&) override;
|
||||
void GroupEnd(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Clear(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Count(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Assert(const v8::debug::ConsoleCallArguments&) override;
|
||||
void MarkTimeline(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Profile(const v8::debug::ConsoleCallArguments&) override;
|
||||
void ProfileEnd(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Timeline(const v8::debug::ConsoleCallArguments&) override;
|
||||
void TimelineEnd(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Time(const v8::debug::ConsoleCallArguments&) override;
|
||||
void TimeEnd(const v8::debug::ConsoleCallArguments&) override;
|
||||
void TimeStamp(const v8::debug::ConsoleCallArguments&) override;
|
||||
void Debug(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Error(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Info(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Log(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Warn(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Dir(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void DirXml(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Table(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Trace(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Group(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void GroupCollapsed(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void GroupEnd(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Clear(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Count(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Assert(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void MarkTimeline(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Profile(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void ProfileEnd(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Timeline(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void TimelineEnd(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void Time(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void TimeEnd(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
void TimeStamp(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext& consoleContext) override;
|
||||
|
||||
template <void (V8Console::*func)(const v8::FunctionCallbackInfo<v8::Value>&)>
|
||||
static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
||||
@ -88,12 +111,13 @@ class V8Console : public v8::debug::ConsoleDelegate {
|
||||
info.Data().As<v8::External>()->Value());
|
||||
(data->first->*func)(info, data->second);
|
||||
}
|
||||
template <void (V8Console::*func)(const v8::debug::ConsoleCallArguments&)>
|
||||
template <void (V8Console::*func)(const v8::debug::ConsoleCallArguments&,
|
||||
const v8::debug::ConsoleContext&)>
|
||||
static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
||||
CommandLineAPIData* data = static_cast<CommandLineAPIData*>(
|
||||
info.Data().As<v8::External>()->Value());
|
||||
v8::debug::ConsoleCallArguments args(info);
|
||||
(data->first->*func)(args);
|
||||
(data->first->*func)(args, v8::debug::ConsoleContext());
|
||||
}
|
||||
|
||||
// TODO(foolip): There is no spec for the Memory Info API, see blink-dev:
|
||||
|
@ -439,6 +439,7 @@ typedef std::vector<HeapObject*> DebugObjectCache;
|
||||
/* Current code coverage mode */ \
|
||||
V(debug::Coverage::Mode, code_coverage_mode, debug::Coverage::kBestEffort) \
|
||||
V(int, last_stack_frame_info_id, 0) \
|
||||
V(int, last_console_context_id, 0) \
|
||||
ISOLATE_INIT_SIMULATOR_LIST(V)
|
||||
|
||||
#define THREAD_LOCAL_TOP_ACCESSOR(type, name) \
|
||||
|
83
test/inspector/runtime/console-context-expected.txt
Normal file
83
test/inspector/runtime/console-context-expected.txt
Normal file
@ -0,0 +1,83 @@
|
||||
Tests console.context
|
||||
|
||||
Running test: testConsoleContextMethod
|
||||
console.context description:
|
||||
{
|
||||
className : Function
|
||||
description : function context() { [native code] }
|
||||
objectId : <objectId>
|
||||
type : function
|
||||
}
|
||||
console.context() methods:
|
||||
[
|
||||
[0] : debug
|
||||
[1] : error
|
||||
[2] : info
|
||||
[3] : log
|
||||
[4] : warn
|
||||
[5] : dir
|
||||
[6] : dirXml
|
||||
[7] : table
|
||||
[8] : trace
|
||||
[9] : group
|
||||
[10] : groupCollapsed
|
||||
[11] : groupEnd
|
||||
[12] : clear
|
||||
[13] : count
|
||||
[14] : assert
|
||||
[15] : markTimeline
|
||||
[16] : profile
|
||||
[17] : profileEnd
|
||||
[18] : timeline
|
||||
[19] : timelineEnd
|
||||
[20] : time
|
||||
[21] : timeEnd
|
||||
[22] : timeStamp
|
||||
]
|
||||
|
||||
Running test: testDefaultConsoleContext
|
||||
undefined
|
||||
undefined
|
||||
undefined
|
||||
|
||||
Running test: testAnonymousConsoleContext
|
||||
anonymous#2
|
||||
anonymous#3
|
||||
anonymous#4
|
||||
|
||||
Running test: testNamedConsoleContext
|
||||
named-context#6
|
||||
named-context#6
|
||||
named-context#6
|
||||
|
||||
Running test: testTwoConsoleContextsWithTheSameName
|
||||
named-context#7
|
||||
named-context#8
|
||||
|
||||
Running test: testConsoleCountInDifferentConsoleContexts
|
||||
[
|
||||
[0] : {
|
||||
type : string
|
||||
value : 239: 1
|
||||
}
|
||||
]
|
||||
[
|
||||
[0] : {
|
||||
type : string
|
||||
value : 239: 1
|
||||
}
|
||||
]
|
||||
|
||||
Running test: testConsoleCountForNamedConsoleContext
|
||||
[
|
||||
[0] : {
|
||||
type : string
|
||||
value : 239: 1
|
||||
}
|
||||
]
|
||||
[
|
||||
[0] : {
|
||||
type : string
|
||||
value : 239: 2
|
||||
}
|
||||
]
|
106
test/inspector/runtime/console-context.js
Normal file
106
test/inspector/runtime/console-context.js
Normal file
@ -0,0 +1,106 @@
|
||||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
let {session, contextGroup, Protocol} = InspectorTest.start('Tests console.context');
|
||||
|
||||
InspectorTest.runAsyncTestSuite([
|
||||
async function testConsoleContextMethod() {
|
||||
InspectorTest.log('console.context description:');
|
||||
var {result:{result}} = await Protocol.Runtime.evaluate({
|
||||
expression: 'console.context'});
|
||||
InspectorTest.logMessage(result);
|
||||
|
||||
InspectorTest.log('console.context() methods:');
|
||||
var {result:{result:{value}}} = await Protocol.Runtime.evaluate({
|
||||
expression: 'Object.keys(console.context())', returnByValue: true});
|
||||
InspectorTest.logMessage(value);
|
||||
},
|
||||
|
||||
async function testDefaultConsoleContext() {
|
||||
await Protocol.Runtime.enable();
|
||||
Protocol.Runtime.evaluate({expression: 'console.log(239)'});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
Protocol.Runtime.evaluate({expression: 'console.info(239)'});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
Protocol.Runtime.evaluate({expression: 'console.debug(239)'});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
|
||||
await Protocol.Runtime.disable();
|
||||
},
|
||||
|
||||
async function testAnonymousConsoleContext() {
|
||||
await Protocol.Runtime.enable();
|
||||
Protocol.Runtime.evaluate({expression: 'console.context().log(239)'});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
Protocol.Runtime.evaluate({expression: 'console.context().info(239)'});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
Protocol.Runtime.evaluate({expression: 'console.context().debug(239)'});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
await Protocol.Runtime.evaluate({expression: 'console.context().clear()'});
|
||||
await Protocol.Runtime.disable();
|
||||
},
|
||||
|
||||
async function testNamedConsoleContext() {
|
||||
await Protocol.Runtime.enable();
|
||||
Protocol.Runtime.evaluate({expression: `
|
||||
var context = console.context('named-context');
|
||||
context.log(239);
|
||||
context.info(239);
|
||||
context.debug(239);
|
||||
`});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
|
||||
await Protocol.Runtime.disable();
|
||||
},
|
||||
|
||||
async function testTwoConsoleContextsWithTheSameName() {
|
||||
await Protocol.Runtime.enable();
|
||||
Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').log(239)'});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').log(239)'});
|
||||
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.log(context);
|
||||
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
|
||||
await Protocol.Runtime.disable();
|
||||
},
|
||||
|
||||
async function testConsoleCountInDifferentConsoleContexts() {
|
||||
await Protocol.Runtime.enable();
|
||||
Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').count(239)'});
|
||||
var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.logMessage(args);
|
||||
Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').count(239)'});
|
||||
var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.logMessage(args);
|
||||
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
|
||||
await Protocol.Runtime.disable();
|
||||
},
|
||||
|
||||
async function testConsoleCountForNamedConsoleContext() {
|
||||
await Protocol.Runtime.enable();
|
||||
Protocol.Runtime.evaluate({expression: `
|
||||
var context = console.context('named-context');
|
||||
context.count(239);
|
||||
context.count(239);
|
||||
`});
|
||||
var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.logMessage(args);
|
||||
var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
|
||||
InspectorTest.logMessage(args);
|
||||
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
|
||||
await Protocol.Runtime.disable();
|
||||
}
|
||||
]);
|
Loading…
Reference in New Issue
Block a user