Web Inspector: Implement console.timeLog
authorpecoraro@apple.com <pecoraro@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Jun 2019 18:36:29 +0000 (18:36 +0000)
committerpecoraro@apple.com <pecoraro@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Jun 2019 18:36:29 +0000 (18:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199184

Reviewed by Devin Rousso.

Source/JavaScriptCore:

* inspector/JSGlobalObjectConsoleClient.cpp:
(Inspector::JSGlobalObjectConsoleClient::timeLog):
* inspector/JSGlobalObjectConsoleClient.h:
* inspector/agents/InspectorConsoleAgent.cpp:
(Inspector::InspectorConsoleAgent::logTiming):
(Inspector::InspectorConsoleAgent::stopTiming):
* inspector/agents/InspectorConsoleAgent.h:
* runtime/ConsoleClient.h:
* runtime/ConsoleObject.cpp:
(JSC::ConsoleObject::finishCreation):
(JSC::consoleProtoFuncTimeLog):

Source/WebCore:

Updated existing tests.

* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::logConsoleTimingImpl):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::logConsoleTiming):
* page/PageConsoleClient.cpp:
(WebCore::PageConsoleClient::timeLog):
* page/PageConsoleClient.h:
* workers/WorkerConsoleClient.cpp:
(WebCore::WorkerConsoleClient::timeLog):
* workers/WorkerConsoleClient.h:
* worklets/WorkletConsoleClient.cpp:
(WebCore::WorkletConsoleClient::timeLog):
* worklets/WorkletConsoleClient.h:

Source/WebInspectorUI:

* UserInterface/Views/ConsoleMessageView.js:
(WI.ConsoleMessageView.prototype._appendMessageTextAndArguments):
Time messages (like timeLog) do not include their messageText
in their parameters list. So to behave more like normal logs
build a parameter list that includes it at the front.

LayoutTests:

* inspector/console/console-time-expected.txt:
* inspector/console/console-time.html:
Add new timeLog tests.

* js/console-expected.txt:
New timeLog method.

* platform/gtk/TestExpectations:
* platform/mac/TestExpectations:
Unskip test.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246798 268f45cc-cd09-0410-ab3c-d52691b4dbfc

24 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/console/console-time-expected.txt
LayoutTests/inspector/console/console-time.html
LayoutTests/js/console-expected.txt
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/mac/TestExpectations
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.cpp
Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.h
Source/JavaScriptCore/inspector/agents/InspectorConsoleAgent.cpp
Source/JavaScriptCore/inspector/agents/InspectorConsoleAgent.h
Source/JavaScriptCore/runtime/ConsoleClient.h
Source/JavaScriptCore/runtime/ConsoleObject.cpp
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/page/PageConsoleClient.cpp
Source/WebCore/page/PageConsoleClient.h
Source/WebCore/workers/WorkerConsoleClient.cpp
Source/WebCore/workers/WorkerConsoleClient.h
Source/WebCore/worklets/WorkletConsoleClient.cpp
Source/WebCore/worklets/WorkletConsoleClient.h
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js

index 81a4855..44cced5 100644 (file)
@@ -1,3 +1,21 @@
+2019-06-25  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Implement console.timeLog
+        https://bugs.webkit.org/show_bug.cgi?id=199184
+
+        Reviewed by Devin Rousso.
+
+        * inspector/console/console-time-expected.txt:
+        * inspector/console/console-time.html:
+        Add new timeLog tests.
+
+        * js/console-expected.txt:
+        New timeLog method.
+
+        * platform/gtk/TestExpectations:
+        * platform/mac/TestExpectations:
+        Unskip test.
+
 2019-06-25  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         Unreviewed test gardening
index 640d7ae..dbe6917 100644 (file)
@@ -1,8 +1,14 @@
-Tests for the console.time and console.timeEnd APIs.
+Tests for the console.time, console.timeLog, and console.timeEnd APIs.
 
 
-== Running test suite: console.time and console.timeEnd
--- Running test case: DefaultLabel
+== Running test suite: console.time
+-- Running test case: console.time.DefaultLabel
+PASS: Should receive a Timing type message.
+PASS: Message should contain the 'default' label name somewhere.
+PASS: Should receive a Timing type message.
+PASS: Message should contain the 'default' label name somewhere.
+PASS: Should receive a Timing type message.
+PASS: Message should contain the 'default' label name somewhere.
 PASS: Should receive a Timing type message.
 PASS: Message should contain the 'default' label name somewhere.
 PASS: Should receive a Timing type message.
