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

Side by Side Diff: test/mjsunit/debug-backtrace.js

Issue 18092: Added handles to the mirror objects. When a mirror for an object is created... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 11 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/mirror-delay.js ('k') | test/mjsunit/mirror-array.js » ('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 25 matching lines...) Expand all
36 new f(1); 36 new f(1);
37 }; 37 };
38 38
39 39
40 // Get the Debug object exposed from the debug context global object. 40 // Get the Debug object exposed from the debug context global object.
41 Debug = debug.Debug 41 Debug = debug.Debug
42 42
43 listenerCalled = false; 43 listenerCalled = false;
44 exception = false; 44 exception = false;
45 45
46 function safeEval(code) { 46
47 try { 47 function ParsedResponse(json) {
48 return eval('(' + code + ')'); 48 this.response_ = eval('(' + json + ')');
49 } catch (e) { 49 this.refs_ = [];
50 return undefined; 50 if (this.response_.refs) {
51 for (var i = 0; i < this.response_.refs.length; i++) {
52 this.refs_[this.response_.refs[i].handle] = this.response_.refs[i];
53 }
51 } 54 }
52 } 55 }
53 56
57
58 ParsedResponse.prototype.response = function() {
59 return this.response_;
60 }
61
62
63 ParsedResponse.prototype.body = function() {
64 return this.response_.body;
65 }
66
67
68 ParsedResponse.prototype.lookup = function(handle) {
69 return this.refs_[handle];
70 }
71
72
54 function listener(event, exec_state, event_data, data) { 73 function listener(event, exec_state, event_data, data) {
55 try { 74 try {
56 if (event == Debug.DebugEvent.Break) 75 if (event == Debug.DebugEvent.Break)
57 { 76 {
58 // The expected backtrace is 77 // The expected backtrace is
59 // 0: f 78 // 0: f
60 // 1: g 79 // 1: g
61 // 2: [anonymous] 80 // 2: [anonymous]
62 81
82 var response;
83 var backtrace;
84 var frame;
85 var source;
86
63 // Get the debug command processor. 87 // Get the debug command processor.
64 var dcp = exec_state.debugCommandProcessor(); 88 var dcp = exec_state.debugCommandProcessor();
65 89
66 // Get the backtrace. 90 // Get the backtrace.
67 var json; 91 var json;
68 json = '{"seq":0,"type":"request","command":"backtrace"}' 92 json = '{"seq":0,"type":"request","command":"backtrace"}'
69 var backtrace = safeEval(dcp.processDebugJSONRequest(json)).body; 93 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
94 backtrace = response.body();
70 assertEquals(0, backtrace.fromFrame); 95 assertEquals(0, backtrace.fromFrame);
71 assertEquals(3, backtrace.toFrame); 96 assertEquals(3, backtrace.toFrame);
72 assertEquals(3, backtrace.totalFrames); 97 assertEquals(3, backtrace.totalFrames);
73 var frames = backtrace.frames; 98 var frames = backtrace.frames;
74 assertEquals(3, frames.length); 99 assertEquals(3, frames.length);
75 for (var i = 0; i < frames.length; i++) { 100 for (var i = 0; i < frames.length; i++) {
76 assertEquals('frame', frames[i].type); 101 assertEquals('frame', frames[i].type);
77 } 102 }
78 assertEquals(0, frames[0].index); 103 assertEquals(0, frames[0].index);
79 assertEquals("f", frames[0].func.name); 104 assertEquals("f", response.lookup(frames[0].func.ref).name);
80 assertEquals(1, frames[1].index); 105 assertEquals(1, frames[1].index);
81 assertEquals("g", frames[1].func.name); 106 assertEquals("g", response.lookup(frames[1].func.ref).name);
82 assertEquals(2, frames[2].index); 107 assertEquals(2, frames[2].index);
83 assertEquals("", frames[2].func.name); 108 assertEquals("", response.lookup(frames[2].func.ref).name);
84 109
85 // Get backtrace with two frames. 110 // Get backtrace with two frames.
86 json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFr ame":1,"toFrame":3}}' 111 json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFr ame":1,"toFrame":3}}'
87 var backtrace = safeEval(dcp.processDebugJSONRequest(json)).body; 112 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
113 backtrace = response.body();
88 assertEquals(1, backtrace.fromFrame); 114 assertEquals(1, backtrace.fromFrame);
89 assertEquals(3, backtrace.toFrame); 115 assertEquals(3, backtrace.toFrame);
90 assertEquals(3, backtrace.totalFrames); 116 assertEquals(3, backtrace.totalFrames);
91 var frames = backtrace.frames; 117 var frames = backtrace.frames;
92 assertEquals(2, frames.length); 118 assertEquals(2, frames.length);
93 for (var i = 0; i < frames.length; i++) { 119 for (var i = 0; i < frames.length; i++) {
94 assertEquals('frame', frames[i].type); 120 assertEquals('frame', frames[i].type);
95 } 121 }
96 assertEquals(1, frames[0].index); 122 assertEquals(1, frames[0].index);
97 assertEquals("g", frames[0].func.name); 123 assertEquals("g", response.lookup(frames[0].func.ref).name);
98 assertEquals(2, frames[1].index); 124 assertEquals(2, frames[1].index);
99 assertEquals("", frames[1].func.name); 125 assertEquals("", response.lookup(frames[1].func.ref).name);
100 126
101 // Get the individual frames. 127 // Get the individual frames.
102 var frame;
103 json = '{"seq":0,"type":"request","command":"frame"}' 128 json = '{"seq":0,"type":"request","command":"frame"}'
104 frame = safeEval(dcp.processDebugJSONRequest(json)).body; 129 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
130 frame = response.body();
105 assertEquals(0, frame.index); 131 assertEquals(0, frame.index);
106 assertEquals("f", frame.func.name); 132 assertEquals("f", response.lookup(frame.func.ref).name);
107 assertTrue(frame.constructCall); 133 assertTrue(frame.constructCall);
108 assertEquals(31, frame.line); 134 assertEquals(31, frame.line);
109 assertEquals(3, frame.column); 135 assertEquals(3, frame.column);
110 assertEquals(2, frame.arguments.length); 136 assertEquals(2, frame.arguments.length);
111 assertEquals('x', frame.arguments[0].name); 137 assertEquals('x', frame.arguments[0].name);
112 assertEquals('number', frame.arguments[0].value.type); 138 assertEquals('number', response.lookup(frame.arguments[0].value.ref).type);
113 assertEquals(1, frame.arguments[0].value.value); 139 assertEquals(1, response.lookup(frame.arguments[0].value.ref).value);
114 assertEquals('y', frame.arguments[1].name); 140 assertEquals('y', frame.arguments[1].name);
115 assertEquals('undefined', frame.arguments[1].value.type); 141 assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).type );
116 142
117 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":0} }' 143 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":0} }'
118 frame = safeEval(dcp.processDebugJSONRequest(json)).body; 144 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
145 frame = response.body();
119 assertEquals(0, frame.index); 146 assertEquals(0, frame.index);
120 assertEquals("f", frame.func.name); 147 assertEquals("f", response.lookup(frame.func.ref).name);
121 assertEquals(31, frame.line); 148 assertEquals(31, frame.line);
122 assertEquals(3, frame.column); 149 assertEquals(3, frame.column);
123 assertEquals(2, frame.arguments.length); 150 assertEquals(2, frame.arguments.length);
124 assertEquals('x', frame.arguments[0].name); 151 assertEquals('x', frame.arguments[0].name);
125 assertEquals('number', frame.arguments[0].value.type); 152 assertEquals('number', response.lookup(frame.arguments[0].value.ref).type);
126 assertEquals(1, frame.arguments[0].value.value); 153 assertEquals(1, response.lookup(frame.arguments[0].value.ref).value);
127 assertEquals('y', frame.arguments[1].name); 154 assertEquals('y', frame.arguments[1].name);
128 assertEquals('undefined', frame.arguments[1].value.type); 155 assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).type );
129 156
130 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":1} }' 157 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":1} }'
131 frame = safeEval(dcp.processDebugJSONRequest(json)).body; 158 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
159 frame = response.body();
132 assertEquals(1, frame.index); 160 assertEquals(1, frame.index);
133 assertEquals("g", frame.func.name); 161 assertEquals("g", response.lookup(frame.func.ref).name);
134 assertFalse(frame.constructCall); 162 assertFalse(frame.constructCall);
135 assertEquals(35, frame.line); 163 assertEquals(35, frame.line);
136 assertEquals(2, frame.column); 164 assertEquals(2, frame.column);
137 assertEquals(0, frame.arguments.length); 165 assertEquals(0, frame.arguments.length);
138 166
139 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":2} }' 167 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":2} }'
140 frame = safeEval(dcp.processDebugJSONRequest(json)).body; 168 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
169 frame = response.body();
141 assertEquals(2, frame.index); 170 assertEquals(2, frame.index);
142 assertEquals("", frame.func.name); 171 assertEquals("", response.lookup(frame.func.ref).name);
143 172
144 // Source slices for the individual frames (they all refer to this script). 173 // Source slices for the individual frames (they all refer to this script).
145 json = '{"seq":0,"type":"request","command":"source",' + 174 json = '{"seq":0,"type":"request","command":"source",' +
146 '"arguments":{"frame":0,"fromLine":30,"toLine":32}}' 175 '"arguments":{"frame":0,"fromLine":30,"toLine":32}}'
147 source = safeEval(dcp.processDebugJSONRequest(json)).body; 176 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
177 source = response.body();
148 assertEquals("function f(x, y) {", source.source.substring(0, 18)); 178 assertEquals("function f(x, y) {", source.source.substring(0, 18));
149 assertEquals(30, source.fromLine); 179 assertEquals(30, source.fromLine);
150 assertEquals(32, source.toLine); 180 assertEquals(32, source.toLine);
151 181
152 json = '{"seq":0,"type":"request","command":"source",' + 182 json = '{"seq":0,"type":"request","command":"source",' +
153 '"arguments":{"frame":1,"fromLine":31,"toLine":32}}' 183 '"arguments":{"frame":1,"fromLine":31,"toLine":32}}'
154 source = safeEval(dcp.processDebugJSONRequest(json)).body; 184 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
185 source = response.body();
155 assertEquals(" a=1;", source.source.substring(0, 6)); 186 assertEquals(" a=1;", source.source.substring(0, 6));
156 assertEquals(31, source.fromLine); 187 assertEquals(31, source.fromLine);
157 assertEquals(32, source.toLine); 188 assertEquals(32, source.toLine);
158 189
159 json = '{"seq":0,"type":"request","command":"source",' + 190 json = '{"seq":0,"type":"request","command":"source",' +
160 '"arguments":{"frame":2,"fromLine":35,"toLine":36}}' 191 '"arguments":{"frame":2,"fromLine":35,"toLine":36}}'
161 source = safeEval(dcp.processDebugJSONRequest(json)).body; 192 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
193 source = response.body();
162 assertEquals(" new f(1);", source.source.substring(0, 11)); 194 assertEquals(" new f(1);", source.source.substring(0, 11));
163 assertEquals(35, source.fromLine); 195 assertEquals(35, source.fromLine);
164 assertEquals(36, source.toLine); 196 assertEquals(36, source.toLine);
165 197
166 // Test line interval way beyond this script will result in an error. 198 // Test line interval way beyond this script will result in an error.
167 json = '{"seq":0,"type":"request","command":"source",' + 199 json = '{"seq":0,"type":"request","command":"source",' +
168 '"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}' 200 '"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}'
169 response = safeEval(dcp.processDebugJSONRequest(json)); 201 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
170 assertFalse(response.success); 202 assertFalse(response.response().success);
171 203
172 // Test without arguments. 204 // Test without arguments.
173 json = '{"seq":0,"type":"request","command":"source"}' 205 json = '{"seq":0,"type":"request","command":"source"}'
174 source = safeEval(dcp.processDebugJSONRequest(json)).body; 206 response = new ParsedResponse(dcp.processDebugJSONRequest(json));
207 source = response.body();
175 assertEquals(Debug.findScript(f).source, source.source); 208 assertEquals(Debug.findScript(f).source, source.source);
176 209
177 listenerCalled = true; 210 listenerCalled = true;
178 } 211 }
179 } catch (e) { 212 } catch (e) {
180 exception = e 213 exception = e
181 }; 214 };
182 }; 215 };
183 216
184 // Add the debug event listener. 217 // Add the debug event listener.
185 Debug.addListener(listener); 218 Debug.addListener(listener);
186 219
187 // Set a break point and call to invoke the debug event listener. 220 // Set a break point and call to invoke the debug event listener.
188 Debug.setBreakPoint(f, 0, 0); 221 Debug.setBreakPoint(f, 0, 0);
189 g(); 222 g();
190 223
191 // Make sure that the debug event listener vas invoked. 224 // Make sure that the debug event listener vas invoked.
192 assertFalse(exception, "exception in listener"); 225 assertFalse(exception, "exception in listener");
193 assertTrue(listenerCalled); 226 assertTrue(listenerCalled);
194 227
OLDNEW
« no previous file with comments | « src/mirror-delay.js ('k') | test/mjsunit/mirror-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698