Commit c97d869d authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[inspector] align console.time(undefined) and console.time() with spec

R=dgozman@chromium.org

Bug: chromium:696798
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ida60ee5fb3e3e42d15bf6d4bad84dfcfb521b74f
Reviewed-on: https://chromium-review.googlesource.com/722073Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48617}
parent f7fbc8ed
...@@ -109,8 +109,11 @@ class ConsoleHelper { ...@@ -109,8 +109,11 @@ class ConsoleHelper {
return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue); return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue);
} }
String16 firstArgToString(const String16& defaultValue) { String16 firstArgToString(const String16& defaultValue,
if (m_info.Length() < 1) return defaultValue; bool allowUndefined = true) {
if (m_info.Length() < 1 || (!allowUndefined && m_info[0]->IsUndefined())) {
return defaultValue;
}
v8::Local<v8::String> titleValue; v8::Local<v8::String> titleValue;
v8::TryCatch tryCatch(m_context->GetIsolate()); v8::TryCatch tryCatch(m_context->GetIsolate());
if (m_info[0]->IsObject()) { if (m_info[0]->IsObject()) {
...@@ -349,7 +352,7 @@ static void timeFunction(const v8::debug::ConsoleCallArguments& info, ...@@ -349,7 +352,7 @@ static void timeFunction(const v8::debug::ConsoleCallArguments& info,
const v8::debug::ConsoleContext& consoleContext, const v8::debug::ConsoleContext& consoleContext,
bool timelinePrefix, V8InspectorImpl* inspector) { bool timelinePrefix, V8InspectorImpl* inspector) {
ConsoleHelper helper(info, consoleContext, inspector); ConsoleHelper helper(info, consoleContext, inspector);
String16 protocolTitle = helper.firstArgToString("default"); String16 protocolTitle = helper.firstArgToString("default", false);
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
inspector->client()->consoleTime(toStringView(protocolTitle)); inspector->client()->consoleTime(toStringView(protocolTitle));
helper.consoleMessageStorage()->time( helper.consoleMessageStorage()->time(
...@@ -361,7 +364,7 @@ static void timeEndFunction(const v8::debug::ConsoleCallArguments& info, ...@@ -361,7 +364,7 @@ static void timeEndFunction(const v8::debug::ConsoleCallArguments& info,
const v8::debug::ConsoleContext& consoleContext, const v8::debug::ConsoleContext& consoleContext,
bool timelinePrefix, V8InspectorImpl* inspector) { bool timelinePrefix, V8InspectorImpl* inspector) {
ConsoleHelper helper(info, consoleContext, inspector); ConsoleHelper helper(info, consoleContext, inspector);
String16 protocolTitle = helper.firstArgToString("default"); String16 protocolTitle = helper.firstArgToString("default", false);
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
inspector->client()->consoleTimeEnd(toStringView(protocolTitle)); inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
double elapsed = helper.consoleMessageStorage()->timeEnd( double elapsed = helper.consoleMessageStorage()->timeEnd(
......
...@@ -27,3 +27,11 @@ timeEnd: 1000000000000000.2ms ...@@ -27,3 +27,11 @@ timeEnd: 1000000000000000.2ms
Running test: huge Running test: huge
js: 1e+42ms js: 1e+42ms
timeEnd: 1e+42ms timeEnd: 1e+42ms
Running test: undefinedAsLabel
js: 1ms
default: 1ms
Running test: emptyAsLabel
js: 1ms
default: 1ms
...@@ -9,37 +9,43 @@ Protocol.Runtime.onConsoleAPICalled(message => { ...@@ -9,37 +9,43 @@ Protocol.Runtime.onConsoleAPICalled(message => {
InspectorTest.log(message.params.args[0].value); InspectorTest.log(message.params.args[0].value);
}); });
InspectorTest.runTestSuite([ InspectorTest.runAsyncTestSuite([
function zero(next) { function zero() {
checkInterval(0.0).then(next); return checkInterval(0.0);
}, },
function verySmall(next) { function verySmall() {
checkInterval(1e-15).then(next); return checkInterval(1e-15);
}, },
function small(next) { function small() {
checkInterval(0.001).then(next); return checkInterval(0.001);
}, },
function regular(next) { function regular() {
checkInterval(1.2345).then(next); return checkInterval(1.2345);
}, },
function big(next) { function big() {
checkInterval(10000.2345).then(next); return checkInterval(10000.2345);
}, },
function veryBig(next) { function veryBig() {
checkInterval(1e+15 + 0.2345).then(next); return checkInterval(1e+15 + 0.2345);
}, },
function huge(next) { function huge() {
checkInterval(1e+42).then(next); return checkInterval(1e+42);
},
function undefinedAsLabel() {
return checkInterval(1.0, 'undefined');
},
function emptyAsLabel() {
return checkInterval(1.0, '');
} }
]); ]);
function checkInterval(time) { async function checkInterval(time, label) {
label = label === undefined ? '\'timeEnd\'' : label;
utils.setCurrentTimeMSForTest(0.0); utils.setCurrentTimeMSForTest(0.0);
return Protocol.Runtime.evaluate({ Protocol.Runtime.evaluate({
expression: `console.log('js: ' + ${time} + 'ms')`}) expression: `console.log('js: ' + ${time} + 'ms')`
.then(() => Protocol.Runtime.evaluate({ });
expression: 'console.time(\'timeEnd\')'})) await Protocol.Runtime.evaluate({expression: `console.time(${label})`});
.then(() => utils.setCurrentTimeMSForTest(time)) utils.setCurrentTimeMSForTest(time);
.then(() => Protocol.Runtime.evaluate({ await Protocol.Runtime.evaluate({expression: `console.timeEnd(${label})`});
expression: 'console.timeEnd(\'timeEnd\')'}));
} }
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