@@ -10,23 +16,52 @@ PASS: Message should contain the 'default' label name somewhere.
 PASS: Should receive a Timing type message.
 PASS: Message should contain the 'default' label name somewhere.
 
--- Running test case: UserLabels
+-- Running test case: console.time.UserLabels
+PASS: Should receive a Timing type message.
+PASS: Message should contain the 'my-label' label name somewhere.
 PASS: Should receive a Timing type message.
 PASS: Message should contain the 'my-label' label name somewhere.
 
--- Running test case: MultipleTimers
+-- Running test case: console.time.MultipleTimers
 PASS: Should receive a Timing type message.
 PASS: Message should contain the 'my-label-2' label name somewhere.
 PASS: Should receive a Timing type message.
 PASS: Message should contain the 'my-label-1' label name somewhere.
 
--- Running test case: WarnWhenExisting
+-- Running test case: console.time.WarnWhenExisting
 PASS: Should receive a Timing type message.
 PASS: Should receive a Warning level message
 PASS: Message should contain the 'default' label name somewhere.
 
--- Running test case: WarnWhenNotExisting
+-- Running test case: console.time.WarnWhenNotExisting
+PASS: Should receive a Timing type message.
+PASS: Should receive a Warning level message.
+PASS: Message should contain the 'default' label name somewhere.
 PASS: Should receive a Timing type message.
 PASS: Should receive a Warning level message.
 PASS: Message should contain the 'default' label name somewhere.
 
+-- Running test case: console.time.TimeLogIncreasing
+PASS: Should receive a Timing type message.
+PASS: Message should contain the 'my-timelog-label' label name somewhere.
+PASS: + Initial timer time seen.
+PASS: Should receive a Timing type message.
+PASS: Message should contain the 'my-timelog-label' label name somewhere.
+PASS: + Timer time should be increasing.
+PASS: Should receive a Timing type message.
+PASS: Message should contain the 'my-timelog-label' label name somewhere.
+PASS: + Timer time should be increasing.
+PASS: Should receive a Timing type message.
+PASS: Message should contain the 'my-timelog-label' label name somewhere.
+PASS: + Timer time should be increasing.
+
+-- Running test case: console.time.TimeLogArguments
+PASS: Should receive a Timing type message.
+PASS: timeLog should contain no parameters
+PASS: Should receive a Timing type message.
+PASS: timeLog should contain 1 parameters
+PASS: Should receive a Timing type message.
+PASS: timeLog should contain 2 parameters
+PASS: Should receive a Timing type message.
+PASS: timeEnd should contain no parameters
+
index 05f44ca..93dcede 100644 (file)
@@ -3,16 +3,22 @@
 <head>
 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
 <script>
