Skip to content

Commit afce912

Browse files
committed
assert: improve performance to instantiate errors
This improves the performance for AssertionError by deactivating duplicated stack frame creation. PR-URL: #26738 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent f0f26ce commit afce912

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/internal/assert/assertion_error.js

+5
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ class AssertionError extends Error {
300300
stackStartFn
301301
} = options;
302302

303+
const limit = Error.stackTraceLimit;
304+
Error.stackTraceLimit = 0;
305+
303306
if (message != null) {
304307
super(String(message));
305308
} else {
@@ -387,6 +390,8 @@ class AssertionError extends Error {
387390
}
388391
}
389392

393+
Error.stackTraceLimit = limit;
394+
390395
this.generatedMessage = !message;
391396
Object.defineProperty(this, 'name', {
392397
value: 'AssertionError [ERR_ASSERTION]',

0 commit comments

Comments
 (0)