@@ -33,14 +33,25 @@ function debuggerPausedCallback(session, notification) {
3333 checkScope ( session , scopeId ) ;
3434}
3535
36- function testNoCrashWithExceptionInCallback ( ) {
36+ function waitForWarningSkipAsyncStackTraces ( resolve ) {
37+ process . once ( 'warning' , function ( warning ) {
38+ if ( warning . code === 'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE' ) {
39+ waitForWarningSkipAsyncStackTraces ( resolve ) ;
40+ } else {
41+ resolve ( warning ) ;
42+ }
43+ } ) ;
44+ }
45+
46+ async function testNoCrashWithExceptionInCallback ( ) {
3747 // There is a deliberate exception in the callback
3848 const session = new inspector . Session ( ) ;
3949 session . connect ( ) ;
4050 const error = new Error ( 'We expect this' ) ;
41- assert . throws ( ( ) => {
42- session . post ( 'Console.enable' , ( ) => { throw error ; } ) ;
43- } , ( e ) => e === error ) ;
51+ console . log ( 'Expecting warning to be emitted' ) ;
52+ const promise = new Promise ( waitForWarningSkipAsyncStackTraces ) ;
53+ session . post ( 'Console.enable' , ( ) => { throw error ; } ) ;
54+ assert . strictEqual ( await promise , error ) ;
4455 session . disconnect ( ) ;
4556}
4657
@@ -97,10 +108,33 @@ function testSampleDebugSession() {
97108 assert . throws ( ( ) => session . post ( 'Debugger.enable' ) , ( e ) => ! ! e ) ;
98109}
99110
100- testNoCrashWithExceptionInCallback ( ) ;
101- testSampleDebugSession ( ) ;
102- let breakpointHit = false ;
103- scopeCallback = ( ) => ( breakpointHit = true ) ;
104- debuggedFunction ( ) ;
105- assert . strictEqual ( breakpointHit , false ) ;
106- testSampleDebugSession ( ) ;
111+ async function testNoCrashConsoleLogBeforeThrow ( ) {
112+ const session = new inspector . Session ( ) ;
113+ session . connect ( ) ;
114+ let attempt = 1 ;
115+ process . on ( 'warning' , common . mustCall ( 3 ) ) ;
116+ session . on ( 'inspectorNotification' , ( ) => {
117+ if ( attempt ++ > 3 )
118+ return ;
119+ console . log ( 'console.log in handler' ) ;
120+ throw new Error ( 'Exception in handler' ) ;
121+ } ) ;
122+ session . post ( 'Runtime.enable' ) ;
123+ console . log ( 'Did not crash' ) ;
124+ session . disconnect ( ) ;
125+ }
126+
127+ common . crashOnUnhandledRejection ( ) ;
128+
129+ async function doTests ( ) {
130+ await testNoCrashWithExceptionInCallback ( ) ;
131+ testSampleDebugSession ( ) ;
132+ let breakpointHit = false ;
133+ scopeCallback = ( ) => ( breakpointHit = true ) ;
134+ debuggedFunction ( ) ;
135+ assert . strictEqual ( breakpointHit , false ) ;
136+ testSampleDebugSession ( ) ;
137+ await testNoCrashConsoleLogBeforeThrow ( ) ;
138+ }
139+
140+ doTests ( ) ;
0 commit comments