Browse Source

console: use a plain object for the the error stack

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: https://github.com/nodejs/node/pull/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>
v6
Ruben Bridgewater 8 years ago
committed by Refael Ackermann
parent
commit
70b31adffa
  1. 9
      lib/console.js

9
lib/console.js

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

Loading…
Cancel
Save