From afce91219359654b44df29e6ec1b730e2a73a919 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 20 Mar 2019 15:48:59 +0100 Subject: assert: improve performance to instantiate errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This improves the performance for AssertionError by deactivating duplicated stack frame creation. PR-URL: https://github.com/nodejs/node/pull/26738 Reviewed-By: Gus Caplan Reviewed-By: Matteo Collina Reviewed-By: Michaƫl Zasso Reviewed-By: Joyee Cheung --- lib/internal/assert/assertion_error.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/internal/assert') diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index c8edf13eca..7c9bace378 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -300,6 +300,9 @@ class AssertionError extends Error { stackStartFn } = options; + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 0; + if (message != null) { super(String(message)); } else { @@ -387,6 +390,8 @@ class AssertionError extends Error { } } + Error.stackTraceLimit = limit; + this.generatedMessage = !message; Object.defineProperty(this, 'name', { value: 'AssertionError [ERR_ASSERTION]', -- cgit v1.2.3