Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: lib/src/script.dart

Issue 1929063002: pkg/vm_service_client: add getSourceReport to VMServiceReference (Closed) Base URL: https://github.com/dart-lang/vm_service_client.git@master
Patch Set: nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/pause_event.dart ('k') | lib/src/source_location.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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. An [ArgumentError] is thrown if `location.end` is `null`.
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 if (location.end == null) {
112 throw new ArgumentError.value(
113 location, 'location', 'location.end cannot be null.');
114 }
115 params['tokenPos'] = location.token._position;
116 params['endTokenPos'] = location.end._position;
117 }
118
119 var json = await _scope.sendRequest('getSourceReport', params);
120 return newSourceReport(_scope, json);
121 }
122
73 bool operator ==(other) => other is VMScriptRef && 123 bool operator ==(other) => other is VMScriptRef &&
74 (_fixedId ? _id == other._id : super == other); 124 (_fixedId ? _id == other._id : super == other);
75 125
76 int get hashCode => _fixedId ? _id.hashCode : super.hashCode; 126 int get hashCode => _fixedId ? _id.hashCode : super.hashCode;
77 127
78 String toString() => uri.toString(); 128 String toString() => uri.toString();
79 } 129 }
80 130
81 /// A script in the Dart VM. 131 /// A script in the Dart VM.
82 class VMScript extends VMScriptRef implements VMObject { 132 class VMScript extends VMScriptRef implements VMObject {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 return new _ScriptSpan(_script, startPosition, endPosition, 410 return new _ScriptSpan(_script, startPosition, endPosition,
361 startPosition == this._startPosition ? this._start : other._start, 411 startPosition == this._startPosition ? this._start : other._start,
362 endPosition == this._endPosition ? this._end : other._end); 412 endPosition == this._endPosition ? this._end : other._end);
363 } else { 413 } else {
364 var start = math.min(this.start.offset, other.start.offset); 414 var start = math.min(this.start.offset, other.start.offset);
365 var end = math.max(this.end.offset, other.end.offset); 415 var end = math.max(this.end.offset, other.end.offset);
366 return file.span(start, end); 416 return file.span(start, end);
367 } 417 }
368 } 418 }
369 } 419 }
OLDNEW
« no previous file with comments | « lib/src/pause_event.dart ('k') | lib/src/source_location.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698