Skip to content

Commit 627dee5

Browse files
author
Anna Gringauze
committed
Addressed CR comments
1 parent 1df7c11 commit 627dee5

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

dwds/lib/src/events.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77
import 'dart:async';
88

99
class DwdsStats {
10+
/// Timestamp for the point when the user starts the debugger
11+
/// by either clicking the debugger extension button or
12+
/// starting debugging in the UI.
1013
final DateTime debuggerStart;
11-
DateTime _debuggerReady;
12-
13-
DateTime get debuggerReady {
14-
return _debuggerReady;
15-
}
1614

17-
set debuggerReady(DateTime value) {
18-
if (_debuggerReady != null) return;
19-
_debuggerReady = value;
20-
}
15+
/// Timestamp for the point when the debugger becomes
16+
/// available and fuctional for the user.
17+
DateTime _debuggerReady;
18+
DateTime get debuggerReady => _debuggerReady;
19+
set debuggerReady(DateTime value) => _debuggerReady ??= value;
2120

2221
int get debuggerReadyElapsed {
22+
if (debuggerStart == null) {
23+
throw StateError('debuggerStart is not set in DwdsStats');
24+
}
2325
if (_debuggerReady == null) {
2426
throw StateError('debuggerReady is not set in DwdsStats');
2527
}

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
428428
bool disableBreakpoints,
429429
}) async {
430430
// TODO(798) - respect disableBreakpoints.
431-
return withEvent(() async {
431+
return _withEvent(() async {
432432
await isInitialized;
433433
if (_expressionEvaluator != null) {
434434
await isCompilerInitialized;
@@ -448,7 +448,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
448448
(result) => DwdsEvent('EVALUATE', {
449449
'expression': expression,
450450
'success': result != null && result is InstanceRef,
451-
if (result is ErrorRef) 'error': result,
451+
if (result != null && result is ErrorRef) 'error': result,
452452
}));
453453
}
454454

@@ -458,7 +458,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
458458
{Map<String, String> scope, bool disableBreakpoints}) async {
459459
// TODO(798) - respect disableBreakpoints.
460460

461-
return withEvent(() async {
461+
return _withEvent(() async {
462462
await isInitialized;
463463
if (_expressionEvaluator != null) {
464464
await isCompilerInitialized;
@@ -485,7 +485,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
485485
(result) => DwdsEvent('EVALUATE_IN_FRAME', {
486486
'expression': expression,
487487
'success': result != null && result is InstanceRef,
488-
if (result is ErrorRef) 'error': result,
488+
if (result != null && result is ErrorRef) 'error': result,
489489
}));
490490
}
491491

@@ -525,7 +525,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
525525

526526
@override
527527
Future<Isolate> getIsolate(String isolateId) async {
528-
return withEvent(() async {
528+
return _withEvent(() async {
529529
await isInitialized;
530530
return _getIsolate(isolateId);
531531
}, (result) => DwdsEvent('GET_ISOLATE', {}));
@@ -540,16 +540,19 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
540540
@override
541541
Future<Obj> getObject(String isolateId, String objectId,
542542
{int offset, int count}) async {
543-
return await withEvent(() async {
543+
return await _withEvent(() async {
544544
await isInitialized;
545545
return await _inspector?.getObject(isolateId, objectId,
546546
offset: offset, count: count);
547-
}, (result) => DwdsEvent('GET_OBJECT', {'type': result.type}));
547+
},
548+
(result) => DwdsEvent('GET_OBJECT', {
549+
if (result != null) 'type': result.type,
550+
}));
548551
}
549552

550553
@override
551554
Future<ScriptList> getScripts(String isolateId) async {
552-
return await withEvent(() async {
555+
return await _withEvent(() async {
553556
await isInitialized;
554557
return await _inspector?.getScripts(isolateId);
555558
}, (result) => DwdsEvent('GET_SCRIPTS', {}));
@@ -562,7 +565,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
562565
int endTokenPos,
563566
bool forceCompile,
564567
bool reportLines}) async {
565-
var result = await withEvent(() async {
568+
var result = await _withEvent(() async {
566569
await isInitialized;
567570
return await _inspector?.getSourceReport(isolateId, reports,
568571
scriptId: scriptId,
@@ -595,7 +598,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
595598

596599
@override
597600
Future<VM> getVM() async {
598-
return withEvent(() async {
601+
return _withEvent(() async {
599602
await isInitialized;
600603
return _vm;
601604
}, (result) => DwdsEvent('GET_VM', {}));
@@ -1069,7 +1072,12 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
10691072
String isolateId, String breakpointId, bool enable) =>
10701073
throw UnimplementedError();
10711074

1072-
Future<T> withEvent<T>(
1075+
/// Call [function] and record its execution time.
1076+
///
1077+
/// Calls [event] to create the event to be recorded,
1078+
/// and appends time and exception details to it if
1079+
/// available.
1080+
Future<T> _withEvent<T>(
10731081
Future<T> Function() function, DwdsEvent Function(T result) event) async {
10741082
var stopwatch = Stopwatch()..start();
10751083
T result;

0 commit comments

Comments
 (0)