Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 14.0.4-dev
- Port some `dwds` files to null safety.

## 14.0.3
- Make data types null safe.
- Update `package:vm_service` to 8.3.0.
Expand Down
5 changes: 5 additions & 0 deletions dwds/lib/asset_reader.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'src/readers/asset_reader.dart' show AssetReader, UrlEncoder;
5 changes: 2 additions & 3 deletions dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export 'src/loaders/frontend_server_require.dart'
export 'src/loaders/legacy.dart' show LegacyStrategy;
export 'src/loaders/require.dart' show RequireStrategy;
export 'src/loaders/strategy.dart' show LoadStrategy, ReloadConfiguration;
export 'src/readers/asset_reader.dart' show AssetReader;
export 'src/readers/asset_reader.dart' show AssetReader, UrlEncoder;
export 'src/readers/frontend_server_asset_reader.dart'
show FrontendServerAssetReader;
export 'src/readers/proxy_server_asset_reader.dart' show ProxyServerAssetReader;
export 'src/servers/devtools.dart';
export 'src/services/chrome_proxy_service.dart' show ChromeDebugException;
export 'src/services/chrome_debug_exception.dart' show ChromeDebugException;
export 'src/services/expression_compiler.dart'
show ExpressionCompilationResult, ExpressionCompiler, ModuleInfo;
export 'src/services/expression_compiler_service.dart'
Expand All @@ -54,7 +54,6 @@ export 'src/utilities/sdk_configuration.dart'
show SdkConfiguration, SdkConfigurationProvider;

typedef ConnectionProvider = Future<ChromeConnection> Function();
typedef UrlEncoder = Future<String> Function(String url);

