2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.9
6
-
7
5
import 'dart:async' ;
8
6
import 'dart:convert' ;
9
7
@@ -32,7 +30,7 @@ class DwdsVmClient {
32
30
/// Null until [close] is called.
33
31
///
34
32
/// All subsequent calls to [close] will return this future.
35
- Future <void > _closed;
33
+ Future <void >? _closed;
36
34
37
35
DwdsVmClient (this .client, this ._requestController, this ._responseController);
38
36
@@ -57,7 +55,7 @@ class DwdsVmClient {
57
55
'$request ' );
58
56
return ;
59
57
}
60
- requestController.sink.add (jsonDecode (request) as Map <String , dynamic >);
58
+ requestController.sink.add (jsonDecode (request) as Map <String , Object >);
61
59
});
62
60
final chromeProxyService =
63
61
debugService.chromeProxyService as ChromeProxyService ;
@@ -73,7 +71,7 @@ class DwdsVmClient {
73
71
return < String , dynamic > {
74
72
'result' : < String , Object > {
75
73
'views' : < Object > [
76
- for (var isolate in isolates)
74
+ for (var isolate in isolates ?? [] )
77
75
< String , Object > {
78
76
'id' : isolate.id,
79
77
'isolate' : isolate.toJson (),
@@ -119,7 +117,7 @@ class DwdsVmClient {
119
117
await client.registerService ('ext.dwds.emitEvent' , 'DWDS' );
120
118
121
119
client.registerServiceCallback ('_yieldControlToDDS' , (request) async {
122
- final ddsUri = request['uri' ] as String ;
120
+ final ddsUri = request['uri' ] as String ? ;
123
121
if (ddsUri == null ) {
124
122
return RPCError (
125
123
request['method' ] as String ,
@@ -146,30 +144,26 @@ class DwdsVmClient {
146
144
147
145
void _processSendEvent (Map <String , dynamic > event,
148
146
ChromeProxyService chromeProxyService, DwdsStats dwdsStats) {
149
- final type = event['type' ] as String ;
150
- final payload = event['payload' ] as Map <String , dynamic >;
147
+ final type = event['type' ] as String ? ;
148
+ final payload = event['payload' ] as Map <String , dynamic >? ;
151
149
switch (type) {
152
150
case 'DevtoolsEvent' :
153
151
{
154
152
_logger.finest ('Received DevTools event: $event ' );
155
- final action = payload == null ? null : payload ['action' ] as String ;
156
- final screen = payload == null ? null : payload ['screen' ] as String ;
157
- if (action == 'pageReady' ) {
153
+ final action = payload? ['action' ] as String ? ;
154
+ final screen = payload? ['screen' ] as String ? ;
155
+ if (screen != null && action == 'pageReady' ) {
158
156
if (dwdsStats.isFirstDebuggerReady) {
159
- if (dwdsStats.devToolsStart != null ) {
160
- final time = DateTime .now ()
161
- .difference (dwdsStats.devToolsStart)
162
- .inMilliseconds;
163
- emitEvent (DwdsEvent .devToolsLoad (time, screen));
164
- _logger.fine ('DevTools load time: $time ms' );
165
- }
166
- if (dwdsStats.debuggerStart != null ) {
167
- final time = DateTime .now ()
168
- .difference (dwdsStats.debuggerStart)
169
- .inMilliseconds;
170
- emitEvent (DwdsEvent .debuggerReady (time, screen));
171
- _logger.fine ('Debugger ready time: $time ms' );
172
- }
157
+ final debuggerReadyTime = DateTime .now ()
158
+ .difference (dwdsStats.devToolsStart)
159
+ .inMilliseconds;
160
+ emitEvent (DwdsEvent .devToolsLoad (debuggerReadyTime, screen));
161
+ _logger.fine ('DevTools load time: $debuggerReadyTime ms' );
162
+ final debuggerStartTime = DateTime .now ()
163
+ .difference (dwdsStats.debuggerStart)
164
+ .inMilliseconds;
165
+ emitEvent (DwdsEvent .debuggerReady (debuggerStartTime, screen));
166
+ _logger.fine ('Debugger ready time: $debuggerStartTime ms' );
173
167
} else {
174
168
_logger
175
169
.finest ('Debugger and DevTools startup times alredy recorded.'
@@ -213,14 +207,15 @@ Future<Map<String, dynamic>> _hotRestart(
213
207
.jsEvaluate ('\$ dartHotRestartDwds(\' $runId \' );' , awaitPromise: true );
214
208
_logger.info ('\$ dartHotRestartDwds request complete.' );
215
209
} on WipError catch (exception) {
216
- final code = exception.error['code' ];
210
+ final code = exception.error? ['code' ];
211
+ final message = exception.error? ['message' ];
217
212
// This corresponds to `Execution context was destroyed` which can
218
213
// occur during a hot restart that must fall back to a full reload.
219
214
if (code != RPCError .kServerError) {
220
215
return {
221
216
'error' : {
222
- 'code' : exception.error[ ' code' ] ,
223
- 'message' : exception.error[ ' message' ] ,
217
+ 'code' : code,
218
+ 'message' : message,
224
219
'data' : exception,
225
220
}
226
221
};
@@ -255,9 +250,14 @@ Future<void> _disableBreakpointsAndResume(
255
250
VmService client, ChromeProxyService chromeProxyService) async {
256
251
_logger.info ('Attempting to disable breakpoints and resume the isolate' );
257
252
final vm = await client.getVM ();
258
- if (vm.isolates.isEmpty) throw StateError ('No active isolate to resume.' );
259
- final isolateRef = vm.isolates.first;
260
-
253
+ final isolates = vm.isolates;
254
+ if (isolates == null || isolates.isEmpty) {
255
+ throw StateError ('No active isolate to resume.' );
256
+ }
257
+ final isolateId = isolates.first.id;
258
+ if (isolateId == null ) {
259
+ throw StateError ('No active isolate to resume.' );
260
+ }
261
261
await chromeProxyService.disableBreakpoints ();
262
262
try {
263
263
// Any checks for paused status result in race conditions or hangs
@@ -274,7 +274,7 @@ Future<void> _disableBreakpointsAndResume(
274
274
// ignore failures indicating that the app is already running:
275
275
//
276
276
// WipError -32000 Can only perform operation while paused.
277
- await client.resume (isolateRef.id );
277
+ await client.resume (isolateId );
278
278
} on RPCError catch (e, s) {
279
279
if (! e.message.contains ('Can only perform operation while paused' )) {
280
280
_logger.severe ('Hot restart failed to resume exiting isolate' , e, s);
0 commit comments