assert: improve performance to instantiate errors

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 <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>
This commit is contained in:
Ruben Bridgewater 2019-03-20 15:48:59 +01:00
parent f0f26cedcc
commit afce912193
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
1 changed files with 5 additions and 0 deletions

View File

@ -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]',