Skip to content

Commit

Permalink
console: use a plain object for the the error stack
Browse files Browse the repository at this point in the history
Using a object instead of an Error is sufficient as the Error
itself won't be used but only the stack trace that would
otherwise be created twice.

This improves the overall .trace() performance.

PR-URL: #13743
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
BridgeAR authored and refack committed Jun 22, 2017
1 parent 3e17884 commit 70b31ad
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ Console.prototype.timeEnd = function timeEnd(label) {


Console.prototype.trace = function trace(...args) {
// TODO probably can to do this better with V8's debug object once that is
// exposed.
var err = new Error();
err.name = 'Trace';
err.message = util.format.apply(null, args);
const err = {
name: 'Trace',
message: util.format.apply(null, args)
};
Error.captureStackTrace(err, trace);
this.error(err.stack);
};
Expand Down

0 comments on commit 70b31ad

Please sign in to comment.