+function sleepTick() {
+    let now = performance.now();
+    let until = now + 10;
+    while (performance.now() < until);
+}
+
 function test()
 {
-    let suite = InspectorTest.createAsyncSuite("console.time and console.timeEnd");
+    let suite = InspectorTest.createAsyncSuite("console.time");
 
     suite.addTestCase({
-        name: "DefaultLabel",
+        name: "console.time.DefaultLabel",
         description: "Test that default label works as expected.",
         test(resolve, reject) {
             let seen = 0;
-            const expected = 3;
+            const expected = 6;
             WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
             function handler(event) {
                 let message = event.data.message;
@@ -24,36 +30,45 @@ function test()
                 }
             }
 
-            InspectorTest.evaluateInPage("console.time()");
-            InspectorTest.evaluateInPage("console.timeEnd()");
+            InspectorTest.evaluateInPage(`console.time()`);
+            InspectorTest.evaluateInPage(`console.timeLog()`);
+            InspectorTest.evaluateInPage(`console.timeEnd()`);
 
-            InspectorTest.evaluateInPage("console.time(undefined)");
-            InspectorTest.evaluateInPage("console.timeEnd('default')");
+            InspectorTest.evaluateInPage(`console.time(undefined)`);
+            InspectorTest.evaluateInPage(`console.timeLog('default')`);
+            InspectorTest.evaluateInPage(`console.timeEnd('default')`);
 
-            InspectorTest.evaluateInPage("console.time('default')");
-            InspectorTest.evaluateInPage("console.timeEnd(undefined)");
+            InspectorTest.evaluateInPage(`console.time('default')`);
+            InspectorTest.evaluateInPage(`console.timeLog(undefined)`);
+            InspectorTest.evaluateInPage(`console.timeEnd(undefined)`);
         }
     });
 
     suite.addTestCase({
-        name: "UserLabels",
+        name: "console.time.UserLabels",
         description: "Test that user labels works as expected.",
         test(resolve, reject) {
-            WI.consoleManager.awaitEvent(WI.ConsoleManager.Event.MessageAdded)
-            .then((event) => {
+            let seen = 0;
+            const expected = 2;
+            WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
+            function handler(event) {
                 let message = event.data.message;
                 InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
                 InspectorTest.expectThat(message.messageText.includes("my-label"), "Message should contain the 'my-label' label name somewhere.");
-            })
-            .then(resolve, reject);
+                if (++seen === expected) {
+                    WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
+                    resolve();
+                }
+            }
 
-            InspectorTest.evaluateInPage("console.time('my-label')");
-            InspectorTest.evaluateInPage("console.timeEnd('my-label')");
+            InspectorTest.evaluateInPage(`console.time('my-label')`);
+            InspectorTest.evaluateInPage(`console.timeLog('my-label')`);
+            InspectorTest.evaluateInPage(`console.timeEnd('my-label')`);
         }
     });
 
     suite.addTestCase({
-        name: "MultipleTimers",
+        name: "console.time.MultipleTimers",
         description: "Test that multiple timers running at the same time work as expected.",
         test(resolve, reject) {
             let seen = 0;
@@ -70,15 +85,15 @@ function test()
                 }
             }
 
-            InspectorTest.evaluateInPage("console.time('my-label-1')");
-            InspectorTest.evaluateInPage("console.time('my-label-2')");
-            InspectorTest.evaluateInPage("console.timeEnd('my-label-2')");
-            InspectorTest.evaluateInPage("console.timeEnd('my-label-1')");
+            InspectorTest.evaluateInPage(`console.time('my-label-1')`);
+            InspectorTest.evaluateInPage(`console.time('my-label-2')`);
+            InspectorTest.evaluateInPage(`console.timeEnd('my-label-2')`);
+            InspectorTest.evaluateInPage(`console.timeEnd('my-label-1')`);
         }
     });
 
     suite.addTestCase({
-        name: "WarnWhenExisting",
+        name: "console.time.WarnWhenExisting",
         description: "Test for a warning when trying to start an already started timer.",
         test(resolve, reject) {
             WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
@@ -96,26 +111,114 @@ function test()
                 }
             }
 
-            InspectorTest.evaluateInPage("console.time()");
-            InspectorTest.evaluateInPage("console.time()"); // Warning
-            InspectorTest.evaluateInPage("console.timeEnd()");
+            InspectorTest.evaluateInPage(`console.time()`);
+            InspectorTest.evaluateInPage(`console.time()`); // Warning
+            InspectorTest.evaluateInPage(`console.timeEnd()`);
         }
     });
 
     suite.addTestCase({
-        name: "WarnWhenNotExisting",
+        name: "console.time.WarnWhenNotExisting",
         description: "Test for a warning when trying to start an already started timer.",
         test(resolve, reject) {
-            WI.consoleManager.awaitEvent(WI.ConsoleManager.Event.MessageAdded)
-            .then((event) => {
+            let seen = 0;
+            const expected = 2;
+            WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
+            function handler(event) {
                 let message = event.data.message;
+                if (message.type === WI.ConsoleMessage.MessageType.Clear)
+                    return;
+
                 InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
                 InspectorTest.expectThat(message.level === WI.ConsoleMessage.MessageLevel.Warning, "Should receive a Warning level message.");
                 InspectorTest.expectThat(message.messageText.includes("default"), "Message should contain the 'default' label name somewhere.");
-            })
-            .then(resolve, reject);
+                if (++seen === expected) {
+                    WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
+                    resolve();
+                }
+            }
+
+            InspectorTest.evaluateInPage(`console.timeLog()`); // Warn
+            InspectorTest.evaluateInPage(`console.clear()`);
+            InspectorTest.evaluateInPage(`console.timeEnd()`); // Warn
+        }
+    });
+
+    suite.addTestCase({
+        name: "console.time.TimeLogIncreasing",
+        description: "Test for timeLog multiple times with a timer should increase.",
+        test(resolve, reject) {
+            let lastTime = 0;
+            let seen = 0;
+            const expected = 4;
+            WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
+            function handler(event) {
+                let message = event.data.message;
+                InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
+                InspectorTest.expectThat(message.messageText.includes("my-timelog-label"), "Message should contain the 'my-timelog-label' label name somewhere.");
+
+                let match = message.messageText.match(/^my-timelog-label: (\d+(\.\d+)?ms)/)
+                if (match) {
+                    let currentTime = parseFloat(match[1]);
+                    if (lastTime) {
+                        InspectorTest.assert(currentTime > 15, "At least 15 milliseconds should have elapsed since this is for timeLog 2 and later.");
+                        InspectorTest.expectGreaterThan(currentTime, lastTime, "+ Timer time should be increasing.");
+                    } else
+                        InspectorTest.pass("+ Initial timer time seen.");
+                    lastTime = currentTime;
+                }
+
+                if (++seen === expected) {
+                    WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
+                    resolve();
+                }
+            }
+
+            InspectorTest.evaluateInPage(`console.time("my-timelog-label")`);
+            InspectorTest.evaluateInPage(`sleepTick(); console.timeLog("my-timelog-label")`);
+            InspectorTest.evaluateInPage(`sleepTick(); console.timeLog("my-timelog-label")`);
+            InspectorTest.evaluateInPage(`sleepTick(); console.timeLog("my-timelog-label")`);
+            InspectorTest.evaluateInPage(`sleepTick(); console.timeEnd("my-timelog-label")`);
+        }
+    });
+
+    suite.addTestCase({
+        name: "console.time.TimeLogArguments",
+        description: "Test for timeLog with trailing parameters.",
+        test(resolve, reject) {
+            let seen = 0;
+            const expected = 4;
+            WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
+            function handler(event) {
+                let message = event.data.message;
+                InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
+
+                switch (seen) {
+                case 0:
+                    InspectorTest.expectEqual(message.parameters, undefined, "timeLog should contain no parameters");
+                    break;
+                case 1:
+                    InspectorTest.expectEqual(message.parameters.length, 1, "timeLog should contain 1 parameters");
+                    break;
+                case 2:
+                    InspectorTest.expectEqual(message.parameters.length, 2, "timeLog should contain 2 parameters");
+                    break;
+                case 3:
+                    InspectorTest.expectEqual(message.parameters, undefined, "timeEnd should contain no parameters");
+                    break;
+                }
+
+                if (++seen === expected) {
+                    WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
+                    resolve();
+                }
+            }
 
-            InspectorTest.evaluateInPage("console.timeEnd()");
+            InspectorTest.evaluateInPage(`console.time("x")`);
+            InspectorTest.evaluateInPage(`console.timeLog("x")`);
+            InspectorTest.evaluateInPage(`console.timeLog("x", 1)`);
+            InspectorTest.evaluateInPage(`console.timeLog("x", 2, window)`);
+            InspectorTest.evaluateInPage(`console.timeEnd("x")`);
         }
     });
 
