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

Side by Side Diff: src/d8.js

Issue 27330: Unify the handling of the event and response JSON in developer shell debugger... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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
« no previous file with comments | « src/d8.cc ('k') | src/d8-debug.cc » ('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 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 // Current debug state. 96 // Current debug state.
97 const kNoFrame = -1; 97 const kNoFrame = -1;
98 Debug.State = { 98 Debug.State = {
99 currentFrame: kNoFrame, 99 currentFrame: kNoFrame,
100 currentSourceLine: -1 100 currentSourceLine: -1
101 } 101 }
102 var trace_compile = false; // Tracing all compile events? 102 var trace_compile = false; // Tracing all compile events?
103 103
104 104
105 function DebugEventToText(event) { 105 // Process a debugger JSON message into a display text and a running status.
106 // This function returns an object with properties "text" and "running" holding
107 // this information.
108 function DebugMessageDetails(message) {
106 // Convert the JSON string to an object. 109 // Convert the JSON string to an object.
107 var response = new ProtocolPackage(event); 110 var response = new ProtocolPackage(message);
108 111
109 // Build the text. 112 if (response.type() == 'event') {
113 return DebugEventDetails(response);
114 } else {
115 return DebugResponseDetails(response);
116 }
117 }
118
119 function DebugEventDetails(response) {
120 details = {text:'', running:false}
121
122 // Get the running state.
123 details.running = response.running();
124
110 var body = response.body(); 125 var body = response.body();
111 var details = ''; 126 var result = '';
112 switch (response.event()) { 127 switch (response.event()) {
113 case 'break': 128 case 'break':
114 if (body.breakpoints) { 129 if (body.breakpoints) {
115 details += 'breakpoint'; 130 result += 'breakpoint';
116 if (body.breakpoints.length > 1) { 131 if (body.breakpoints.length > 1) {
117 details += 's'; 132 result += 's';
118 } 133 }
119 details += ' #'; 134 result += ' #';
120 for (var i = 0; i < body.breakpoints.length; i++) { 135 for (var i = 0; i < body.breakpoints.length; i++) {
121 if (i > 0) { 136 if (i > 0) {
122 details += ', #'; 137 result += ', #';
123 } 138 }
124 details += body.breakpoints[i]; 139 result += body.breakpoints[i];
125 } 140 }
126 } else { 141 } else {
127 details += 'break'; 142 result += 'break';
128 } 143 }
129 details += ' in '; 144 result += ' in ';
130 details += body.invocationText; 145 result += body.invocationText;
131 details += ', '; 146 result += ', ';
132 details += SourceInfo(body); 147 result += SourceInfo(body);
133 details += '\n'; 148 result += '\n';
134 details += SourceUnderline(body.sourceLineText, body.sourceColumn); 149 result += SourceUnderline(body.sourceLineText, body.sourceColumn);
135 Debug.State.currentSourceLine = body.sourceLine; 150 Debug.State.currentSourceLine = body.sourceLine;
136 Debug.State.currentFrame = 0; 151 Debug.State.currentFrame = 0;
137 return details; 152 details.text = result;
153 break;
138 154
139 case 'exception': 155 case 'exception':
140 if (body.uncaught) { 156 if (body.uncaught) {
141 details += 'Uncaught: '; 157 result += 'Uncaught: ';
142 } else { 158 } else {
143 details += 'Exception: '; 159 result += 'Exception: ';
144 } 160 }
145 details += '"'; 161 result += '"';
146 details += body.exception.text; 162 result += body.exception.text;
147 details += '"'; 163 result += '"';
148 if (body.sourceLine >= 0) { 164 if (body.sourceLine >= 0) {
149 details += ', '; 165 result += ', ';
150 details += SourceInfo(body); 166 result += SourceInfo(body);
151 details += '\n'; 167 result += '\n';
152 details += SourceUnderline(body.sourceLineText, body.sourceColumn); 168 result += SourceUnderline(body.sourceLineText, body.sourceColumn);
153 Debug.State.currentSourceLine = body.sourceLine; 169 Debug.State.currentSourceLine = body.sourceLine;
154 Debug.State.currentFrame = 0; 170 Debug.State.currentFrame = 0;
155 } else { 171 } else {
156 details += ' (empty stack)'; 172 result += ' (empty stack)';
157 Debug.State.currentSourceLine = -1; 173 Debug.State.currentSourceLine = -1;
158 Debug.State.currentFrame = kNoFrame; 174 Debug.State.currentFrame = kNoFrame;
159 } 175 }
160 return details; 176 details.text = result;
177 break;
161 178
162 case 'exception':
163 if (trace_compile) {
164 details = 'Source ' + body.script.name + ' compiled:\n'
165 } else {
166 return '';
167 }
168
169 case 'afterCompile': 179 case 'afterCompile':
170 if (trace_compile) { 180 if (trace_compile) {
171 details = 'Source ' + event.script().name() + ' compiled:\n' 181 result = 'Source ' + body.script.name + ' compiled:\n'
172 var source = body.script.source; 182 var source = body.script.source;
173 if (!(source[source.length - 1] == '\n')) { 183 if (!(source[source.length - 1] == '\n')) {
174 details += source; 184 result += source;
175 } else { 185 } else {
176 details += source.substring(0, source.length - 1); 186 result += source.substring(0, source.length - 1);
177 } 187 }
178 return details;
179 } else {
180 return '';
181 } 188 }
189 details.text = result;
190 break;
191
192 default:
193 details.text = 'Unknown debug event ' + response.event();
182 } 194 }
183 return 'Unknown debug event ' + response.event(); 195
196 return details;
184 }; 197 };
185 198
186 199
187 function SourceInfo(body) { 200 function SourceInfo(body) {
188 var result = ''; 201 var result = '';
189 202
190 if (body.script) { 203 if (body.script) {
191 if (body.script.name) { 204 if (body.script.name) {
192 result += body.script.name; 205 result += body.script.name;
193 } else { 206 } else {
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 result += ' '; 755 result += ' ';
743 result += formatHandleReference_(property_value); 756 result += formatHandleReference_(property_value);
744 result += '\n'; 757 result += '\n';
745 } 758 }
746 } 759 }
747 return result; 760 return result;
748 } 761 }
749 762
750 763
751 // Convert a JSON response to text for display in a text based debugger. 764 // Convert a JSON response to text for display in a text based debugger.
752 function DebugResponseDetails(json_response) { 765 function DebugResponseDetails(response) {
753 details = {text:'', running:false} 766 details = {text:'', running:false}
754 767
755 try { 768 try {
756 // Convert the JSON string to an object.
757 var response = new ProtocolPackage(json_response);
758
759 if (!response.success()) { 769 if (!response.success()) {
760 details.text = response.message(); 770 details.text = response.message();
761 return details; 771 return details;
762 } 772 }
763 773
764 // Get the running state. 774 // Get the running state.
765 details.running = response.running(); 775 details.running = response.running();
766 776
767 var body = response.body(); 777 var body = response.body();
768 var result = ''; 778 var result = '';
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 json += NumberToJSON_(elem); 1394 json += NumberToJSON_(elem);
1385 } else if (typeof(elem) === 'string') { 1395 } else if (typeof(elem) === 'string') {
1386 json += StringToJSON_(elem); 1396 json += StringToJSON_(elem);
1387 } else { 1397 } else {
1388 json += elem; 1398 json += elem;
1389 } 1399 }
1390 } 1400 }
1391 json += ']'; 1401 json += ']';
1392 return json; 1402 return json;
1393 } 1403 }
OLDNEW
« no previous file with comments | « src/d8.cc ('k') | src/d8-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698