/// The Dart Web Debug Service.
class Dwds {
Expand Down
6 changes: 6 additions & 0 deletions dwds/lib/expression_compiler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'src/services/expression_compiler.dart'
show ExpressionCompilationResult, ExpressionCompiler, ModuleInfo;
1 change: 1 addition & 0 deletions dwds/lib/src/debugging/debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'

import '../loaders/strategy.dart';
import '../services/chrome_proxy_service.dart';
import '../services/chrome_debug_exception.dart';
import '../utilities/conversions.dart';
import '../utilities/dart_uri.dart';
import '../utilities/domain.dart';
Expand Down
37 changes: 25 additions & 12 deletions dwds/lib/src/debugging/execution_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';

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

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

int _id;
int? _id;

@override
Future<int> get id async {
if (_id != null) return _id;
if (_id != null) return _id!;
_logger.fine('Looking for Dart execution context...');
const timeoutInMs = 100;
while (await _contexts.hasNext
Expand All @@ -45,7 +46,7 @@ class RemoteDebuggerExecutionContext extends ExecutionContext {
'expression': r'window["$dartAppInstanceId"];',
'contextId': context,
});
if (result.result['result']['value'] != null) {
if (result.result?['result']?['value'] != null) {
_logger.fine('Found valid execution context: $context');
_id = context;
break;
Expand All @@ -59,18 +60,30 @@ class RemoteDebuggerExecutionContext extends ExecutionContext {
if (_id == null) {
throw StateError('No context with the running Dart application.');
}
return _id;
return _id!;
}

RemoteDebuggerExecutionContext(this._id, this._remoteDebugger) {
final contextController = StreamController<int>();
_remoteDebugger
.eventStream('Runtime.executionContextsCleared', (e) => e)
.listen((_) => _id = null);
_remoteDebugger
.eventStream('Runtime.executionContextCreated',
(e) => int.parse(e.params['context']['id'].toString()))
.listen(contextController.add);
_remoteDebugger.eventStream('Runtime.executionContextCreated', (e) {
// Parse and add the context ID to the stream.
// If we cannot detect or parse the context ID, add `null` to the stream
// to indicate an error context - those will be skipped when trying to find
// the dart context, with a warning.
final id = e.params?['context']?['id']?.toString();
final parsedId = id == null ? null : int.parse(id);
if (id == null) {
_logger.warning('Cannot find execution context id: $e');
} else if (parsedId == null) {
_logger.warning('Cannot parse execution context id: $id');
}
return parsedId;
}).listen((e) {
if (e != null) contextController.add(e);
});
_contexts = StreamQueue(contextController.stream);
}
}
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/metadata/class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../../debugging/classes.dart';
import '../../debugging/inspector.dart';
import '../../debugging/remote_debugger.dart';
import '../../loaders/strategy.dart';
import '../../services/chrome_proxy_service.dart';
import '../../services/chrome_debug_exception.dart';

/// Meta data for a remote Dart class in Chrome.
class ClassMetaData {
Expand Down
10 changes: 4 additions & 6 deletions dwds/lib/src/debugging/remote_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

class TargetCrashedEvent extends WipEvent {
Expand Down Expand Up @@ -31,7 +29,7 @@ abstract class RemoteDebugger {
Stream<void> get onClose;

Future<WipResponse> sendCommand(String command,
{Map<String, dynamic> params});
{Map<String, dynamic>? params});

Future<void> disable();

Expand All @@ -47,18 +45,18 @@ abstract class RemoteDebugger {

Future<WipResponse> removeBreakpoint(String breakpointId);

Future<WipResponse> stepInto({Map<String, dynamic> params});
Future<WipResponse> stepInto({Map<String, dynamic>? params});

Future<WipResponse> stepOut();

Future<WipResponse> stepOver({Map<String, dynamic> params});
Future<WipResponse> stepOver({Map<String, dynamic>? params});

Future<WipResponse> enablePage();

Future<WipResponse> pageReload();

Future<RemoteObject> evaluate(String expression,
{bool returnByValue, int contextId});
{bool? returnByValue, int? contextId});

Future<RemoteObject> evaluateOnCallFrame(
String callFrameId, String expression);
Expand Down
12 changes: 5 additions & 7 deletions dwds/lib/src/debugging/webkit_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

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

WebkitDebugger(this._wipDebugger);

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

@override
Future<WipResponse> sendCommand(String command,
{Map<String, dynamic> params}) =>
{Map<String, dynamic>? params}) =>
_wipDebugger.sendCommand(command, params: params);

@override
Expand Down Expand Up @@ -60,14 +58,14 @@ class WebkitDebugger implements RemoteDebugger {
_wipDebugger.removeBreakpoint(breakpointId);

@override
Future<WipResponse> stepInto({Map<String, dynamic> params}) =>
Future<WipResponse> stepInto({Map<String, dynamic>? params}) =>
_wipDebugger.stepInto(params: params);

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

@override
Future<WipResponse> stepOver({Map<String, dynamic> params}) =>
Future<WipResponse> stepOver({Map<String, dynamic>? params}) =>
_wipDebugger.stepOver(params: params);

@override
Expand All @@ -78,7 +76,7 @@ class WebkitDebugger implements RemoteDebugger {

@override
Future<RemoteObject> evaluate(String expression,
{bool returnByValue, int contextId}) {
{bool? returnByValue, int? contextId}) {
return _wipDebugger.connection.runtime
.evaluate(expression, returnByValue: returnByValue);
}
Expand Down
19 changes: 9 additions & 10 deletions dwds/lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';

import 'package:vm_service/vm_service.dart';

class DwdsStats {
/// The time when the user starts the debugger.
DateTime _debuggerStart;
late DateTime _debuggerStart;
DateTime get debuggerStart => _debuggerStart;

/// The time when dwds launches DevTools.
DateTime _devToolsStart;
late DateTime _devToolsStart;
DateTime get devToolsStart => _devToolsStart;

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

void updateLoadTime({DateTime debuggerStart, DateTime devToolsStart}) {
void updateLoadTime(
{required DateTime debuggerStart, required DateTime devToolsStart}) {
_debuggerStart = debuggerStart;
_devToolsStart = devToolsStart;
}
Expand Down Expand Up @@ -66,14 +65,14 @@ class DwdsEvent {

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

DwdsEvent.evaluate(String expression, Response result)
DwdsEvent.evaluate(String expression, Response? result)
: this(DwdsEventKind.evaluate, {
'expression': expression,
'success': result != null && result is InstanceRef,
if (result != null && result is ErrorRef) 'error': result,
});

DwdsEvent.evaluateInFrame(String expression, Response result)
DwdsEvent.evaluateInFrame(String expression, Response? result)
: this(DwdsEventKind.evaluateInFrame, {
'expression': expression,
'success': result != null && result is InstanceRef,
Expand Down Expand Up @@ -140,13 +139,13 @@ Stream<DwdsEvent> get eventStream => _eventController.stream;
/// and appends time and exception details to it if
/// available.
Future<T> captureElapsedTime<T>(
Future<T> Function() function, DwdsEvent Function(T result) event) async {
Future<T> Function() function, DwdsEvent Function(T? result) event) async {
final stopwatch = Stopwatch()..start();
T result;
T? result;
try {
return result = await function();
} catch (e) {
emitEvent(event(result)
emitEvent(event(null)
..addException(e)
..addElapsedTime(stopwatch.elapsedMilliseconds));
rethrow;
Expand Down
11 changes: 4 additions & 7 deletions dwds/lib/src/handlers/socket_connections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';

import 'package:async/async.dart';
Expand Down Expand Up @@ -56,7 +54,7 @@ class SseSocketHandler extends SocketHandler {
final SseHandler _sseHandler;
final StreamController<SseSocketConnection> _connectionsStream =
StreamController<SseSocketConnection>();
StreamQueue<SseSocketConnection> _connectionsStreamQueue;
StreamQueue<SseSocketConnection>? _connectionsStreamQueue;

SseSocketHandler(this._sseHandler) {
unawaited(() async {
Expand Down Expand Up @@ -90,8 +88,7 @@ class WebSocketConnection extends SocketConnection {
StreamSink<dynamic> get sink => _channel.sink;

@override
Stream<String> get stream =>
_channel.stream.map((dynamic o) => o?.toString());
Stream<String> get stream => _channel.stream.map((dynamic o) => o.toString());

@override
void shutdown() => _channel.sink.close();
Expand All @@ -100,10 +97,10 @@ class WebSocketConnection extends SocketConnection {
/// An implemenation of [SocketHandler] that accepts WebSocket connections and
/// wraps them in a [WebSocketConnection].
class WebSocketSocketHandler extends SocketHandler {
Handler _handler;
late Handler _handler;
final StreamController<WebSocketConnection> _connectionsStream =
StreamController<WebSocketConnection>();
StreamQueue<WebSocketConnection> _connectionsStreamQueue;
StreamQueue<WebSocketConnection>? _connectionsStreamQueue;

WebSocketSocketHandler() {
_handler = webSocketHandler((WebSocketChannel channel) =>
Expand Down
Loading