@@ -124,6 +227,6 @@ function test()
 </script>
 </head>
 <body onload="runTest()">
-<p>Tests for the console.time and console.timeEnd APIs.</p>
+<p>Tests for the console.time, console.timeLog, and console.timeEnd APIs.</p>
 </body>
 </html>
index b6bf724..63f7d47 100644 (file)
@@ -121,6 +121,13 @@ PASS descriptor.configurable is true
 PASS descriptor.writable is true
 PASS descriptor.enumerable is true
 
+console.timeLog
+PASS typeof console.timeLog is "function"
+PASS console.timeLog.length is 0
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS descriptor.enumerable is true
+
 console.timeEnd
 PASS typeof console.timeEnd is "function"
 PASS console.timeEnd.length is 0
index e7aa4e4..52f85dc 100644 (file)
@@ -2135,8 +2135,6 @@ webkit.org/b/197498 imported/w3c/web-platform-tests/web-animations/interfaces/An
 webkit.org/b/197498 imported/w3c/web-platform-tests/web-animations/interfaces/Animation/ready.html [ Failure Pass ]
 webkit.org/b/197498 imported/w3c/web-platform-tests/web-animations/timing-model/timelines/update-and-send-events.html [ Failure Pass ]
 
-webkit.org/b/197499 inspector/console/console-time.html [ Failure Pass ]
-
 webkit.org/b/197500 legacy-animation-engine/compositing/repaint/become-overlay-composited-layer.html [ Failure Pass ]
 
 webkit.org/b/197501 fast/images/animated-webp.html [ ImageOnlyFailure Pass ]
index 999a96f..01c09f7 100644 (file)
@@ -1089,7 +1089,6 @@ webkit.org/b/155607 inspector/heap/snapshot.html [ Pass Failure ]
 webkit.org/b/143719 inspector/console/console-api.html [ Pass Timeout ]
 webkit.org/b/156078 inspector/console/heapSnapshot.html [ Pass Timeout ]
 webkit.org/b/182620 inspector/console/clearMessages.html [ Pass Timeout ]
