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

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 String styleForHits(int hits) {
42 if ((script == null) || !coverage) { 44 if (hits == null) {
43 return hitStyleNone; 45 return hitStyleNone;
44 } 46 } 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; 47 return hitStyleNotExecuted;
51 } 48 }
52 assert(hit > 0); 49 assert(hits > 0);
53 return hitStyleExecuted; 50 return hitStyleExecuted;
54 } 51 }
55 52
53 var _updateFuture;
56 54
57 void _updateProperties() { 55 void _updateLines() {
58 if (!script.loaded) { 56 if (_updateFuture != null) {
59 script.load().then((_) { 57 // Already scheduled.
60 if (script.loaded) {
61 _updateProperties();
62 }
63 });
64 return; 58 return;
65 } 59 }
66 notifyPropertyChange(#lines, 0, 1); 60 if (!script.loaded) {
67 lines.clear(); 61 _updateFuture = script.load().then((_) {
68 var startLineNumber = script.tokenToLine(pos); 62 if (script.loaded) {
69 if (startLineNumber != null) { 63 _updateFuture = null;
70 if (endPos == null) { 64 _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 } 65 }
78 } 66 });
67 return;
68 }
69 startLine =
70 (pos != null) ? script.tokenToLine(pos) - 1 : 0;
71 endLine =
72 (endPos != null) ? script.tokenToLine(endPos) : script.lines.length;
73 // Add line numbers.
74 lineNumbers.clear();
75 for (var i = startLine; i < endLine; i++) {
76 lineNumbers.add(i);
79 } 77 }
80 } 78 }
81 79
82 ScriptInsetElement.created() : super.created(); 80 ScriptInsetElement.created() : super.created();
83 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698