Commit c9a728aa authored by Dominic Farolino's avatar Dominic Farolino Committed by Commit Bot

[inspector] implement console.countReset()

Implement console.countReset() from the WHATWG Console Standard

R=bmeurer@chromium.org, dgozman@chromium.org, kozyatinskiy@chromium.org

Bug: chromium:839947
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I8a900e9cdf3e5b08506f709cf6497476c8c6c00b
Reviewed-on: https://chromium-review.googlesource.com/1044902Reviewed-by: 's avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Dominic Farolino <domfarolino@gmail.com>
Cr-Commit-Position: refs/heads/master@{#53106}
parent 8f1c90d2
...@@ -62,6 +62,7 @@ Daniel Andersson <kodandersson@gmail.com> ...@@ -62,6 +62,7 @@ Daniel Andersson <kodandersson@gmail.com>
Daniel Bevenius <daniel.bevenius@gmail.com> Daniel Bevenius <daniel.bevenius@gmail.com>
Daniel James <dnljms@gmail.com> Daniel James <dnljms@gmail.com>
Deon Dior <diaoyuanjie@gmail.com> Deon Dior <diaoyuanjie@gmail.com>
Dominic Farolini <domfarolino@gmail.com>
Douglas Crosher <dtc-v8@scieneer.com> Douglas Crosher <dtc-v8@scieneer.com>
Dusan Milosavljevic <dusan.m.milosavljevic@gmail.com> Dusan Milosavljevic <dusan.m.milosavljevic@gmail.com>
Erich Ocean <erich.ocean@me.com> Erich Ocean <erich.ocean@me.com>
......
...@@ -2686,6 +2686,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2686,6 +2686,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
NONE); NONE);
SimpleInstallFunction(console, "count", Builtins::kConsoleCount, 1, false, SimpleInstallFunction(console, "count", Builtins::kConsoleCount, 1, false,
NONE); NONE);
SimpleInstallFunction(console, "countReset", Builtins::kConsoleCountReset,
1, false, NONE);
SimpleInstallFunction(console, "assert", Builtins::kFastConsoleAssert, 1, SimpleInstallFunction(console, "assert", Builtins::kFastConsoleAssert, 1,
false, NONE); false, NONE);
SimpleInstallFunction(console, "markTimeline", SimpleInstallFunction(console, "markTimeline",
......
...@@ -30,6 +30,7 @@ namespace internal { ...@@ -30,6 +30,7 @@ namespace internal {
V(GroupEnd, groupEnd) \ V(GroupEnd, groupEnd) \
V(Clear, clear) \ V(Clear, clear) \
V(Count, count) \ V(Count, count) \
V(CountReset, countReset) \
V(Assert, assert) \ V(Assert, assert) \
V(MarkTimeline, markTimeline) \ V(MarkTimeline, markTimeline) \
V(Profile, profile) \ V(Profile, profile) \
......
...@@ -431,6 +431,7 @@ namespace internal { ...@@ -431,6 +431,7 @@ namespace internal {
CPP(ConsoleGroupEnd) \ CPP(ConsoleGroupEnd) \
CPP(ConsoleClear) \ CPP(ConsoleClear) \
CPP(ConsoleCount) \ CPP(ConsoleCount) \
CPP(ConsoleCountReset) \
CPP(ConsoleAssert) \ CPP(ConsoleAssert) \
TFJ(FastConsoleAssert, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \ TFJ(FastConsoleAssert, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
CPP(ConsoleMarkTimeline) \ CPP(ConsoleMarkTimeline) \
......
...@@ -150,6 +150,8 @@ class ConsoleDelegate { ...@@ -150,6 +150,8 @@ class ConsoleDelegate {
const ConsoleContext& context) {} const ConsoleContext& context) {}
virtual void Count(const ConsoleCallArguments& args, virtual void Count(const ConsoleCallArguments& args,
const ConsoleContext& context) {} const ConsoleContext& context) {}
virtual void CountReset(const ConsoleCallArguments& args,
const ConsoleContext& context) {}
virtual void Assert(const ConsoleCallArguments& args, virtual void Assert(const ConsoleCallArguments& args,
const ConsoleContext& context) {} const ConsoleContext& context) {}
virtual void MarkTimeline(const ConsoleCallArguments& args, virtual void MarkTimeline(const ConsoleCallArguments& args,
......
...@@ -532,6 +532,14 @@ void V8ConsoleMessageStorage::time(int contextId, const String16& id) { ...@@ -532,6 +532,14 @@ void V8ConsoleMessageStorage::time(int contextId, const String16& id) {
m_data[contextId].m_time[id] = m_inspector->client()->currentTimeMS(); m_data[contextId].m_time[id] = m_inspector->client()->currentTimeMS();
} }
bool V8ConsoleMessageStorage::countReset(int contextId, const String16& id) {
std::map<String16, int>& count_map = m_data[contextId].m_count;
if (count_map.find(id) == count_map.end()) return false;
count_map[id] = 0;
return true;
}
double V8ConsoleMessageStorage::timeEnd(int contextId, const String16& id) { double V8ConsoleMessageStorage::timeEnd(int contextId, const String16& id) {
std::map<String16, double>& time = m_data[contextId].m_time; std::map<String16, double>& time = m_data[contextId].m_time;
auto it = time.find(id); auto it = time.find(id);
......
...@@ -118,6 +118,7 @@ class V8ConsoleMessageStorage { ...@@ -118,6 +118,7 @@ class V8ConsoleMessageStorage {
bool shouldReportDeprecationMessage(int contextId, const String16& method); bool shouldReportDeprecationMessage(int contextId, const String16& method);
int count(int contextId, const String16& id); int count(int contextId, const String16& id);
bool countReset(int contextId, const String16& id);
void time(int contextId, const String16& id); void time(int contextId, const String16& id);
double timeEnd(int contextId, const String16& id); double timeEnd(int contextId, const String16& id);
bool hasTimer(int contextId, const String16& id); bool hasTimer(int contextId, const String16& id);
...@@ -130,7 +131,9 @@ class V8ConsoleMessageStorage { ...@@ -130,7 +131,9 @@ class V8ConsoleMessageStorage {
struct PerContextData { struct PerContextData {
std::set<String16> m_reportedDeprecationMessages; std::set<String16> m_reportedDeprecationMessages;
// Corresponds to https://console.spec.whatwg.org/#count-map
std::map<String16, int> m_count; std::map<String16, int> m_count;
// Corresponds to https://console.spec.whatwg.org/#timer-table
std::map<String16, double> m_time; std::map<String16, double> m_time;
}; };
std::map<int, PerContextData> m_data; std::map<int, PerContextData> m_data;
......
...@@ -282,14 +282,14 @@ void V8Console::Clear(const v8::debug::ConsoleCallArguments& info, ...@@ -282,14 +282,14 @@ void V8Console::Clear(const v8::debug::ConsoleCallArguments& info,
String16("console.clear")); String16("console.clear"));
} }
void V8Console::Count(const v8::debug::ConsoleCallArguments& info, static String16 identifierFromTitleOrStackTrace(
const v8::debug::ConsoleContext& consoleContext) { const String16& title, const ConsoleHelper& helper,
ConsoleHelper helper(info, consoleContext, m_inspector); const v8::debug::ConsoleContext& consoleContext,
String16 title = helper.firstArgToString(String16("default"), false); V8InspectorImpl* inspector) {
String16 identifier; String16 identifier;
if (title.isEmpty()) { if (title.isEmpty()) {
std::unique_ptr<V8StackTraceImpl> stackTrace = std::unique_ptr<V8StackTraceImpl> stackTrace =
V8StackTraceImpl::capture(m_inspector->debugger(), helper.groupId(), 1); V8StackTraceImpl::capture(inspector->debugger(), helper.groupId(), 1);
if (stackTrace && !stackTrace->isEmpty()) { if (stackTrace && !stackTrace->isEmpty()) {
identifier = toString16(stackTrace->topSourceURL()) + ":" + identifier = toString16(stackTrace->topSourceURL()) + ":" +
String16::fromInteger(stackTrace->topLineNumber()); String16::fromInteger(stackTrace->topLineNumber());
...@@ -299,6 +299,16 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info, ...@@ -299,6 +299,16 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info,
} }
identifier = consoleContextToString(consoleContext) + "@" + identifier; identifier = consoleContextToString(consoleContext) + "@" + identifier;
return identifier;
}
void V8Console::Count(const v8::debug::ConsoleCallArguments& info,
const v8::debug::ConsoleContext& consoleContext) {
ConsoleHelper helper(info, consoleContext, m_inspector);
String16 title = helper.firstArgToString(String16("default"), false);
String16 identifier = identifierFromTitleOrStackTrace(
title, helper, consoleContext, m_inspector);
int count = int count =
helper.consoleMessageStorage()->count(helper.contextId(), identifier); helper.consoleMessageStorage()->count(helper.contextId(), identifier);
String16 countString = String16::fromInteger(count); String16 countString = String16::fromInteger(count);
...@@ -307,6 +317,20 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info, ...@@ -307,6 +317,20 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info,
title.isEmpty() ? countString : (title + ": " + countString)); title.isEmpty() ? countString : (title + ": " + countString));
} }
void V8Console::CountReset(const v8::debug::ConsoleCallArguments& info,
const v8::debug::ConsoleContext& consoleContext) {
ConsoleHelper helper(info, consoleContext, m_inspector);
String16 title = helper.firstArgToString(String16("default"), false);
String16 identifier = identifierFromTitleOrStackTrace(
title, helper, consoleContext, m_inspector);
if (!helper.consoleMessageStorage()->countReset(helper.contextId(),
identifier)) {
helper.reportCallWithArgument(ConsoleAPIType::kWarning,
"Count for '" + title + "' does not exist");
}
}
void V8Console::Assert(const v8::debug::ConsoleCallArguments& info, void V8Console::Assert(const v8::debug::ConsoleCallArguments& info,
const v8::debug::ConsoleContext& consoleContext) { const v8::debug::ConsoleContext& consoleContext) {
ConsoleHelper helper(info, consoleContext, m_inspector); ConsoleHelper helper(info, consoleContext, m_inspector);
......
...@@ -16,7 +16,7 @@ class InspectedContext; ...@@ -16,7 +16,7 @@ class InspectedContext;
class V8InspectorImpl; class V8InspectorImpl;
// Console API // Console API
// https://console.spec.whatwg.org/#console-interface // https://console.spec.whatwg.org/#console-namespace
class V8Console : public v8::debug::ConsoleDelegate { class V8Console : public v8::debug::ConsoleDelegate {
public: public:
v8::Local<v8::Object> createCommandLineAPI(v8::Local<v8::Context> context, v8::Local<v8::Object> createCommandLineAPI(v8::Local<v8::Context> context,
...@@ -78,6 +78,8 @@ class V8Console : public v8::debug::ConsoleDelegate { ...@@ -78,6 +78,8 @@ class V8Console : public v8::debug::ConsoleDelegate {
const v8::debug::ConsoleContext& consoleContext) override; const v8::debug::ConsoleContext& consoleContext) override;
void Count(const v8::debug::ConsoleCallArguments&, void Count(const v8::debug::ConsoleCallArguments&,
const v8::debug::ConsoleContext& consoleContext) override; const v8::debug::ConsoleContext& consoleContext) override;
void CountReset(const v8::debug::ConsoleCallArguments&,
const v8::debug::ConsoleContext& consoleContext) override;
void Assert(const v8::debug::ConsoleCallArguments&, void Assert(const v8::debug::ConsoleCallArguments&,
const v8::debug::ConsoleContext& consoleContext) override; const v8::debug::ConsoleContext& consoleContext) override;
void MarkTimeline(const v8::debug::ConsoleCallArguments&, void MarkTimeline(const v8::debug::ConsoleCallArguments&,
......
...@@ -24,15 +24,16 @@ console.context() methods: ...@@ -24,15 +24,16 @@ console.context() methods:
[11] : groupEnd [11] : groupEnd
[12] : clear [12] : clear
[13] : count [13] : count
[14] : assert [14] : countReset
[15] : markTimeline [15] : assert
[16] : profile [16] : markTimeline
[17] : profileEnd [17] : profile
[18] : timeline [18] : profileEnd
[19] : timelineEnd [19] : timeline
[20] : time [20] : timelineEnd
[21] : timeEnd [21] : time
[22] : timeStamp [22] : timeEnd
[23] : timeStamp
] ]
Running test: testDefaultConsoleContext Running test: testDefaultConsoleContext
......
...@@ -821,3 +821,131 @@ Checks console methods ...@@ -821,3 +821,131 @@ Checks console methods
type : count type : count
} }
} }
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
type : string
value : default: 1
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : testFunction
lineNumber : 35
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : count
}
}
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
type : string
value : default: 1
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : testFunction
lineNumber : 37
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : count
}
}
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
type : string
value : default: 1
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : testFunction
lineNumber : 39
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : count
}
}
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
type : string
value : Count for 'countReset' does not exist
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : testFunction
lineNumber : 40
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : warning
}
}
...@@ -32,6 +32,13 @@ function testFunction() { ...@@ -32,6 +32,13 @@ function testFunction() {
console.count(); console.count();
console.count(undefined); console.count(undefined);
console.count('default'); console.count('default');
console.countReset();
console.count();
console.countReset(undefined);
console.count();
console.countReset('default');
console.count();
console.countReset('countReset');
} }
//# sourceURL=test.js`, 7, 26); //# sourceURL=test.js`, 7, 26);
......
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