-webkit.org/b/158006 inspector/console/console-time.html [ Pass Failure ]
 webkit.org/b/183880 [ Debug ] inspector/console/messageAdded-from-named-evaluations.html [ Slow ]
 webkit.org/b/156634 inspector/formatting/formatting-javascript.html [ Pass Timeout ]
 webkit.org/b/158948 inspector/timeline [ Pass Timeout ]
index fef3421..aa65b11 100644 (file)
@@ -1,3 +1,22 @@
+2019-06-25  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Implement console.timeLog
+        https://bugs.webkit.org/show_bug.cgi?id=199184
+
+        Reviewed by Devin Rousso.
+
+        * inspector/JSGlobalObjectConsoleClient.cpp:
+        (Inspector::JSGlobalObjectConsoleClient::timeLog):
+        * inspector/JSGlobalObjectConsoleClient.h:
+        * inspector/agents/InspectorConsoleAgent.cpp:
+        (Inspector::InspectorConsoleAgent::logTiming):
+        (Inspector::InspectorConsoleAgent::stopTiming):
+        * inspector/agents/InspectorConsoleAgent.h:
+        * runtime/ConsoleClient.h:
+        * runtime/ConsoleObject.cpp:
+        (JSC::ConsoleObject::finishCreation):
+        (JSC::consoleProtoFuncTimeLog):
+
 2019-06-25  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         REGRESSION(r245586): static assertion failed: Match result and EncodedMatchResult should be the same size
index 0cd9227..fcdcc49 100644 (file)
@@ -153,6 +153,11 @@ void JSGlobalObjectConsoleClient::time(ExecState*, const String& title)
     m_consoleAgent->startTiming(title);
 }
 
+void JSGlobalObjectConsoleClient::timeLog(ExecState*, const String& title, Ref<ScriptArguments>&& arguments)
+{
+    m_consoleAgent->logTiming(title, WTFMove(arguments));
+}
+
 void JSGlobalObjectConsoleClient::timeEnd(ExecState* exec, const String& title)
 {
     m_consoleAgent->stopTiming(title, createScriptCallStackForConsole(exec, 1));
index 4194700..8bfeada 100644 (file)
@@ -54,6 +54,7 @@ protected:
     void profileEnd(JSC::ExecState*, const String& title) override;
     void takeHeapSnapshot(JSC::ExecState*, const String& title) override;
     void time(JSC::ExecState*, const String& title) override;
+    void timeLog(JSC::ExecState*, const String& title, Ref<ScriptArguments>&& arguments) override;
     void timeEnd(JSC::ExecState*, const String& title) override;
     void timeStamp(JSC::ExecState*, Ref<ScriptArguments>&&) override;
     void record(JSC::ExecState*, Ref<ScriptArguments>&&) override;
index c62b6e8..0386837 100644 (file)
@@ -144,7 +144,7 @@ void InspectorConsoleAgent::startTiming(const String& title)
     }
 }
 
-void InspectorConsoleAgent::stopTiming(const String& title, Ref<ScriptCallStack>&& callStack)
+void InspectorConsoleAgent::logTiming(const String& title, Ref<ScriptArguments>&& arguments)
 {
     if (!m_injectedScriptManager.inspectorEnvironment().developerExtrasEnabled())
         return;
@@ -162,11 +162,34 @@ void InspectorConsoleAgent::stopTiming(const String& title, Ref<ScriptCallStack>
     }
 
     MonotonicTime startTime = it->value;
-    m_times.remove(it);
+    Seconds elapsed = MonotonicTime::now() - startTime;
+    String message = makeString(title, ": ", FormattedNumber::fixedWidth(elapsed.milliseconds(), 3), "ms");
+    addMessageToConsole(std::make_unique<ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Timing, MessageLevel::Debug, message, WTFMove(arguments)));
+}
 
