File tree 3 files changed +28
-4
lines changed
3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -321,7 +321,7 @@ See [`util.format()`][] for more information.
321
321
<!-- YAML
322
322
added: v0.1.104
323
323
-->
324
- * ` label ` {string}
324
+ * ` label ` {string} Defaults to ` 'default' ` .
325
325
326
326
Starts a timer that can be used to compute the duration of an operation. Timers
327
327
are identified by a unique ` label ` . Use the same ` label ` when calling
@@ -337,7 +337,7 @@ changes:
337
337
description: This method no longer supports multiple calls that don’t map
338
338
to individual `console.time()` calls; see below for details.
339
339
-->
340
- * ` label ` {string}
340
+ * ` label ` {string} Defaults to ` 'default' ` .
341
341
342
342
Stops a timer that was previously started by calling [ ` console.time() ` ] [ ] and
343
343
prints the result to ` stdout ` :
Original file line number Diff line number Diff line change @@ -139,12 +139,16 @@ Console.prototype.dir = function dir(object, options) {
139
139
} ;
140
140
141
141
142
- Console . prototype . time = function time ( label ) {
142
+ Console . prototype . time = function time ( label = 'default' ) {
143
+ // Coerces everything other than Symbol to a string
144
+ label = `${ label } ` ;
143
145
this . _times . set ( label , process . hrtime ( ) ) ;
144
146
} ;
145
147
146
148
147
- Console . prototype . timeEnd = function timeEnd ( label ) {
149
+ Console . prototype . timeEnd = function timeEnd ( label = 'default' ) {
150
+ // Coerces everything other than Symbol to a string
151
+ label = `${ label } ` ;
148
152
const time = this . _times . get ( label ) ;
149
153
if ( ! time ) {
150
154
process . emitWarning ( `No such label '${ label } ' for console.timeEnd()` ) ;
Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ assert.doesNotThrow(function() {
42
42
console . timeEnd ( 'label' ) ;
43
43
} ) ;
44
44
45
+ assert . throws ( ( ) => console . time ( Symbol ( 'test' ) ) ,
46
+ / ^ T y p e E r r o r : C a n n o t c o n v e r t a S y m b o l v a l u e t o a s t r i n g $ / ) ;
47
+ assert . throws ( ( ) => console . timeEnd ( Symbol ( 'test' ) ) ,
48
+ / ^ T y p e E r r o r : C a n n o t c o n v e r t a S y m b o l v a l u e t o a s t r i n g $ / ) ;
49
+
50
+
45
51
// an Object with a custom .inspect() function
46
52
const custom_inspect = { foo : 'bar' , inspect : ( ) => 'inspect' } ;
47
53
@@ -103,6 +109,20 @@ console.timeEnd('constructor');
103
109
console . time ( 'hasOwnProperty' ) ;
104
110
console . timeEnd ( 'hasOwnProperty' ) ;
105
111
112
+ // verify that values are coerced to strings
113
+ console . time ( [ ] ) ;
114
+ console . timeEnd ( [ ] ) ;
115
+ console . time ( { } ) ;
116
+ console . timeEnd ( { } ) ;
117
+ console . time ( null ) ;
118
+ console . timeEnd ( null ) ;
119
+ console . time ( undefined ) ;
120
+ console . timeEnd ( 'default' ) ;
121
+ console . time ( 'default' ) ;
122
+ console . timeEnd ( ) ;
123
+ console . time ( NaN ) ;
124
+ console . timeEnd ( NaN ) ;
125
+
106
126
assert . strictEqual ( strings . length , process . stdout . writeTimes ) ;
107
127
assert . strictEqual ( errStrings . length , process . stderr . writeTimes ) ;
108
128
common . restoreStdout ( ) ;
You can’t perform that action at this time.
0 commit comments