Skip to content
Permalink
Browse files

console: timeEnd() with no label emits warning

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 21, 2016
1 parent 6c1e5ad commit 1c84579031e34326742c9c264f54625c5918197c
Showing with 10 additions and 5 deletions.
  1. +3 −2 lib/console.js
  2. +7 −3 test/parallel/test-console.js
@@ -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;
@@ -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');
});

0 comments on commit 1c84579

Please sign in to comment.
You can’t perform that action at this time.