@@ -52,10 +52,14 @@ class ChromeProxyService implements VmServiceInterface {
52
52
/// are dynamic and roughly map to chrome tabs.
53
53
final VM _vm;
54
54
55
- final _initializedCompleter = Completer < void >();
56
-
55
+ /// Signals when isolate is intialized.
56
+ Completer < void > _initializedCompleter = Completer < void >();
57
57
Future <void > get isInitialized => _initializedCompleter.future;
58
58
59
+ /// Signals when expression compiler is ready to evaluate.
60
+ Completer <void > _compilerCompleter = Completer <void >();
61
+ Future <void > get isCompilerInitialized => _compilerCompleter.future;
62
+
59
63
/// The root URI at which we're serving.
60
64
final String uri;
61
65
@@ -165,10 +169,10 @@ class ChromeProxyService implements VmServiceInterface {
165
169
_skipLists.initialize ();
166
170
// We do not need to wait for compiler dependencies to be udpated as the
167
171
// [ExpressionEvaluator] is robust to evaluation requests during updates.
168
- unawaited (updateCompilerDependencies (entrypoint));
172
+ unawaited (_updateCompilerDependencies (entrypoint));
169
173
}
170
174
171
- Future <void > updateCompilerDependencies (String entrypoint) async {
175
+ Future <void > _updateCompilerDependencies (String entrypoint) async {
172
176
var metadataProvider = globalLoadStrategy.metadataProviderFor (entrypoint);
173
177
var moduleFormat = globalLoadStrategy.moduleFormat;
174
178
var soundNullSafety = await metadataProvider.soundNullSafety;
@@ -183,6 +187,8 @@ class ChromeProxyService implements VmServiceInterface {
183
187
await globalLoadStrategy.moduleInfoForEntrypoint (entrypoint);
184
188
var stopwatch = Stopwatch ()..start ();
185
189
await _compiler.updateDependencies (dependencies);
190
+ // Expression evaluation is ready after dependencies are updated.
191
+ if (! _compilerCompleter.isCompleted) _compilerCompleter.complete ();
186
192
emitEvent (DwdsEvent ('COMPILER_UPDATE_DEPENDENCIES' , {
187
193
'entrypoint' : entrypoint,
188
194
'elapsedMilliseconds' : stopwatch.elapsedMilliseconds,
@@ -273,6 +279,8 @@ class ChromeProxyService implements VmServiceInterface {
273
279
void destroyIsolate () {
274
280
var isolate = _inspector? .isolate;
275
281
if (isolate == null ) return ;
282
+ _initializedCompleter = Completer <void >();
283
+ _compilerCompleter = Completer <void >();
276
284
_streamNotify (
277
285
'Isolate' ,
278
286
Event (
@@ -299,9 +307,11 @@ class ChromeProxyService implements VmServiceInterface {
299
307
300
308
@override
301
309
Future <Breakpoint > addBreakpoint (String isolateId, String scriptId, int line,
302
- {int column}) async =>
303
- (await _debugger)
304
- .addBreakpoint (isolateId, scriptId, line, column: column);
310
+ {int column}) async {
311
+ await isInitialized;
312
+ return (await _debugger)
313
+ .addBreakpoint (isolateId, scriptId, line, column: column);
314
+ }
305
315
306
316
@override
307
317
Future <Breakpoint > addBreakpointAtEntry (String isolateId, String functionId) {
@@ -312,6 +322,7 @@ class ChromeProxyService implements VmServiceInterface {
312
322
Future <Breakpoint > addBreakpointWithScriptUri (
313
323
String isolateId, String scriptUri, int line,
314
324
{int column}) async {
325
+ await isInitialized;
315
326
var dartUri = DartUri (scriptUri, uri);
316
327
var ref = await _inspector.scriptRefFor (dartUri.serverPath);
317
328
return (await _debugger)
@@ -321,6 +332,7 @@ class ChromeProxyService implements VmServiceInterface {
321
332
@override
322
333
Future <Response > callServiceExtension (String method,
323
334
{String isolateId, Map args}) async {
335
+ await isInitialized;
324
336
// Validate the isolate id is correct, _getIsolate throws if not.
325
337
if (isolateId != null ) _getIsolate (isolateId);
326
338
args ?? = < String , String > {};
@@ -413,7 +425,9 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
413
425
dynamic error;
414
426
415
427
try {
428
+ await isInitialized;
416
429
if (_expressionEvaluator != null ) {
430
+ await isCompilerInitialized;
417
431
_validateIsolateId (isolateId);
418
432
419
433
var library = await _inspector? .getLibrary (isolateId, targetId);
@@ -453,7 +467,9 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
453
467
dynamic error;
454
468
455
469
try {
470
+ await isInitialized;
456
471
if (_expressionEvaluator != null ) {
472
+ await isCompilerInitialized;
457
473
_validateIsolateId (isolateId);
458
474
459
475
var result = await _getEvaluationResult (
@@ -516,25 +532,38 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
516
532
}
517
533
518
534
@override
519
- Future <Isolate > getIsolate (String isolateId) async => _getIsolate (isolateId);
535
+ Future <Isolate > getIsolate (String isolateId) async {
536
+ await isInitialized;
537
+ return _getIsolate (isolateId);
538
+ }
520
539
521
540
@override
522
- Future <MemoryUsage > getMemoryUsage (String isolateId) {
541
+ Future <MemoryUsage > getMemoryUsage (String isolateId) async {
542
+ await isInitialized;
523
543
return _inspector.getMemoryUsage (isolateId);
524
544
}
525
545
526
546
@override
527
547
Future <Obj > getObject (String isolateId, String objectId,
528
- {int offset, int count}) =>
529
- _inspector? .getObject (isolateId, objectId, offset: offset, count: count);
548
+ {int offset, int count}) async {
549
+ await isInitialized;
550
+ return _inspector? .getObject (isolateId, objectId,
551
+ offset: offset, count: count);
552
+ }
530
553
531
554
@override
532
- Future <ScriptList > getScripts (String isolateId) =>
533
- _inspector? .getScripts (isolateId);
555
+ Future <ScriptList > getScripts (String isolateId) async {
556
+ await isInitialized;
557
+ return _inspector? .getScripts (isolateId);
558
+ }
534
559
535
560
@override
536
561
Future <SourceReport > getSourceReport (String isolateId, List <String > reports,
537
- {String scriptId, int tokenPos, int endTokenPos, bool forceCompile}) {
562
+ {String scriptId,
563
+ int tokenPos,
564
+ int endTokenPos,
565
+ bool forceCompile}) async {
566
+ await isInitialized;
538
567
return _inspector? .getSourceReport (isolateId, reports,
539
568
scriptId: scriptId,
540
569
tokenPos: tokenPos,
@@ -548,8 +577,10 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
548
577
///
549
578
/// The returned stack will contain up to [limit] frames if provided.
550
579
@override
551
- Future <Stack > getStack (String isolateId, {int limit}) async =>
552
- (await _debugger).getStack (isolateId, limit: limit);
580
+ Future <Stack > getStack (String isolateId, {int limit}) async {
581
+ await isInitialized;
582
+ return (await _debugger).getStack (isolateId, limit: limit);
583
+ }
553
584
554
585
@override
555
586
Future <VM > getVM () async {
@@ -577,6 +608,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
577
608
Future <Response > invoke (
578
609
String isolateId, String targetId, String selector, List argumentIds,
579
610
{bool disableBreakpoints}) async {
611
+ await isInitialized;
580
612
// TODO(798) - respect disableBreakpoints.
581
613
var remote =
582
614
await _inspector? .invoke (isolateId, targetId, selector, argumentIds);
@@ -633,7 +665,10 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
633
665
}
634
666
635
667
@override
636
- Future <Success > pause (String isolateId) async => (await _debugger).pause ();
668
+ Future <Success > pause (String isolateId) async {
669
+ await isInitialized;
670
+ return (await _debugger).pause ();
671
+ }
637
672
638
673
@override
639
674
Future <Success > registerService (String service, String alias) async {
@@ -653,6 +688,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
653
688
@override
654
689
Future <Success > removeBreakpoint (
655
690
String isolateId, String breakpointId) async {
691
+ await isInitialized;
656
692
_disabledBreakpoints
657
693
.removeWhere ((breakpoint) => breakpoint.id == breakpointId);
658
694
return (await _debugger).removeBreakpoint (isolateId, breakpointId);
@@ -664,6 +700,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
664
700
if (_inspector == null ) throw StateError ('No running isolate.' );
665
701
if (_inspector.appConnection.isStarted) {
666
702
var stopwatch = Stopwatch ()..start ();
703
+ await isInitialized;
667
704
var result = await (await _debugger)
668
705
.resume (isolateId, step: step, frameIndex: frameIndex);
669
706
emitEvent (DwdsEvent ('RESUME' , {
@@ -679,6 +716,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
679
716
680
717
@override
681
718
Future <Success > setExceptionPauseMode (String isolateId, String mode) async {
719
+ await isInitialized;
682
720
return (await _debugger).setExceptionPauseMode (isolateId, mode);
683
721
}
684
722
@@ -695,6 +733,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
695
733
696
734
@override
697
735
Future <Success > setName (String isolateId, String name) async {
736
+ await isInitialized;
698
737
var isolate = _getIsolate (isolateId);
699
738
isolate.name = name;
700
739
return Success ();
0 commit comments