@@ -154,65 +154,75 @@ suite('ExtensionHostMain#ErrorHandler - Wrapping prepareStackTrace can cause slo
154154 assert . strictEqual ( findSubstrCount , 2 ) ;
155155 assert . strictEqual ( do_something_count , 2 ) ;
156156 } ) ;
157- } ) ;
158-
159- suite ( 'ExtensionHostMain#ErrorHandler - from https://gist.github.com/thecrypticace/f0f2e182082072efdaf0f8e1537d2cce' , function ( ) {
160-
161- test ( "Restored, separate operations" , ( ) => {
162- // Actual Test
163- let original ;
164-
165- // Operation 1
166- original = Error . prepareStackTrace ;
167- for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
168- assert . ok ( new Error ( ) . stack ) ;
169- Error . prepareStackTrace = original ;
170-
171- // Operation 2
172- original = Error . prepareStackTrace ;
173- for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
174- assert . ok ( new Error ( ) . stack ) ;
175- Error . prepareStackTrace = original ;
176-
177- // Operation 3
178- original = Error . prepareStackTrace ;
179- for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
180- assert . ok ( new Error ( ) . stack ) ;
181- Error . prepareStackTrace = original ;
182-
183- // Operation 4
184- original = Error . prepareStackTrace ;
185- for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
186- assert . ok ( new Error ( ) . stack ) ;
187- Error . prepareStackTrace = original ;
188- } ) ;
189-
190- test ( "Never restored, separate operations" , ( ) => {
191- // Operation 1
192- for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
193- assert . ok ( new Error ( ) . stack ) ;
194-
195- // Operation 2
196- for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
197- assert . ok ( new Error ( ) . stack ) ;
198-
199- // Operation 3
200- for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
201- assert . ok ( new Error ( ) . stack ) ;
202157
203- // Operation 4
204- for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
205- assert . ok ( new Error ( ) . stack ) ;
206- } ) ;
207-
208- test ( "Restored, too many uses before restoration" , async ( ) => {
209- const original = Error . prepareStackTrace ;
210- Error . prepareStackTrace = ( _ , stack ) => stack ;
211158
212- // Operation 1 — more uses of `prepareStackTrace`
213- for ( let i = 0 ; i < 10_000 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
214- assert . ok ( new Error ( ) . stack ) ;
215-
216- Error . prepareStackTrace = original ;
159+ suite ( 'https://gist.github.com/thecrypticace/f0f2e182082072efdaf0f8e1537d2cce' , function ( ) {
160+
161+ test ( "Restored, separate operations" , ( ) => {
162+ // Actual Test
163+ let original ;
164+
165+ // Operation 1
166+ original = Error . prepareStackTrace ;
167+ for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
168+ const err1 = new Error ( ) ;
169+ assert . ok ( err1 . stack ) ;
170+ assert . strictEqual ( findSubstrCount , 1 ) ;
171+ Error . prepareStackTrace = original ;
172+
173+ // Operation 2
174+ original = Error . prepareStackTrace ;
175+ for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
176+ assert . ok ( new Error ( ) . stack ) ;
177+ assert . strictEqual ( findSubstrCount , 2 ) ;
178+ Error . prepareStackTrace = original ;
179+
180+ // Operation 3
181+ original = Error . prepareStackTrace ;
182+ for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
183+ assert . ok ( new Error ( ) . stack ) ;
184+ assert . strictEqual ( findSubstrCount , 3 ) ;
185+ Error . prepareStackTrace = original ;
186+
187+ // Operation 4
188+ original = Error . prepareStackTrace ;
189+ for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
190+ assert . ok ( new Error ( ) . stack ) ;
191+ assert . strictEqual ( findSubstrCount , 4 ) ;
192+ Error . prepareStackTrace = original ;
193+
194+ // Back to Operation 1
195+ assert . ok ( err1 . stack ) ;
196+ assert . strictEqual ( findSubstrCount , 4 ) ;
197+ } ) ;
198+
199+ test ( "Never restored, separate operations" , ( ) => {
200+ // Operation 1
201+ for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
202+ assert . ok ( new Error ( ) . stack ) ;
203+
204+ // Operation 2
205+ for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
206+ assert . ok ( new Error ( ) . stack ) ;
207+
208+ // Operation 3
209+ for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
210+ assert . ok ( new Error ( ) . stack ) ;
211+
212+ // Operation 4
213+ for ( let i = 0 ; i < 12_500 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
214+ assert . ok ( new Error ( ) . stack ) ;
215+ } ) ;
216+
217+ test ( "Restored, too many uses before restoration" , async ( ) => {
218+ const original = Error . prepareStackTrace ;
219+ Error . prepareStackTrace = ( _ , stack ) => stack ;
220+
221+ // Operation 1 — more uses of `prepareStackTrace`
222+ for ( let i = 0 ; i < 10_000 ; ++ i ) { Error . prepareStackTrace = Error . prepareStackTrace ; }
223+ assert . ok ( new Error ( ) . stack ) ;
224+
225+ Error . prepareStackTrace = original ;
226+ } ) ;
217227 } ) ;
218228} ) ;
0 commit comments