From 27a2adc4a09a517d30f45dc0f922bd42b4610c85 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Jun 2017 15:20:39 +0200 Subject: [PATCH] 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 Reviewed-By: Timothy Gu Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Refael Ackermann --- lib/console.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/console.js b/lib/console.js index 7ec9c846329cce..a3506247906f4a 100644 --- a/lib/console.js +++ b/lib/console.js @@ -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); };