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:
parent
f0f26cedcc
commit
afce912193
@ -300,6 +300,9 @@ class AssertionError extends Error {
|
|||||||
stackStartFn
|
stackStartFn
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
const limit = Error.stackTraceLimit;
|
||||||
|
Error.stackTraceLimit = 0;
|
||||||
|
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
super(String(message));
|
super(String(message));
|
||||||
} else {
|
} else {
|
||||||
@ -387,6 +390,8 @@ class AssertionError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Error.stackTraceLimit = limit;
|
||||||
|
|
||||||
this.generatedMessage = !message;
|
this.generatedMessage = !message;
|
||||||
Object.defineProperty(this, 'name', {
|
Object.defineProperty(this, 'name', {
|
||||||
value: 'AssertionError [ERR_ASSERTION]',
|
value: 'AssertionError [ERR_ASSERTION]',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user