Skip to content

Commit 9690f7a

Browse files
authored
Specify console.timeLog() + clean up timing
1 parent 474670b commit 9690f7a

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

index.bs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace console { // but see namespace object requirements below
6868

6969
// Timing
7070
void time(optional DOMString label = "default");
71+
void timeLog(optional DOMString label = "default", any... data);
7172
void timeEnd(optional DOMString label = "default");
7273
};
7374
</pre>
@@ -78,8 +79,7 @@ namespace console { // but see namespace object requirements below
7879

7980
<p class="note">
8081
It is important that {{console}} is always visible and usable to scripts, even if the developer
81-
console has not been opened or
82-
does not exist.
82+
console has not been opened or does not exist.
8383
</p>
8484

8585
For historical web-compatibility reasons, the <a>namespace object</a> for {{console}} must have as
@@ -234,16 +234,49 @@ Each {{console}} namespace object has an associated <dfn>timer table</dfn>, whic
234234
1. Otherwise, [=map/set=] the value of the entry with key |label| in the associated
235235
<a>timer table</a> to the current time.
236236

237-
<h4 id="timeend" oldids="timeend-label,dom-console-timeend" method for="console">timeEnd(|label|)</h4>
237+
<h4 id="timelog" method for="console">timeLog(|label|, ...|data|)</h4>
238238

239-
1. Let |startTime| be the result of [=map/getting=] the value of the entry with key |label| in the
240-
associated <a>timer table</a>.
239+
1. Let |timerTable| be the associated <a>timer table</a>.
240+
1. Let |startTime| be |timerTable|[|label|].
241241
1. Let |duration| be a string representing the difference between the current time and
242242
|startTime|, in an implementation-defined format.
243243
<p class="example" id="duration-string-example">"4650", "4650.69 ms", "5 seconds", and "00:05"
244244
are all reasonable ways of displaying a 4650.69 ms duration.</p>
245245
1. Let |concat| be the concatenation of |label|, U+003A (:), U+0020 SPACE, and |duration|.
246-
1. Perform <a abstract-op>Logger</a>("timeEnd", « |concat| »).
246+
1. [=list/prepend|Prepend=] |concat| to |data|.
247+
1. Perform <a abstract-op>Printer</a>("timeLog", data).
248+
249+
<div class="example" id="timelog-example">
250+
The |data| parameter in calls to {{console/timeLog()}} is included in the call to
251+
<a abstract-op>Logger</a> to make it easier for users to supply intermediate timer logs with
252+
some extra data throughout the life of a timer. For example:
253+
254+
<pre><code class="lang-javascript">
255+
console.time("MyTimer");
256+
console.timeLog("MyTimer", "Starting application up…");
257+
// Perhaps some code runs to boostrap a complex app
258+
// ...
259+
console.timeLog("MyTimer", "UI is setup, making API calls now");
260+
// Perhaps some fetch()'s here filling the app with data
261+
// ...
262+
console.timeEnd("MyTimer");
263+
</code></pre>
264+
</div>
265+
266+
<h4 id="timeend" oldids="timeend-label,dom-console-timeend" method for="console">timeEnd(|label|)</h4>
267+
268+
1. Let |timerTable| be the associated <a>timer table</a>.
269+
1. Let |startTime| be |timerTable|[|label|].
270+
1. [=map/Remove=] |timerTable|[|label|].
271+
1. Let |duration| be a string representing the difference between the current time and
272+
|startTime|, in an implementation-defined format.
273+
1. Let |concat| be the concatenation of |label|, U+003A (:), U+0020 SPACE, and |duration|.
274+
1. Perform <a abstract-op>Printer</a>("timeEnd", « |concat| »).
275+
276+
<p class="note">See <a href="https://github.com/whatwg/console/issues/134">whatwg/console#134</a>
277+
for plans to make {{console/timeEnd()}} and {{console/timeLog()}} formally report warnings to the
278+
console when a given |label| does not exist in the associated <a>timer table</a>.
279+
</p>
247280

248281
<h2 id="supporting-ops">Supporting abstract operations</h2>
249282

@@ -394,7 +427,7 @@ their output similarly, in four broad categories. This table summarizes these co
394427
<td>log</td>
395428
<td>
396429
{{console/log()}}, {{console/trace()}}, {{console/dir()}}, {{console/dirxml()}},
397-
{{console/group()}}, {{console/groupCollapsed()}}, {{console/debug()}}
430+
{{console/group()}}, {{console/groupCollapsed()}}, {{console/debug()}}, {{console/timeLog()}}
398431
</td>
399432
<td>
400433
A generic log

0 commit comments

Comments
 (0)