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: https://github.com/nodejs/node/pull/5901 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
parent
6c1e5ad3ab
commit
1c84579031
@ -67,9 +67,10 @@ Console.prototype.time = function(label) {
|
|||||||
|
|
||||||
|
|
||||||
Console.prototype.timeEnd = function(label) {
|
Console.prototype.timeEnd = function(label) {
|
||||||
var time = this._times.get(label);
|
const time = this._times.get(label);
|
||||||
if (!time) {
|
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 duration = process.hrtime(time);
|
||||||
const ms = duration[0] * 1000 + duration[1] / 1e6;
|
const ms = duration[0] * 1000 + duration[1] / 1e6;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
assert.ok(process.stdout.writable);
|
assert.ok(process.stdout.writable);
|
||||||
assert.ok(process.stderr.writable);
|
assert.ok(process.stderr.writable);
|
||||||
@ -8,7 +8,11 @@ assert.ok(process.stderr.writable);
|
|||||||
assert.equal('number', typeof process.stdout.fd);
|
assert.equal('number', typeof process.stdout.fd);
|
||||||
assert.equal('number', typeof process.stderr.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');
|
console.timeEnd('no such label');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user