Skip to content

Commit

Permalink
console: timeEnd() with no label emits warning
Browse files Browse the repository at this point in the history
When timeEnd() provided with label that doesn't exists
it emits warning in the console, so developer get know about it.

PR-URL: #5901
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
ghaiklor authored and jasnell committed Apr 26, 2016
1 parent 3350b47 commit 3050795
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/console.js
Expand Up @@ -67,9 +67,10 @@ Console.prototype.time = function(label) {


Console.prototype.timeEnd = function(label) {
var time = this._times.get(label);
const time = this._times.get(label);
if (!time) {
throw new Error(`No such label: ${label}`);
process.emitWarning(`No such label '${label}' for console.timeEnd()`);
return;
}
const duration = process.hrtime(time);
const ms = duration[0] * 1000 + duration[1] / 1e6;
Expand Down
10 changes: 7 additions & 3 deletions test/parallel/test-console.js
@@ -1,14 +1,18 @@
'use strict';
require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

assert.ok(process.stdout.writable);
assert.ok(process.stderr.writable);
// Support legacy API
assert.equal('number', typeof process.stdout.fd);
assert.equal('number', typeof process.stderr.fd);

assert.throws(function() {
assert.doesNotThrow(function() {
process.once('warning', common.mustCall((warning) => {
assert(/no such label/.test(warning.message));
}));

console.timeEnd('no such label');
});

Expand Down

0 comments on commit 3050795

Please sign in to comment.