+void InspectorConsoleAgent::stopTiming(const String& title, Ref<ScriptCallStack>&& callStack)
+{
+    if (!m_injectedScriptManager.inspectorEnvironment().developerExtrasEnabled())
+        return;
+
+    ASSERT(!title.isNull());
+    if (title.isNull())
+        return;
+
+    auto it = m_times.find(title);
+    if (it == m_times.end()) {
+        // FIXME: Send an enum to the frontend for localization?
+        String warning = makeString("Timer \"", title, "\" does not exist");
+        addMessageToConsole(std::make_unique<ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Timing, MessageLevel::Warning, warning));
+        return;
+    }
+
+    MonotonicTime startTime = it->value;
     Seconds elapsed = MonotonicTime::now() - startTime;
     String message = makeString(title, ": ", FormattedNumber::fixedWidth(elapsed.milliseconds(), 3), "ms");
     addMessageToConsole(std::make_unique<ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Timing, MessageLevel::Debug, message, WTFMove(callStack)));
+
+    m_times.remove(it);
 }
 
 void InspectorConsoleAgent::takeHeapSnapshot(const String& title)
index f0b6aae..3c3d605 100644 (file)
@@ -71,6 +71,7 @@ public:
     void addMessageToConsole(std::unique_ptr<ConsoleMessage>);
 
     void startTiming(const String& title);
+    void logTiming(const String& title, Ref<ScriptArguments>&&);
     void stopTiming(const String& title, Ref<ScriptCallStack>&&);
     void takeHeapSnapshot(const String& title);
     void count(JSC::ExecState*, Ref<ScriptArguments>&&);
index 53abb50..b3a846b 100644 (file)
@@ -60,6 +60,7 @@ public:
     virtual void profileEnd(ExecState*, const String& title) = 0;
     virtual void takeHeapSnapshot(ExecState*, const String& title) = 0;
     virtual void time(ExecState*, const String& title) = 0;
+    virtual void timeLog(ExecState*, const String& title, Ref<Inspector::ScriptArguments>&&) = 0;
     virtual void timeEnd(ExecState*, const String& title) = 0;
     virtual void timeStamp(ExecState*, Ref<Inspector::ScriptArguments>&&) = 0;
     virtual void record(ExecState*, Ref<Inspector::ScriptArguments>&&) = 0;
index 37c40d3..4bdfaeb 100644 (file)
@@ -52,6 +52,7 @@ static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfile(ExecState*);
 static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfileEnd(ExecState*);
 static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTakeHeapSnapshot(ExecState*);
 static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTime(ExecState*);
+static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeLog(ExecState*);
 static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeEnd(ExecState*);
 static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeStamp(ExecState*);
 static EncodedJSValue JSC_HOST_CALL consoleProtoFuncGroup(ExecState*);
@@ -92,6 +93,7 @@ void ConsoleObject::finishCreation(VM& vm, JSGlobalObject* globalObject)
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("profile", consoleProtoFuncProfile, static_cast<unsigned>(PropertyAttribute::None), 0);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("profileEnd", consoleProtoFuncProfileEnd, static_cast<unsigned>(PropertyAttribute::None), 0);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("time", consoleProtoFuncTime, static_cast<unsigned>(PropertyAttribute::None), 0);
+    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("timeLog", consoleProtoFuncTimeLog, static_cast<unsigned>(PropertyAttribute::None), 0);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("timeEnd", consoleProtoFuncTimeEnd, static_cast<unsigned>(PropertyAttribute::None), 0);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("timeStamp", consoleProtoFuncTimeStamp, static_cast<unsigned>(PropertyAttribute::None), 0);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("takeHeapSnapshot", consoleProtoFuncTakeHeapSnapshot, static_cast<unsigned>(PropertyAttribute::None), 0);
@@ -313,6 +315,26 @@ static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTime(ExecState* exec)
     return JSValue::encode(jsUndefined());
 }
 
+static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeLog(ExecState* exec)
+{
+    VM& vm = exec->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+    ConsoleClient* client = exec->lexicalGlobalObject()->consoleClient();
+    if (!client)
+        return JSValue::encode(jsUndefined());
+
+    String title;
+    if (exec->argumentCount() < 1)
+        title =  "default"_s;
+    else {
+        title = valueOrDefaultLabelString(exec, exec->argument(0));
+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
+    }
+
+    client->timeLog(exec, title, Inspector::createScriptArguments(exec, 1));
+    return JSValue::encode(jsUndefined());
+}
+
 static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeEnd(ExecState* exec)
 {
     VM& vm = exec->vm();
index 704f598..fc5ff08 100644 (file)
@@ -1,3 +1,26 @@
+2019-06-25  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Implement console.timeLog
+        https://bugs.webkit.org/show_bug.cgi?id=199184
+
+        Reviewed by Devin Rousso.
+
+        Updated existing tests.
+
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::logConsoleTimingImpl):
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::logConsoleTiming):
+        * page/PageConsoleClient.cpp:
+        (WebCore::PageConsoleClient::timeLog):
+        * page/PageConsoleClient.h:
+        * workers/WorkerConsoleClient.cpp:
+        (WebCore::WorkerConsoleClient::timeLog):
+        * workers/WorkerConsoleClient.h:
+        * worklets/WorkletConsoleClient.cpp:
+        (WebCore::WorkletConsoleClient::timeLog):
+        * worklets/WorkletConsoleClient.h:
+
 2019-06-25  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Add user agent quirk for bankofamerica.com
