@@ -46,15 +46,6 @@ const ErrorToString = Function.call.bind(Error.prototype.toString);
4646
4747const SUPPORTED = ! ! Error . captureStackTrace ;
4848
49- // We add some extra frames to Error.stackTraceLimit, so that we can respect
50- // the original Error.stackTraceLimit even after removing all our internal
51- // frames.
52- // STACK_TRACE_LIMIT_DELTA should be bigger than the expected number of internal
53- // frames, but not too big because capturing the stack trace is slow (this is
54- // why Error.stackTraceLimit does not default to Infinity!).
55- // Increase it if needed.
56- const STACK_TRACE_LIMIT_DELTA = 100 ;
57-
5849const START_HIDNG = "startHiding - secret - don't use this - v1" ;
5950const STOP_HIDNG = "stopHiding - secret - don't use this - v1" ;
6051
@@ -131,7 +122,18 @@ function setupPrepareStackTrace() {
131122
132123 const { prepareStackTrace = defaultPrepareStackTrace } = Error ;
133124
134- Error . stackTraceLimit += STACK_TRACE_LIMIT_DELTA ;
125+ // We add some extra frames to Error.stackTraceLimit, so that we can
126+ // always show some useful frames even after deleting ours.
127+ // STACK_TRACE_LIMIT_DELTA should be around the maximum expected number
128+ // of internal frames, and not too big because capturing the stack trace
129+ // is slow (this is why Error.stackTraceLimit does not default to Infinity!).
130+ // Increase it if needed.
131+ // However, we only do it if the user did not explicitly set it to 0.
132+ const MIN_STACK_TRACE_LIMIT = 50 ;
133+ Error . stackTraceLimit &&= Math . max (
134+ Error . stackTraceLimit ,
135+ MIN_STACK_TRACE_LIMIT ,
136+ ) ;
135137
136138 Error . prepareStackTrace = function stackTraceRewriter ( err , trace ) {
137139 let newTrace = [ ] ;
@@ -160,10 +162,7 @@ function setupPrepareStackTrace() {
160162 }
161163 }
162164
163- return prepareStackTrace (
164- err ,
165- newTrace . slice ( 0 , Error . stackTraceLimit - STACK_TRACE_LIMIT_DELTA ) ,
166- ) ;
165+ return prepareStackTrace ( err , newTrace ) ;
167166 } ;
168167}
169168
0 commit comments