File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Expand file tree Collapse file tree 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.
321321<!-- YAML
322322added: v0.1.104
323323-->
324- * ` label ` {string}
324+ * ` label ` {string} Defaults to ` 'default' ` .
325325
326326Starts a timer that can be used to compute the duration of an operation. Timers
327327are identified by a unique ` label ` . Use the same ` label ` when calling
@@ -337,7 +337,7 @@ changes:
337337 description: This method no longer supports multiple calls that don’t map
338338 to individual `console.time()` calls; see below for details.
339339-->
340- * ` label ` {string}
340+ * ` label ` {string} Defaults to ` 'default' ` .
341341
342342Stops a timer that was previously started by calling [ ` console.time() ` ] [ ] and
343343prints 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) {
139139} ;
140140
141141
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 } ` ;
143145 this . _times . set ( label , process . hrtime ( ) ) ;
144146} ;
145147
146148
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 } ` ;
148152 const time = this . _times . get ( label ) ;
149153 if ( ! time ) {
150154 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() {
4242 console . timeEnd ( 'label' ) ;
4343} ) ;
4444
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+
4551// an Object with a custom .inspect() function
4652const custom_inspect = { foo : 'bar' , inspect : ( ) => 'inspect' } ;
4753
@@ -103,6 +109,20 @@ console.timeEnd('constructor');
103109console . time ( 'hasOwnProperty' ) ;
104110console . timeEnd ( 'hasOwnProperty' ) ;
105111
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+
106126assert . strictEqual ( strings . length , process . stdout . writeTimes ) ;
107127assert . strictEqual ( errStrings . length , process . stderr . writeTimes ) ;
108128common . restoreStdout ( ) ;
You can’t perform that action at this time.
0 commit comments