OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'script.dart'; |
| 6 import 'scope.dart'; |
| 7 import 'source_location.dart'; |
| 8 |
| 9 VMSourceReport newSourceReport(Scope scope, Map json) { |
| 10 if (json == null) return null; |
| 11 assert(json["type"] == "SourceReport"); |
| 12 |
| 13 var scripts = (json['scripts'] as List) |
| 14 .map((script) => newVMScriptRef(scope, script)) |
| 15 .toList(); |
| 16 |
| 17 var ranges = new List<VMSourceReportRange>.unmodifiable( |
| 18 (json['ranges'] as List).map((rangeItem) => |
| 19 new VMSourceReportRange._fromJson(rangeItem, scripts))); |
| 20 |
| 21 return new VMSourceReport._(ranges); |
| 22 } |
| 23 |
| 24 /// A report about ranges of source code. |
| 25 /// |
| 26 /// [ranges] exposes code coverage and information on possible breakpoints. |
| 27 class VMSourceReport { |
| 28 /// Ranges in the program source corresponding to ranges of executable code in |
| 29 /// the user's program. |
| 30 /// |
| 31 /// Ranges can include members such as functions, methods, and |
| 32 /// constructors. |
| 33 /// |
| 34 /// Note: ranges may nest in other ranges, in the case of nested functions. |
| 35 /// Ranges may be duplicated, in the case of mixins. |
| 36 final List<VMSourceReportRange> ranges; |
| 37 |
| 38 VMSourceReport._(this.ranges); |
| 39 } |
| 40 |
| 41 /// A range of executable code (function, method, constructor, etc) |
| 42 /// in the running program. |
| 43 /// |
| 44 /// This is part of a [VMSourceReport]. |
| 45 class VMSourceReportRange { |
| 46 VMScriptRef get script => location.script; |
| 47 |
| 48 /// The location of the range in the target script. |
| 49 final VMSourceLocation location; |
| 50 |
| 51 /// `true` if this range been compiled by the Dart VM. |
| 52 /// |
| 53 /// If `false`, `possibleBreakpoints`, `hits`, and `misses` will be `null`. |
| 54 /// |
| 55 /// Use `forceCompile` in `getSourceReport` to ensure the target scripts are |
| 56 /// compiled. |
| 57 final bool compiled; |
| 58 |
| 59 /// Token positions at which breakpoints can be set. |
| 60 /// |
| 61 /// Provided only when `includePossibleBreakpoints` in `getSourceReport` |
| 62 /// is `true` and the range has been compiled. |
| 63 final List<VMScriptToken> possibleBreakpoints; |
| 64 |
| 65 /// Token positions in this range which have been executed. |
| 66 /// |
| 67 /// Provided only when `includeCoverageReport` in `getSourceReport` is `true` |
| 68 /// and the range has been compiled. |
| 69 /// |
| 70 /// Sorted by the position in the source file, starting with the first hit. |
| 71 final List<VMScriptToken> hits; |
| 72 |
| 73 /// Token positions in this range which have not yet been executed. |
| 74 /// |
| 75 /// Provided only when `includeCoverageReport` in `getSourceReport` is `true` |
| 76 /// and the range has been compiled. |
| 77 /// |
| 78 /// Sorted by the location in the source file, starting with the first miss. |
| 79 final List<VMScriptToken> misses; |
| 80 |
| 81 /// Creates a new [VMSourceReportRange]. |
| 82 /// |
| 83 /// [json] corresponds to data returned by the `getSourceReport` RPC. |
| 84 /// |
| 85 /// [scripts] is used to find the [VMScriptRef] referenced by index in [json]. |
| 86 factory VMSourceReportRange._fromJson(Map json, List<VMScriptRef> scripts) { |
| 87 var script = scripts[json['scriptIndex']]; |
| 88 |
| 89 var location = newVMSourceLocationFromPosition( |
| 90 script, json['startPos'], json['endPos']); |
| 91 |
| 92 var compiled = json['compiled']; |
| 93 |
| 94 var hits = json['coverage'] == null |
| 95 ? null |
| 96 : _getTokens(script, json['coverage']['hits']); |
| 97 |
| 98 var misses = json['coverage'] == null |
| 99 ? null |
| 100 : _getTokens(script, json['coverage']['misses']); |
| 101 |
| 102 var possibleBreakpoints = json['possibleBreakpoints'] == null |
| 103 ? null |
| 104 : _getTokens(script, json['possibleBreakpoints']); |
| 105 |
| 106 return new VMSourceReportRange._( |
| 107 compiled, hits, misses, possibleBreakpoints, location); |
| 108 } |
| 109 |
| 110 VMSourceReportRange._(this.compiled, this.hits, this.misses, |
| 111 this.possibleBreakpoints, this.location); |
| 112 |
| 113 /// Returns an unmodifiable [List<VMScriptToken>] corresponding to the |
| 114 /// provided token [locations]. |
| 115 static List<VMScriptToken> _getTokens( |
| 116 VMScriptRef script, Iterable<int> locations) { |
| 117 return new List<VMScriptToken>.unmodifiable(locations |
| 118 .map((position) => newVMScriptTokenFromPosition(script, position))); |
| 119 } |
| 120 } |
OLD | NEW |