@@ -91,14 +91,14 @@ class WorkerSession extends EventEmitter {
91
91
this . emit ( message . method , message ) ;
92
92
return ;
93
93
}
94
- const callback = this . _requestCallbacks . get ( message . id ) ;
95
- if ( callback ) {
96
- this . _requestCallbacks . delete ( message . id ) ;
97
- if ( message . error )
98
- callback [ 1 ] ( message . error . message ) ;
99
- else
100
- callback [ 0 ] ( message . result ) ;
101
- }
94
+ if ( ! this . _requestCallbacks . has ( message . id ) )
95
+ return ;
96
+ const [ resolve , reject ] = this . _requestCallbacks . get ( message . id ) ;
97
+ this . _requestCallbacks . delete ( message . id ) ;
98
+ if ( message . error )
99
+ reject ( new Error ( message . error . message ) ) ;
100
+ else
101
+ resolve ( message . result ) ;
102
102
}
103
103
104
104
async waitForBreakAfterCommand ( command , script , line ) {
@@ -144,7 +144,7 @@ async function testBasicWorkerDebug(session, post) {
144
144
assert . strictEqual ( waitingForDebugger , true ) ;
145
145
const detached = waitForWorkerDetach ( session , sessionId ) ;
146
146
const workerSession = new WorkerSession ( session , sessionId ) ;
147
- const contextEvents = Promise . all ( [
147
+ const contextEventPromises = Promise . all ( [
148
148
waitForEvent ( workerSession , 'Runtime.executionContextCreated' ) ,
149
149
waitForEvent ( workerSession , 'Runtime.executionContextDestroyed' )
150
150
] ) ;
@@ -156,9 +156,10 @@ async function testBasicWorkerDebug(session, post) {
156
156
'Runtime.runIfWaitingForDebugger' , __filename , 1 ) ;
157
157
await workerSession . waitForBreakAfterCommand (
158
158
'Debugger.resume' , __filename , 26 ) ; // V8 line number is zero-based
159
- assert . strictEqual ( await consolePromise , workerMessage ) ;
159
+ const msg = await consolePromise ;
160
+ assert . strictEqual ( msg , workerMessage ) ;
160
161
workerSession . post ( 'Debugger.resume' ) ;
161
- await Promise . all ( [ worker , detached , contextEvents ] ) ;
162
+ await Promise . all ( [ worker , detached , contextEventPromises ] ) ;
162
163
}
163
164
164
165
async function testNoWaitOnStart ( session , post ) {
@@ -252,7 +253,7 @@ async function testWaitForDisconnectInWorker(session, post) {
252
253
sessionWithoutWaiting . disconnect ( ) ;
253
254
}
254
255
255
- async function test ( ) {
256
+ ( async function test ( ) {
256
257
const session = new Session ( ) ;
257
258
session . connect ( ) ;
258
259
const post = doPost . bind ( null , session ) ;
@@ -264,11 +265,14 @@ async function test() {
264
265
await runWorker ( 1 ) ;
265
266
266
267
await testNoWaitOnStart ( session , post ) ;
268
+
267
269
await testTwoWorkers ( session , post ) ;
270
+
268
271
await testWaitForDisconnectInWorker ( session , post ) ;
269
272
270
273
session . disconnect ( ) ;
271
274
console . log ( 'Test done' ) ;
272
- }
273
-
274
- test ( ) ;
275
+ } ) ( ) . catch ( ( err ) => {
276
+ console . error ( err ) ;
277
+ process . abort ( ) ;
278
+ } ) ;
0 commit comments