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 <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
BridgeAR authored and addaleax committed Jul 18, 2017
1 parent 04bca73 commit 816f98f
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 @@ -150,11 +150,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 816f98f

Please sign in to comment.