Skip to content

Commit

Permalink
assert: improve performance to instantiate errors
Browse files Browse the repository at this point in the history
This improves the performance for AssertionError by deactivating
duplicated stack frame creation.

PR-URL: nodejs#26738
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
BridgeAR committed Mar 23, 2019
1 parent f0f26ce commit afce912
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ class AssertionError extends Error {
stackStartFn
} = options;

const limit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;

if (message != null) {
super(String(message));
} else {
Expand Down Expand Up @@ -387,6 +390,8 @@ class AssertionError extends Error {
}
}

Error.stackTraceLimit = limit;

this.generatedMessage = !message;
Object.defineProperty(this, 'name', {
value: 'AssertionError [ERR_ASSERTION]',
Expand Down

0 comments on commit afce912

Please sign in to comment.