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

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

Issue 381383010: Add breakpoints and single-stepping to Observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix bugs, gen js Created 6 years, 4 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 'dart:html'; 7 import 'dart:html';
8 import 'observatory_element.dart'; 8 import 'observatory_element.dart';
9 import 'package:observatory/service.dart'; 9 import 'package:observatory/service.dart';
10 import 'package:polymer/polymer.dart'; 10 import 'package:polymer/polymer.dart';
11 11
12 /// Box with script source code in it. 12 /// Box with script source code in it.
13 @CustomTag('script-inset') 13 @CustomTag('script-inset')
14 class ScriptInsetElement extends ObservatoryElement { 14 class ScriptInsetElement extends ObservatoryElement {
15 @published Script script; 15 @published Script script;
16 16
17 /// Set the height to make the script inset scroll. Otherwise it 17 /// Set the height to make the script inset scroll. Otherwise it
18 /// will show from startPos to endPos. 18 /// will show from startPos to endPos.
19 @published String height = null; 19 @published String height = null;
20 20
21 @published int currentPos; 21 @published int currentPos;
22 @published int startPos; 22 @published int startPos;
23 @published int endPos; 23 @published int endPos;
24 24
25 @observable int currentLine; 25 @observable int currentLine;
26 @observable int startLine; 26 @observable int startLine;
27 @observable int endLine; 27 @observable int endLine;
28 @observable bool linesReady = false;
28 29
29 @observable List<ScriptLine> lines = toObservable([]); 30 @observable List<ScriptLine> lines = toObservable([]);
30 31
31 String makeLineId(int line) { 32 String makeLineId(int line) {
32 return 'line-$line'; 33 return 'line-$line';
33 } 34 }
34 35
35 MutationObserver _observer; 36 MutationObserver _observer;
36 37
37 void _onMutation(mutations, observer) { 38 void _scrollToCurrentPos() {
38 var line = shadowRoot.querySelector('#line-$currentLine'); 39 var line = shadowRoot.querySelector('#line-$currentLine');
39 if (line != null) { 40 if (line != null) {
40 line.scrollIntoView(); 41 line.scrollIntoView();
41 } 42 }
43 }
44
45 void _onMutation(mutations, observer) {
46 _scrollToCurrentPos();
42 } 47 }
43 48
44 void attached() { 49 void attached() {
45 super.attached(); 50 super.attached();
46 var table = shadowRoot.querySelector('.sourceTable'); 51 var table = shadowRoot.querySelector('.sourceTable');
47 if (table != null) { 52 if (table != null) {
48 _observer = new MutationObserver(_onMutation); 53 _observer = new MutationObserver(_onMutation);
49 _observer.observe(table, childList:true); 54 _observer.observe(table, childList:true);
50 } 55 }
51 } 56 }
52 57
53 void detached() { 58 void detached() {
54 if (_observer != null) { 59 if (_observer != null) {
55 _observer.disconnect(); 60 _observer.disconnect();
56 _observer = null; 61 _observer = null;
57 } 62 }
58 super.detached(); 63 super.detached();
59 } 64 }
60 65
61 void currentPosChanged(oldValue) { 66 void currentPosChanged(oldValue) {
62 _updateLines(); 67 _updateLines();
68 _scrollToCurrentPos();
63 } 69 }
64 70
65 void startPosChanged(oldValue) { 71 void startPosChanged(oldValue) {
66 _updateLines(); 72 _updateLines();
67 } 73 }
68 74
69 void endPosChanged(oldValue) { 75 void endPosChanged(oldValue) {
70 _updateLines(); 76 _updateLines();
71 } 77 }
72 78
73 void scriptChanged(oldValue) { 79 void scriptChanged(oldValue) {
74 _updateLines(); 80 _updateLines();
75 } 81 }
76 82
77 var _updateFuture; 83 var _updateFuture;
78 84
79 void _updateLines() { 85 void _updateLines() {
86 linesReady = false;
80 if (_updateFuture != null) { 87 if (_updateFuture != null) {
81 // Already scheduled. 88 // Already scheduled.
82 return; 89 return;
83 } 90 }
84 if (script == null) { 91 if (script == null) {
85 // Wait for script to be assigned. 92 // Wait for script to be assigned.
86 return; 93 return;
87 } 94 }
88 if (!script.loaded) { 95 if (!script.loaded) {
89 _updateFuture = script.load().then((_) { 96 _updateFuture = script.load().then((_) {
90 if (script.loaded) { 97 if (script.loaded) {
91 _updateFuture = null; 98 _updateFuture = null;
92 _updateLines(); 99 _updateLines();
93 } 100 }
94 }); 101 });
95 return; 102 return;
96 } 103 }
97 startLine = (startPos != null 104 startLine = (startPos != null
98 ? script.tokenToLine(startPos) 105 ? script.tokenToLine(startPos)
99 : 1); 106 : 1);
100 currentLine = (currentPos != null 107 currentLine = (currentPos != null
101 ? script.tokenToLine(currentPos) 108 ? script.tokenToLine(currentPos)
102 : null); 109 : null);
103 endLine = (endPos != null 110 endLine = (endPos != null
104 ? script.tokenToLine(endPos) 111 ? script.tokenToLine(endPos)
105 : script.lines.length); 112 : script.lines.length);
113
106 lines.clear(); 114 lines.clear();
107 for (int i = (startLine - 1); i <= (endLine - 1); i++) { 115 for (int i = (startLine - 1); i <= (endLine - 1); i++) {
108 lines.add(script.lines[i]); 116 lines.add(script.lines[i]);
109 } 117 }
118 linesReady = true;
110 } 119 }
111 120
112 ScriptInsetElement.created() : super.created(); 121 ScriptInsetElement.created() : super.created();
113 } 122 }
123
124 @CustomTag('breakpoint-toggle')
125 class BreakpointToggleElement extends ObservatoryElement {
126 @published ScriptLine line;
127 @observable bool busy = false;
128
129 void toggleBreakpoint(var a, var b, var c) {
130 if (busy) {
131 return;
132 }
133 busy = true;
134 if (line.bpt == null) {
135 // No breakpoint. Set it.
136 line.script.isolate.setBreakpoint(line.script, line.line).then((_) {
137 busy = false;
138 });
139 } else {
140 // Existing breakpoint. Remove it.
141 line.script.isolate.clearBreakpoint(line.bpt).then((_) {
142 busy = false;
143 });
144 }
145 }
146
147 BreakpointToggleElement.created() : super.created();
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698