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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/elements/script_inset.dart

Issue 345113002: Fix Observatory code coverage (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 script_inset_element; 5 library script_inset_element;
6 6
7 import 'observatory_element.dart'; 7 import 'observatory_element.dart';
8 import 'package:observatory/service.dart'; 8 import 'package:observatory/service.dart';
9 import 'package:polymer/polymer.dart'; 9 import 'package:polymer/polymer.dart';
10 10
11 /// Box with script source code in it. 11 /// Box with script source code in it.
12 @CustomTag('script-inset') 12 @CustomTag('script-inset')
13 class ScriptInsetElement extends ObservatoryElement { 13 class ScriptInsetElement extends ObservatoryElement {
14 @published Script script; 14 @published Script script;
15 @published int pos; 15 @published int pos;
16 @published int endPos; 16 @published int endPos;
17 @published bool coverage = false; 17 final List<int> lineNumbers = new ObservableList<int>();
18 @observable int startLine;
19 @observable int endLine;
18 20
19 @observable List<ScriptLine> lines = toObservable([]); 21 @observable List<ScriptLine> lines = toObservable([]);
20 22
23 void attached() {
24 super.attached();
25 }
26
21 void scriptChanged(oldValue) { 27 void scriptChanged(oldValue) {
22 _updateProperties(); 28 _updateLines();
23 notifyPropertyChange(#hitStyle, 0, 1);
24 notifyPropertyChange(#lines, 0, 1);
25 } 29 }
26 30
27 void posChanged(oldValue) { 31 void posChanged(oldValue) {
28 _updateProperties(); 32 _updateLines();
29 } 33 }
30 34
31 coverageChanged(oldValue) { 35 void endPosChanged(oldValue) {
32 _updateProperties(); 36 _updateLines();
33 notifyPropertyChange(#lines, 0, 1);
34 notifyPropertyChange(#hitStyle, 0, 1);
35 } 37 }
36 38
37 static const hitStyleNone = 'min-width:32px;'; 39 static const hitStyleNone = 'min-width:32px;';
38 static const hitStyleExecuted = 'min-width:32px;background-color:green'; 40 static const hitStyleExecuted = 'min-width:32px; background-color:green';
39 static const hitStyleNotExecuted = 'min-width:32px;background-color:red'; 41 static const hitStyleNotExecuted = 'min-width:32px; background-color:red';
40 42
41 @observable String hitStyle(ScriptLine line) { 43 /// [hits] can be null which indicates that the line is not executable.
42 if ((script == null) || !coverage) { 44 /// When [hits] is 0, the line is executable but hasn't been executed and
45 /// when [hits] is positive, the line is executable and has been executed.
46 String styleForHits(int hits) {
47 if (hits == null) {
43 return hitStyleNone; 48 return hitStyleNone;
44 } 49 } else if (hits == 0) {
45 var hit = script.hits[line.line];
46 if (hit == null) {
47 return hitStyleNone;
48 }
49 if (hit == 0) {
50 return hitStyleNotExecuted; 50 return hitStyleNotExecuted;
51 } 51 }
52 assert(hit > 0); 52 assert(hits > 0);
53 return hitStyleExecuted; 53 return hitStyleExecuted;
54 } 54 }
55 55
56 var _updateFuture;
56 57
57 void _updateProperties() { 58 void _updateLines() {
58 if (!script.loaded) { 59 if (_updateFuture != null) {
59 script.load().then((_) { 60 // Already scheduled.
60 if (script.loaded) {
61 _updateProperties();
62 }
63 });
64 return; 61 return;
65 } 62 }
66 notifyPropertyChange(#lines, 0, 1); 63 if (!script.loaded) {
67 lines.clear(); 64 _updateFuture = script.load().then((_) {
68 var startLineNumber = script.tokenToLine(pos); 65 if (script.loaded) {
69 if (startLineNumber != null) { 66 _updateFuture = null;
70 if (endPos == null) { 67 _updateLines();
71 lines.add(script.lines[startLineNumber - 1]);
72 } else {
73 var endLineNumber = script.tokenToLine(endPos);
74 assert(endLineNumber != null);
75 for (var i = startLineNumber; i <= endLineNumber; i++) {
76 lines.add(script.lines[i - 1]);
77 } 68 }
78 } 69 });
70 return;
71 }
72 startLine =
73 (pos != null) ? script.tokenToLine(pos) - 1 : 0;
74 endLine =
75 (endPos != null) ? script.tokenToLine(endPos) : script.lines.length;
76 // Add line numbers.
77 lineNumbers.clear();
78 for (var i = startLine; i < endLine; i++) {
79 lineNumbers.add(i);
79 } 80 }
80 } 81 }
81 82
82 ScriptInsetElement.created() : super.created(); 83 ScriptInsetElement.created() : super.created();
83 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698