index 9b1d2fc..2ec7798 100644 (file)
@@ -886,6 +886,15 @@ void InspectorInstrumentation::startConsoleTimingImpl(InstrumentingAgents& instr
         consoleAgent->startTiming(title);
 }
 
+void InspectorInstrumentation::logConsoleTimingImpl(InstrumentingAgents& instrumentingAgents, const String& title, Ref<Inspector::ScriptArguments>&& arguments)
+{
+    if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
+        return;
+
+    if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
+        consoleAgent->logTiming(title, WTFMove(arguments));
+}
+
 void InspectorInstrumentation::stopConsoleTimingImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, const String& title, Ref<ScriptCallStack>&& stack)
 {
     if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
index 9d132c5..1f75137 100644 (file)
@@ -226,6 +226,8 @@ public:
     static void takeHeapSnapshot(Frame&, const String& title);
     static void startConsoleTiming(Frame&, const String& title);
     static void startConsoleTiming(WorkerGlobalScope&, const String& title);
+    static void logConsoleTiming(Frame&, const String& title, Ref<Inspector::ScriptArguments>&&);
+    static void logConsoleTiming(WorkerGlobalScope&, const String& title, Ref<Inspector::ScriptArguments>&&);
     static void stopConsoleTiming(Frame&, const String& title, Ref<Inspector::ScriptCallStack>&&);
     static void stopConsoleTiming(WorkerGlobalScope&, const String& title, Ref<Inspector::ScriptCallStack>&&);
     static void consoleTimeStamp(Frame&, Ref<Inspector::ScriptArguments>&&);
@@ -404,6 +406,7 @@ private:
     static void takeHeapSnapshotImpl(InstrumentingAgents&, const String& title);
     static void startConsoleTimingImpl(InstrumentingAgents&, Frame&, const String& title);
     static void startConsoleTimingImpl(InstrumentingAgents&, const String& title);
+    static void logConsoleTimingImpl(InstrumentingAgents&, const String& title, Ref<Inspector::ScriptArguments>&&);
     static void stopConsoleTimingImpl(InstrumentingAgents&, Frame&, const String& title, Ref<Inspector::ScriptCallStack>&&);
     static void stopConsoleTimingImpl(InstrumentingAgents&, const String& title, Ref<Inspector::ScriptCallStack>&&);
     static void consoleTimeStampImpl(InstrumentingAgents&, Frame&, Ref<Inspector::ScriptArguments>&&);
@@ -1408,6 +1411,17 @@ inline void InspectorInstrumentation::startConsoleTiming(WorkerGlobalScope& work
     startConsoleTimingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), title);
 }
 
+inline void InspectorInstrumentation::logConsoleTiming(Frame& frame, const String& title, Ref<Inspector::ScriptArguments>&& arguments)
+{
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
+        logConsoleTimingImpl(*instrumentingAgents, title, WTFMove(arguments));
+}
+
+inline void InspectorInstrumentation::logConsoleTiming(WorkerGlobalScope& workerGlobalScope, const String& title, Ref<Inspector::ScriptArguments>&& arguments)
+{
+    logConsoleTimingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), title, WTFMove(arguments));
+}
+
 inline void InspectorInstrumentation::stopConsoleTiming(Frame& frame, const String& title, Ref<Inspector::ScriptCallStack>&& stack)
 {
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
index d8de7e2..7b9704d 100644 (file)
@@ -197,6 +197,11 @@ void PageConsoleClient::time(JSC::ExecState*, const String& title)
     InspectorInstrumentation::startConsoleTiming(m_page.mainFrame(), title);
 }
 
