This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

console: throw when no such label exists in `console.timeEnd`

Test included.
  • Loading branch information...
1 parent 3bcbd14 commit 77c18d1e1b470d99af317a2b1ed4b7e9bb81d5b6 @mmalecki mmalecki committed with bnoordhuis Apr 29, 2012
Showing with 14 additions and 1 deletion.
  1. +5 −1 lib/console.js
  2. +9 −0 test/simple/test-console.js
View
@@ -49,7 +49,11 @@ exports.time = function(label) {
exports.timeEnd = function(label) {
- var duration = Date.now() - times[label];
+ var time = times[label];
+ if (!time) {
+ throw new Error('No such label: ' + label);
+ }
+ var duration = Date.now() - time;
exports.log('%s: %dms', label, duration);
};
@@ -50,3 +50,12 @@ assert.equal('foo bar hop\n', strings.shift());
assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift());
process.stderr.write('hello world');
+
+assert.throws(function () {
+ console.timeEnd('no such label');
+});
+
+assert.doesNotThrow(function () {
+ console.time('label');
+ console.timeEnd('label');
+});

0 comments on commit 77c18d1

Please sign in to comment.