@@ -73,10 +73,7 @@ class DocumentLinter {
73
73
let parser ;
74
74
try {
75
75
process = await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
76
- // BEGIN CRITICAL SECTION (no awaiting below)
77
- this . _documentProcessManager . checkIfProcessCrashed ( process ) ;
78
76
parser = process . createDocumentForVSCode ( ) ;
79
- // END CRITICAL SECTION (no awaiting above)
80
77
} catch ( e ) {
81
78
if ( e instanceof ProcessCrashed ) {
82
79
this . _documentProcessManager . processCrashed ( process ) ;
@@ -121,12 +118,7 @@ class DocumentLinter {
121
118
}
122
119
if ( this . _parser !== null ) {
123
120
try {
124
- // BEGIN CRITICAL SECTION (no awaiting below)
125
- this . _documentProcessManager . checkIfProcessCrashed (
126
- this . _parser . process
127
- ) ;
128
121
this . _parser . dispose ( ) ;
129
- // END CRITICAL SECTION (no awaiting above)
130
122
} catch ( e ) {
131
123
if ( e instanceof ProcessCrashed ) {
132
124
this . _documentProcessManager . processCrashed ( this . _parser . process ) ;
@@ -206,21 +198,13 @@ class DocumentLinter {
206
198
case DocumentLinterState . PARSER_LOADED :
207
199
this . _pendingChanges . push ( ...changes ) ;
208
200
try {
209
- this . _documentProcessManager . checkIfProcessCrashed (
210
- this . _parser . process
211
- ) ;
212
201
for ( let change of this . _pendingChanges ) {
213
202
this . _parser . replaceText ( change . range , change . text ) ;
214
203
}
215
204
this . _pendingChanges . length = 0 ;
216
205
// END CRITICAL SECTION (no awaiting above)
217
206
218
- // BEGIN CRITICAL SECTION (no awaiting below)
219
- this . _documentProcessManager . checkIfProcessCrashed (
220
- this . _parser . process
221
- ) ;
222
207
let diags = this . _parser . lint ( ) ;
223
- // END CRITICAL SECTION (no awaiting above)
224
208
this . _document . setDiagnostics ( diags ) ;
225
209
} catch ( e ) {
226
210
// END CRITICAL SECTION (no awaiting above)
@@ -254,7 +238,6 @@ class DocumentLinter {
254
238
// BEGIN CRITICAL SECTION (no awaiting below)
255
239
assertEqual ( this . _state , DocumentLinterState . PARSER_UNINITIALIZED ) ;
256
240
try {
257
- this . _documentProcessManager . checkIfProcessCrashed ( this . _parser . process ) ;
258
241
this . _parser . replaceText (
259
242
{
260
243
start : { line : 0 , character : 0 } ,
@@ -266,10 +249,7 @@ class DocumentLinter {
266
249
this . _state = DocumentLinterState . PARSER_LOADED ;
267
250
// END CRITICAL SECTION (no awaiting above)
268
251
269
- // BEGIN CRITICAL SECTION (no awaiting below)
270
- this . _documentProcessManager . checkIfProcessCrashed ( this . _parser . process ) ;
271
252
let diags = this . _parser . lint ( ) ;
272
- // END CRITICAL SECTION (no awaiting above)
273
253
this . _document . setDiagnostics ( diags ) ;
274
254
} catch ( e ) {
275
255
if ( e instanceof ProcessCrashed ) {
@@ -293,14 +273,10 @@ class DocumentLinter {
293
273
let process ;
294
274
try {
295
275
process = await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
296
- // BEGIN CRITICAL SECTION (no awaiting below)
297
- this . _documentProcessManager . checkIfProcessCrashed ( process ) ;
298
276
let parser = process . createDocumentForVSCode ( ) ;
299
- // END CRITICAL SECTION (no awaiting above)
300
277
301
278
// BEGIN CRITICAL SECTION (no awaiting below)
302
279
assertEqual ( this . _state , DocumentLinterState . RECOVERING ) ;
303
- this . _documentProcessManager . checkIfProcessCrashed ( process ) ;
304
280
parser . replaceText (
305
281
{
306
282
start : { line : 0 , character : 0 } ,
@@ -313,10 +289,7 @@ class DocumentLinter {
313
289
this . _state = DocumentLinterState . PARSER_LOADED ;
314
290
// END CRITICAL SECTION (no awaiting above)
315
291
316
- // BEGIN CRITICAL SECTION (no awaiting below)
317
- this . _documentProcessManager . checkIfProcessCrashed ( process ) ;
318
292
diags = parser . lint ( ) ;
319
- // END CRITICAL SECTION (no awaiting above)
320
293
} catch ( e ) {
321
294
this . _parser = null ;
322
295
this . _parserPromise = null ;
@@ -355,15 +328,6 @@ class DocumentProcessManager {
355
328
}
356
329
}
357
330
358
- checkIfProcessCrashed ( process ) {
359
- if ( ! ( process instanceof Process ) ) {
360
- throw new TypeError ( `Expected Process, but got ${ process } ` ) ;
361
- }
362
- if ( this . _process !== process ) {
363
- throw new ProcessCrashed ( ) ;
364
- }
365
- }
366
-
367
331
async createNewProcessAsync ( ) {
368
332
let processFactory = await this . _processFactoryPromise ;
369
333
let process = await processFactory . createProcessAsync ( ) ;
@@ -490,12 +454,12 @@ let nextProcessIDForDebugging = 1;
490
454
// A WebAssembly instance.
491
455
//
492
456
// If a Process crashes, every DocumentForVSCode or DocumentForWebDemo
493
- // associated with its creating Process is tainted and should not be used
494
- // anymore.
457
+ // associated with its creating Process is tainted.
495
458
class Process {
496
459
constructor ( wasmInstance ) {
497
460
this . _idForDebugging = nextProcessIDForDebugging ++ ;
498
461
this . _wasmInstance = wasmInstance ;
462
+ this . _crashedException = null ;
499
463
500
464
let process = this ;
501
465
function wrap ( name ) {
@@ -504,11 +468,21 @@ class Process {
504
468
}
505
469
let func = wasmInstance . exports [ name ] ;
506
470
return ( ...args ) => {
507
- exports . maybeInjectFault ( process , name ) ;
471
+ if ( process . _crashedException !== null ) {
472
+ throw process . _crashedException ;
473
+ }
508
474
try {
509
- return func ( ...args ) ;
475
+ exports . maybeInjectFault ( process , name ) ;
476
+ try {
477
+ return func ( ...args ) ;
478
+ } catch ( e ) {
479
+ throw new ProcessCrashedWithUnknownError ( e ) ;
480
+ }
510
481
} catch ( e ) {
511
- throw new ProcessCrashedWithUnknownError ( e ) ;
482
+ if ( e instanceof ProcessCrashed ) {
483
+ process . _crashedException = e ;
484
+ }
485
+ throw e ;
512
486
}
513
487
} ;
514
488
}
0 commit comments