Skip to content

Commit 36561ff

Browse files
author
Anna Gringauze
authored
Migrate some dwds files to null safety (#1635)
* Remove dead code * Remove abstract ResidentCompiler class * Migrate events and utilities to null safety * Migrate some of dwds files to null safety * Update test infrastructure code * Built * Remove unneded null check * Address CR comments * Addressed CR comments * Addressed CR comments
1 parent e17ec62 commit 36561ff

28 files changed

+604
-450
lines changed

dwds/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 14.0.4-dev
2+
- Port some `dwds` files to null safety.
3+
14
## 14.0.3
25
- Make data types null safe.
36
- Update `package:vm_service` to 8.3.0.

dwds/lib/asset_reader.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
export 'src/readers/asset_reader.dart' show AssetReader, UrlEncoder;

dwds/lib/dwds.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ export 'src/loaders/frontend_server_require.dart'
4040
export 'src/loaders/legacy.dart' show LegacyStrategy;
4141
export 'src/loaders/require.dart' show RequireStrategy;
4242
export 'src/loaders/strategy.dart' show LoadStrategy, ReloadConfiguration;
43-
export 'src/readers/asset_reader.dart' show AssetReader;
43+
export 'src/readers/asset_reader.dart' show AssetReader, UrlEncoder;
4444
export 'src/readers/frontend_server_asset_reader.dart'
4545
show FrontendServerAssetReader;
4646
export 'src/readers/proxy_server_asset_reader.dart' show ProxyServerAssetReader;
4747
export 'src/servers/devtools.dart';
48-
export 'src/services/chrome_proxy_service.dart' show ChromeDebugException;
48+
export 'src/services/chrome_debug_exception.dart' show ChromeDebugException;
4949
export 'src/services/expression_compiler.dart'
5050
show ExpressionCompilationResult, ExpressionCompiler, ModuleInfo;
5151
export 'src/services/expression_compiler_service.dart'
@@ -54,7 +54,6 @@ export 'src/utilities/sdk_configuration.dart'
5454
show SdkConfiguration, SdkConfigurationProvider;
5555

5656
typedef ConnectionProvider = Future<ChromeConnection> Function();
57-
typedef UrlEncoder = Future<String> Function(String url);
5857

5958
/// The Dart Web Debug Service.
6059
class Dwds {

dwds/lib/expression_compiler.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
export 'src/services/expression_compiler.dart'
6+
show ExpressionCompilationResult, ExpressionCompiler, ModuleInfo;

dwds/lib/src/debugging/debugger.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
1616

1717
import '../loaders/strategy.dart';
1818
import '../services/chrome_proxy_service.dart';
19+
import '../services/chrome_debug_exception.dart';
1920
import '../utilities/conversions.dart';
2021
import '../utilities/dart_uri.dart';
2122
import '../utilities/domain.dart';

dwds/lib/src/debugging/execution_context.dart

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'dart:async';
86

97
import 'package:async/async.dart';
@@ -21,14 +19,17 @@ class RemoteDebuggerExecutionContext extends ExecutionContext {
2119
final RemoteDebugger _remoteDebugger;
2220
final _logger = Logger('RemoteDebuggerExecutionContext');
2321

24-
// Contexts that may contain a Dart application.
25-
StreamQueue<int> _contexts;
22+
/// Contexts that may contain a Dart application.
23+
///
24+
/// Context can be null if an error has occured and we cannot detect
25+
/// and parse the context ID.
26+
late StreamQueue<int> _contexts;
2627

27-
int _id;
28+
int? _id;
2829

2930
@override
3031
Future<int> get id async {
31-
if (_id != null) return _id;
32+
if (_id != null) return _id!;
3233
_logger.fine('Looking for Dart execution context...');
3334
const timeoutInMs = 100;
3435
while (await _contexts.hasNext
@@ -45,7 +46,7 @@ class RemoteDebuggerExecutionContext extends ExecutionContext {
4546
'expression': r'window["$dartAppInstanceId"];',
4647
'contextId': context,
4748
});
48-
if (result.result['result']['value'] != null) {
49+
if (result.result?['result']?['value'] != null) {
4950
_logger.fine('Found valid execution context: $context');
5051
_id = context;
5152
break;
@@ -59,18 +60,30 @@ class RemoteDebuggerExecutionContext extends ExecutionContext {
5960
if (_id == null) {
6061
throw StateError('No context with the running Dart application.');
6162
}
62-
return _id;
63+
return _id!;
6364
}
6465

6566
RemoteDebuggerExecutionContext(this._id, this._remoteDebugger) {
6667
final contextController = StreamController<int>();
6768
_remoteDebugger
6869
.eventStream('Runtime.executionContextsCleared', (e) => e)
6970
.listen((_) => _id = null);
70-
_remoteDebugger
71-
.eventStream('Runtime.executionContextCreated',
72-
(e) => int.parse(e.params['context']['id'].toString()))
73-
.listen(contextController.add);
71+
_remoteDebugger.eventStream('Runtime.executionContextCreated', (e) {
72+
// Parse and add the context ID to the stream.
73+
// If we cannot detect or parse the context ID, add `null` to the stream
74+
// to indicate an error context - those will be skipped when trying to find
75+
// the dart context, with a warning.
76+
final id = e.params?['context']?['id']?.toString();
77+
final parsedId = id == null ? null : int.parse(id);
78+
if (id == null) {
79+
_logger.warning('Cannot find execution context id: $e');
80+
} else if (parsedId == null) {
81+
_logger.warning('Cannot parse execution context id: $id');
82+
}
83+
return parsedId;
84+
}).listen((e) {
85+
if (e != null) contextController.add(e);
86+
});
7487
_contexts = StreamQueue(contextController.stream);
7588
}
7689
}

dwds/lib/src/debugging/metadata/class.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../../debugging/classes.dart';
1111
import '../../debugging/inspector.dart';
1212
import '../../debugging/remote_debugger.dart';
1313
import '../../loaders/strategy.dart';
14-
import '../../services/chrome_proxy_service.dart';
14+
import '../../services/chrome_debug_exception.dart';
1515

1616
/// Meta data for a remote Dart class in Chrome.
1717
class ClassMetaData {

dwds/lib/src/debugging/remote_debugger.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
86

97
class TargetCrashedEvent extends WipEvent {
@@ -31,7 +29,7 @@ abstract class RemoteDebugger {
3129
Stream<void> get onClose;
3230

3331
Future<WipResponse> sendCommand(String command,
34-
{Map<String, dynamic> params});
32+
{Map<String, dynamic>? params});
3533

3634
Future<void> disable();
3735

@@ -47,18 +45,18 @@ abstract class RemoteDebugger {
4745

4846
Future<WipResponse> removeBreakpoint(String breakpointId);
4947

50-
Future<WipResponse> stepInto({Map<String, dynamic> params});
48+
Future<WipResponse> stepInto({Map<String, dynamic>? params});
5149

5250
Future<WipResponse> stepOut();
5351

54-
Future<WipResponse> stepOver({Map<String, dynamic> params});
52+
Future<WipResponse> stepOver({Map<String, dynamic>? params});
5553

5654
Future<WipResponse> enablePage();
5755

5856
Future<WipResponse> pageReload();
5957

6058
Future<RemoteObject> evaluate(String expression,
61-
{bool returnByValue, int contextId});
59+
{bool? returnByValue, int? contextId});
6260

6361
Future<RemoteObject> evaluateOnCallFrame(
6462
String callFrameId, String expression);

dwds/lib/src/debugging/webkit_debugger.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
86

97
import 'remote_debugger.dart';
@@ -15,7 +13,7 @@ class WebkitDebugger implements RemoteDebugger {
1513
/// Null until [close] is called.
1614
///
1715
/// All subsequent calls to [close] will return this future.
18-
Future<void> _closed;
16+
Future<void>? _closed;
1917

2018
WebkitDebugger(this._wipDebugger);
2119

@@ -29,7 +27,7 @@ class WebkitDebugger implements RemoteDebugger {
2927

3028
@override
3129
Future<WipResponse> sendCommand(String command,
32-
{Map<String, dynamic> params}) =>
30+
{Map<String, dynamic>? params}) =>
3331
_wipDebugger.sendCommand(command, params: params);
3432

3533
@override
@@ -60,14 +58,14 @@ class WebkitDebugger implements RemoteDebugger {
6058
_wipDebugger.removeBreakpoint(breakpointId);
6159

6260
@override
63-
Future<WipResponse> stepInto({Map<String, dynamic> params}) =>
61+
Future<WipResponse> stepInto({Map<String, dynamic>? params}) =>
6462
_wipDebugger.stepInto(params: params);
6563

6664
@override
6765
Future<WipResponse> stepOut() => _wipDebugger.stepOut();
6866

6967
@override
70-
Future<WipResponse> stepOver({Map<String, dynamic> params}) =>
68+
Future<WipResponse> stepOver({Map<String, dynamic>? params}) =>
7169
_wipDebugger.stepOver(params: params);
7270

7371
@override
@@ -78,7 +76,7 @@ class WebkitDebugger implements RemoteDebugger {
7876

7977
@override
8078
Future<RemoteObject> evaluate(String expression,
81-
{bool returnByValue, int contextId}) {
79+
{bool? returnByValue, int? contextId}) {
8280
return _wipDebugger.connection.runtime
8381
.evaluate(expression, returnByValue: returnByValue);
8482
}

dwds/lib/src/events.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'dart:async';
86

97
import 'package:vm_service/vm_service.dart';
108

119
class DwdsStats {
1210
/// The time when the user starts the debugger.
13-
DateTime _debuggerStart;
11+
late DateTime _debuggerStart;
1412
DateTime get debuggerStart => _debuggerStart;
1513

1614
/// The time when dwds launches DevTools.
17-
DateTime _devToolsStart;
15+
late DateTime _devToolsStart;
1816
DateTime get devToolsStart => _devToolsStart;
1917

2018
/// Records and returns weither the debugger is ready.
@@ -25,7 +23,8 @@ class DwdsStats {
2523
return wasReady;
2624
}
2725

28-
void updateLoadTime({DateTime debuggerStart, DateTime devToolsStart}) {
26+
void updateLoadTime(
27+
{required DateTime debuggerStart, required DateTime devToolsStart}) {
2928
_debuggerStart = debuggerStart;
3029
_devToolsStart = devToolsStart;
3130
}
@@ -66,14 +65,14 @@ class DwdsEvent {
6665

6766
DwdsEvent.devtoolsLaunch() : this(DwdsEventKind.devtoolsLaunch, {});
6867

69-
DwdsEvent.evaluate(String expression, Response result)
68+
DwdsEvent.evaluate(String expression, Response? result)
7069
: this(DwdsEventKind.evaluate, {
7170
'expression': expression,
7271
'success': result != null && result is InstanceRef,
7372
if (result != null && result is ErrorRef) 'error': result,
7473
});
7574

76-
DwdsEvent.evaluateInFrame(String expression, Response result)
75+
DwdsEvent.evaluateInFrame(String expression, Response? result)
7776
: this(DwdsEventKind.evaluateInFrame, {
7877
'expression': expression,
7978
'success': result != null && result is InstanceRef,
@@ -140,13 +139,13 @@ Stream<DwdsEvent> get eventStream => _eventController.stream;
140139
/// and appends time and exception details to it if
141140
/// available.
142141
Future<T> captureElapsedTime<T>(
143-
Future<T> Function() function, DwdsEvent Function(T result) event) async {
142+
Future<T> Function() function, DwdsEvent Function(T? result) event) async {
144143
final stopwatch = Stopwatch()..start();
145-
T result;
144+
T? result;
146145
try {
147146
return result = await function();
148147
} catch (e) {
149-
emitEvent(event(result)
148+
emitEvent(event(null)
150149
..addException(e)
151150
..addElapsedTime(stopwatch.elapsedMilliseconds));
152151
rethrow;

0 commit comments

Comments
 (0)