OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:math' as math; | 6 import 'dart:math' as math; |
7 | 7 |
8 import 'package:json_rpc_2/json_rpc_2.dart' as rpc; | 8 import 'package:json_rpc_2/json_rpc_2.dart' as rpc; |
9 import 'package:source_span/source_span.dart'; | 9 import 'package:source_span/source_span.dart'; |
10 | 10 |
11 import 'breakpoint.dart'; | 11 import 'breakpoint.dart'; |
12 import 'class.dart'; | 12 import 'class.dart'; |
13 import 'library.dart'; | 13 import 'library.dart'; |
14 import 'object.dart'; | 14 import 'object.dart'; |
15 import 'scope.dart'; | 15 import 'scope.dart'; |
16 import 'source_location.dart'; | 16 import 'source_location.dart'; |
17 import 'source_report.dart'; | |
17 | 18 |
18 VMScriptRef newVMScriptRef(Scope scope, Map json) { | 19 VMScriptRef newVMScriptRef(Scope scope, Map json) { |
19 if (json == null) return null; | 20 if (json == null) return null; |
20 assert(json["type"] == "@Script" || json["type"] == "Script"); | 21 assert(json["type"] == "@Script" || json["type"] == "Script"); |
21 return new VMScriptRef._(scope, json); | 22 return new VMScriptRef._(scope, json); |
22 } | 23 } |
23 | 24 |
24 VMScriptToken newVMScriptToken(String isolateId, String scriptId, | 25 VMScriptToken newVMScriptToken(String isolateId, String scriptId, |
25 int position) { | 26 int position) { |
26 if (position == null) return null; | 27 if (position == null) return null; |
27 return new VMScriptToken._(isolateId, scriptId, position); | 28 return new VMScriptToken._(isolateId, scriptId, position); |
28 } | 29 } |
29 | 30 |
31 VMScriptToken newVMScriptTokenFromPosition(VMScriptRef script, int position) { | |
32 if (position == null) return null; | |
33 return new VMScriptToken._(script._scope.isolateId, script._id, position); | |
34 } | |
35 | |
30 /// A reference to a script in the Dart VM. | 36 /// A reference to a script in the Dart VM. |
31 /// | 37 /// |
32 /// A script contains information about the actual text of a library. Usually | 38 /// A script contains information about the actual text of a library. Usually |
33 /// there's only one script per library, but the `part` directive can produce | 39 /// there's only one script per library, but the `part` directive can produce |
34 /// libraries made up of multiple scripts. | 40 /// libraries made up of multiple scripts. |
35 class VMScriptRef implements VMObjectRef { | 41 class VMScriptRef implements VMObjectRef { |
36 final Scope _scope; | 42 final Scope _scope; |
37 | 43 |
38 /// The ID for script library, which is unique relative to its isolate. | 44 /// The ID for script library, which is unique relative to its isolate. |
39 final String _id; | 45 final String _id; |
(...skipping 23 matching lines...) Expand all Loading... | |
63 try { | 69 try { |
64 var response = await _scope.sendRequest("addBreakpoint", params); | 70 var response = await _scope.sendRequest("addBreakpoint", params); |
65 return newVMBreakpoint(_scope, response); | 71 return newVMBreakpoint(_scope, response); |
66 } on rpc.RpcException catch (error) { | 72 } on rpc.RpcException catch (error) { |
67 // Error 102 indicates that the breakpoint couldn't be created. | 73 // Error 102 indicates that the breakpoint couldn't be created. |
68 if (error.code == 102) return null; | 74 if (error.code == 102) return null; |
69 rethrow; | 75 rethrow; |
70 } | 76 } |
71 } | 77 } |
72 | 78 |
79 /// Generates a set of reports tied to this script. | |
80 /// | |
81 /// If [includeCoverageReport] is `true`, the report includes code coverage | |
82 /// information via [VMSourceReportRange.coverage] in | |
83 /// [VMSourceReport.ranges]. | |
84 /// Otherwise, [VMSourceReportRange.coverage] is `null`. | |
85 /// | |
86 /// If [includePossibleBreakpoints] is `true`, the report includes a list of | |
87 /// token positions which correspond to possible breakpoints via | |
88 /// [VMSourceReportRange.possibleBreakpoints] in [VMSourceReport.ranges]. | |
89 /// Otherwise, [VMSourceReportRange.possibleBreakpoints] is `null`. | |
90 /// | |
91 /// If [forceCompile] is `true`, all functions in the range of the report | |
92 /// will be compiled. If `false`, functions that are never used may not appear | |
93 /// in [VMSourceReportRange.misses]. | |
94 /// Forcing compilation can cause a compilation error, which could terminate | |
95 /// the running Dart program. | |
96 /// | |
97 /// [location] can be provided to restrict analysis to a subrange of the | |
98 /// script. | |
99 Future<VMSourceReport> getSourceReport( | |
100 {bool includeCoverageReport: true, | |
101 bool includePossibleBreakpoints: true, | |
102 bool forceCompile: false, | |
103 VMSourceLocation location}) async { | |
104 var reports = <String>[]; | |
105 if (includeCoverageReport) reports.add('Coverage'); | |
106 if (includePossibleBreakpoints) reports.add('PossibleBreakpoints'); | |
107 | |
108 var params = <String, dynamic>{'scriptId': _id, 'reports': reports}; | |
109 if (forceCompile) params['forceCompile'] = true; | |
110 if (location != null) { | |
111 params['tokenPos'] = location.token._position; | |
112 if (location.end != null) { | |
113 params['endTokenPos'] = location.end._position; | |
nweiz
2016/05/19 21:11:13
A location without an end represents a single poin
kevmoo
2016/05/19 21:59:46
Acknowledged.
| |
114 } | |
115 } | |
116 | |
117 var json = await _scope.sendRequest('getSourceReport', params); | |
118 return newSourceReport(_scope, json); | |
119 } | |
120 | |
73 bool operator ==(other) => other is VMScriptRef && | 121 bool operator ==(other) => other is VMScriptRef && |
74 (_fixedId ? _id == other._id : super == other); | 122 (_fixedId ? _id == other._id : super == other); |
75 | 123 |
76 int get hashCode => _fixedId ? _id.hashCode : super.hashCode; | 124 int get hashCode => _fixedId ? _id.hashCode : super.hashCode; |
77 | 125 |
78 String toString() => uri.toString(); | 126 String toString() => uri.toString(); |
79 } | 127 } |
80 | 128 |
81 /// A script in the Dart VM. | 129 /// A script in the Dart VM. |
82 class VMScript extends VMScriptRef implements VMObject { | 130 class VMScript extends VMScriptRef implements VMObject { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 return new _ScriptSpan(_script, startPosition, endPosition, | 408 return new _ScriptSpan(_script, startPosition, endPosition, |
361 startPosition == this._startPosition ? this._start : other._start, | 409 startPosition == this._startPosition ? this._start : other._start, |
362 endPosition == this._endPosition ? this._end : other._end); | 410 endPosition == this._endPosition ? this._end : other._end); |
363 } else { | 411 } else { |
364 var start = math.min(this.start.offset, other.start.offset); | 412 var start = math.min(this.start.offset, other.start.offset); |
365 var end = math.max(this.end.offset, other.end.offset); | 413 var end = math.max(this.end.offset, other.end.offset); |
366 return file.span(start, end); | 414 return file.span(start, end); |
367 } | 415 } |
368 } | 416 } |
369 } | 417 } |
OLD | NEW |