+void PageConsoleClient::timeLog(JSC::ExecState*, const String& title, Ref<ScriptArguments>&& arguments)
+{
+    InspectorInstrumentation::logConsoleTiming(m_page.mainFrame(), title, WTFMove(arguments));
+}
+
 void PageConsoleClient::timeEnd(JSC::ExecState* exec, const String& title)
 {
     InspectorInstrumentation::stopConsoleTiming(m_page.mainFrame(), title, createScriptCallStackForConsole(exec, 1));
index 52c2fdc..3d08900 100644 (file)
@@ -72,6 +72,7 @@ protected:
     void profileEnd(JSC::ExecState*, const String& title) override;
     void takeHeapSnapshot(JSC::ExecState*, const String& title) override;
     void time(JSC::ExecState*, const String& title) override;
+    void timeLog(JSC::ExecState*, const String& title, Ref<Inspector::ScriptArguments>&&) override;
     void timeEnd(JSC::ExecState*, const String& title) override;
     void timeStamp(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
     void record(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
index bab2da6..dd643e7 100644 (file)
@@ -60,6 +60,11 @@ void WorkerConsoleClient::time(JSC::ExecState*, const String& title)
     InspectorInstrumentation::startConsoleTiming(m_workerGlobalScope, title);
 }
 
+void WorkerConsoleClient::timeLog(JSC::ExecState*, const String& title, Ref<ScriptArguments>&& arguments)
+{
+    InspectorInstrumentation::logConsoleTiming(m_workerGlobalScope, title, WTFMove(arguments));
+}
+
 void WorkerConsoleClient::timeEnd(JSC::ExecState* exec, const String& title)
 {
     InspectorInstrumentation::stopConsoleTiming(m_workerGlobalScope, title, createScriptCallStackForConsole(exec, 1));
index ef38587..ec3e19c 100644 (file)
@@ -48,6 +48,7 @@ protected:
     void profileEnd(JSC::ExecState*, const String& title) override;
     void takeHeapSnapshot(JSC::ExecState*, const String& title) override;
     void time(JSC::ExecState*, const String& title) override;
+    void timeLog(JSC::ExecState*, const String& title, Ref<Inspector::ScriptArguments>&&) override;
     void timeEnd(JSC::ExecState*, const String& title) override;
     void timeStamp(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
     void record(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
index 5dcb68e..eefbb9a 100644 (file)
@@ -55,6 +55,7 @@ void WorkletConsoleClient::messageWithTypeAndLevel(MessageType type, MessageLeve
 void WorkletConsoleClient::count(JSC::ExecState*, Ref<ScriptArguments>&&) { }
 
 void WorkletConsoleClient::time(JSC::ExecState*, const String&) { }
+void WorkletConsoleClient::timeLog(JSC::ExecState*, const String&, Ref<ScriptArguments>&&) { }
 void WorkletConsoleClient::timeEnd(JSC::ExecState*, const String&) { }
 
 void WorkletConsoleClient::profile(JSC::ExecState*, const String&) { }
index 7a581c8..38b6774 100644 (file)
@@ -50,6 +50,7 @@ private:
     void profileEnd(JSC::ExecState*, const String& title) final;
     void takeHeapSnapshot(JSC::ExecState*, const String& title) final;
     void time(JSC::ExecState*, const String& title) final;
+    void timeLog(JSC::ExecState*, const String& title, Ref<Inspector::ScriptArguments>&&) final;
     void timeEnd(JSC::ExecState*, const String& title) final;
     void timeStamp(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) final;
     void record(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) final;
index dd4d4a9..9f89afd 100644 (file)
@@ -1,3 +1,16 @@
+2019-06-25  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Implement console.timeLog
+        https://bugs.webkit.org/show_bug.cgi?id=199184
+
+        Reviewed by Devin Rousso.
+
+        * UserInterface/Views/ConsoleMessageView.js:
+        (WI.ConsoleMessageView.prototype._appendMessageTextAndArguments):
+        Time messages (like timeLog) do not include their messageText
+        in their parameters list. So to behave more like normal logs
+        build a parameter list that includes it at the front.
+
 2019-06-23  Matt Baker  <mattbaker@apple.com>
 
         Web Inspector: REGRESSION (r246684): Dark Mode: dashboard buttons should have no background
index 7f6f93b..6f0a7dd 100644 (file)
@@ -288,6 +288,14 @@ WI.ConsoleMessageView = class ConsoleMessageView extends WI.Object
                 this._extraParameters = null;
                 break;
 
+            case WI.ConsoleMessage.MessageType.Timing: {
+                let args = [this._message.messageText];
+                if (this._extraParameters)
+                    args = args.concat(this._extraParameters);
+                this._appendFormattedArguments(element, args);
+                break;
+            }
+
             case WI.ConsoleMessage.MessageType.Image: {
                 let img = element.appendChild(document.createElement("img"));
                 img.classList.add("console-image", "show-grid");