OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library service_test_common; | 5 library service_test_common; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:observatory/models.dart' as M; | 8 import 'package:observatory/models.dart' as M; |
9 import 'package:observatory/service_common.dart'; | 9 import 'package:observatory/service_common.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
(...skipping 10 matching lines...) Expand all Loading... |
21 StreamSubscription subscription = stream.listen(onEvent); | 21 StreamSubscription subscription = stream.listen(onEvent); |
22 streamSubscriptions[streamName] = subscription; | 22 streamSubscriptions[streamName] = subscription; |
23 } | 23 } |
24 | 24 |
25 Future cancelStreamSubscription(String streamName) async { | 25 Future cancelStreamSubscription(String streamName) async { |
26 StreamSubscription subscription = streamSubscriptions[streamName]; | 26 StreamSubscription subscription = streamSubscriptions[streamName]; |
27 subscription.cancel(); | 27 subscription.cancel(); |
28 streamSubscriptions.remove(streamName); | 28 streamSubscriptions.remove(streamName); |
29 } | 29 } |
30 | 30 |
| 31 Future smartNext(Isolate isolate) async { |
| 32 print('smartNext'); |
| 33 if (isolate.status == M.IsolateStatus.paused) { |
| 34 var event = isolate.pauseEvent; |
| 35 if (event.atAsyncSuspension) { |
| 36 return asyncNext(isolate); |
| 37 } else { |
| 38 return syncNext(isolate); |
| 39 } |
| 40 } else { |
| 41 throw 'The program is already running'; |
| 42 } |
| 43 } |
| 44 |
| 45 Future asyncNext(Isolate isolate) async { |
| 46 print('asyncNext'); |
| 47 if (isolate.status == M.IsolateStatus.paused) { |
| 48 var event = isolate.pauseEvent; |
| 49 if (!event.atAsyncSuspension) { |
| 50 throw 'No async continuation at this location'; |
| 51 } else { |
| 52 return isolate.stepOverAsyncSuspension(); |
| 53 } |
| 54 } else { |
| 55 throw 'The program is already running'; |
| 56 } |
| 57 } |
| 58 |
| 59 Future syncNext(Isolate isolate) async { |
| 60 print('syncNext'); |
| 61 if (isolate.status == M.IsolateStatus.paused) { |
| 62 return isolate.stepOver(); |
| 63 } else { |
| 64 throw 'The program is already running'; |
| 65 } |
| 66 } |
| 67 |
31 Future asyncStepOver(Isolate isolate) async { | 68 Future asyncStepOver(Isolate isolate) async { |
32 final Completer pausedAtSyntheticBreakpoint = new Completer(); | 69 final Completer pausedAtSyntheticBreakpoint = new Completer(); |
33 StreamSubscription subscription; | 70 StreamSubscription subscription; |
34 | 71 |
35 // Cancel the subscription. | 72 // Cancel the subscription. |
36 cancelSubscription() { | 73 cancelSubscription() { |
37 if (subscription != null) { | 74 if (subscription != null) { |
38 subscription.cancel(); | 75 subscription.cancel(); |
39 subscription = null; | 76 subscription = null; |
40 } | 77 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 Script script = await top.location.script.load(); | 228 Script script = await top.location.script.load(); |
192 int actualLine = script.tokenToLine(top.location.tokenPos); | 229 int actualLine = script.tokenToLine(top.location.tokenPos); |
193 if (actualLine != line) { | 230 if (actualLine != line) { |
194 var sb = new StringBuffer(); | 231 var sb = new StringBuffer(); |
195 sb.write("Expected to be at line $line but actually at line $actualLine"); | 232 sb.write("Expected to be at line $line but actually at line $actualLine"); |
196 sb.write("\nFull stack trace:\n"); | 233 sb.write("\nFull stack trace:\n"); |
197 for (Frame f in stack['frames']) { | 234 for (Frame f in stack['frames']) { |
198 sb.write(" $f [${await f.location.getLine()}]\n"); | 235 sb.write(" $f [${await f.location.getLine()}]\n"); |
199 } | 236 } |
200 throw sb.toString(); | 237 throw sb.toString(); |
| 238 } else { |
| 239 print('Program is stopped at line: $line'); |
201 } | 240 } |
202 }; | 241 }; |
203 } | 242 } |
204 | 243 |
205 | 244 |
206 Future<Isolate> resumeIsolate(Isolate isolate) { | 245 Future<Isolate> resumeIsolate(Isolate isolate) { |
207 Completer completer = new Completer(); | 246 Completer completer = new Completer(); |
208 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { | 247 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { |
209 var subscription; | 248 var subscription; |
210 subscription = stream.listen((ServiceEvent event) { | 249 subscription = stream.listen((ServiceEvent event) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 306 |
268 Future<Instance> rootLibraryFieldValue(Isolate isolate, | 307 Future<Instance> rootLibraryFieldValue(Isolate isolate, |
269 String fieldName) async { | 308 String fieldName) async { |
270 Library rootLib = await isolate.rootLibrary.load(); | 309 Library rootLib = await isolate.rootLibrary.load(); |
271 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); | 310 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); |
272 await field.load(); | 311 await field.load(); |
273 Instance value = field.staticValue; | 312 Instance value = field.staticValue; |
274 await value.load(); | 313 await value.load(); |
275 return value; | 314 return value; |
276 } | 315 } |
OLD | NEW |