OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-debug-as debug | 5 // Flags: --expose-debug-as debug |
6 | 6 |
7 var Debug = debug.Debug; | 7 var Debug = debug.Debug; |
8 | 8 |
9 function RunTest(name, formals_and_body, args, handler, continuation) { | 9 function RunTest(name, formals_and_body, args, handler, continuation) { |
10 var handler_called = false; | 10 var handler_called = false; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 assertScopeMirrorEquals(all_scopes[i], scope); | 76 assertScopeMirrorEquals(all_scopes[i], scope); |
77 | 77 |
78 // Check the global object when hitting the global scope. | 78 // Check the global object when hitting the global scope. |
79 if (scopes[i] == debug.ScopeType.Global) { | 79 if (scopes[i] == debug.ScopeType.Global) { |
80 // Objects don't have same class (one is "global", other is "Object", | 80 // Objects don't have same class (one is "global", other is "Object", |
81 // so just check the properties directly. | 81 // so just check the properties directly. |
82 assertPropertiesEqual(this, scope.scopeObject().value()); | 82 assertPropertiesEqual(this, scope.scopeObject().value()); |
83 } | 83 } |
84 } | 84 } |
85 CheckFastAllScopes(scopes, exec_state); | 85 CheckFastAllScopes(scopes, exec_state); |
86 | |
87 // Get the debug command processor. | |
88 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | |
89 | |
90 // Send a scopes request and check the result. | |
91 var json; | |
92 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; | |
93 var response_json = dcp.processDebugJSONRequest(request_json); | |
94 var response = JSON.parse(response_json); | |
95 assertEquals(scopes.length, response.body.scopes.length); | |
96 for (var i = 0; i < scopes.length; i++) { | |
97 assertEquals(i, response.body.scopes[i].index); | |
98 assertEquals(scopes[i], response.body.scopes[i].type); | |
99 if (scopes[i] == debug.ScopeType.Local || | |
100 scopes[i] == debug.ScopeType.Script || | |
101 scopes[i] == debug.ScopeType.Closure) { | |
102 assertTrue(response.body.scopes[i].object.ref < 0); | |
103 } else { | |
104 assertTrue(response.body.scopes[i].object.ref >= 0); | |
105 } | |
106 var found = false; | |
107 for (var j = 0; j < response.refs.length && !found; j++) { | |
108 found = response.refs[j].handle == response.body.scopes[i].object.ref; | |
109 } | |
110 assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " n
ot found"); | |
111 } | |
112 } | 86 } |
113 | 87 |
114 // Check that the content of the scope is as expected. For functions just check | 88 // Check that the content of the scope is as expected. For functions just check |
115 // that there is a function. | 89 // that there is a function. |
116 function CheckScopeContent(content, number, exec_state) { | 90 function CheckScopeContent(content, number, exec_state) { |
117 var scope = exec_state.frame().scope(number); | 91 var scope = exec_state.frame().scope(number); |
118 var count = 0; | 92 var count = 0; |
119 for (var p in content) { | 93 for (var p in content) { |
120 var property_mirror = scope.scopeObject().property(p); | 94 var property_mirror = scope.scopeObject().property(p); |
121 assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in
scope'); | 95 assertFalse(property_mirror.isUndefined(), |
| 96 'property ' + p + ' not found in scope'); |
122 if (typeof(content[p]) === 'function') { | 97 if (typeof(content[p]) === 'function') { |
123 assertTrue(property_mirror.value().isFunction()); | 98 assertTrue(property_mirror.value().isFunction()); |
124 } else { | 99 } else { |
125 assertEquals(content[p], property_mirror.value().value(), 'property ' + p
+ ' has unexpected value'); | 100 assertEquals(content[p], property_mirror.value().value(), |
| 101 'property ' + p + ' has unexpected value'); |
126 } | 102 } |
127 count++; | 103 count++; |
128 } | 104 } |
129 | 105 |
130 // 'arguments' and might be exposed in the local and closure scope. Just | 106 // 'arguments' and might be exposed in the local and closure scope. Just |
131 // ignore this. | 107 // ignore this. |
132 var scope_size = scope.scopeObject().properties().length; | 108 var scope_size = scope.scopeObject().properties().length; |
133 if (!scope.scopeObject().property('arguments').isUndefined()) { | 109 if (!scope.scopeObject().property('arguments').isUndefined()) { |
134 scope_size--; | 110 scope_size--; |
135 } | 111 } |
136 // Skip property with empty name. | 112 // Skip property with empty name. |
137 if (!scope.scopeObject().property('').isUndefined()) { | 113 if (!scope.scopeObject().property('').isUndefined()) { |
138 scope_size--; | 114 scope_size--; |
139 } | 115 } |
140 | 116 |
141 if (count != scope_size) { | 117 if (count != scope_size) { |
142 print('Names found in scope:'); | 118 print('Names found in scope:'); |
143 var names = scope.scopeObject().propertyNames(); | 119 var names = scope.scopeObject().propertyNames(); |
144 for (var i = 0; i < names.length; i++) { | 120 for (var i = 0; i < names.length; i++) { |
145 print(names[i]); | 121 print(names[i]); |
146 } | 122 } |
147 } | 123 } |
148 assertEquals(count, scope_size); | 124 assertEquals(count, scope_size); |
149 | |
150 // Get the debug command processor. | |
151 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | |
152 | |
153 // Send a scope request for information on a single scope and check the | |
154 // result. | |
155 var request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"
number":'; | |
156 request_json += scope.scopeIndex(); | |
157 request_json += '}}'; | |
158 var response_json = dcp.processDebugJSONRequest(request_json); | |
159 var response = JSON.parse(response_json); | |
160 assertEquals(scope.scopeType(), response.body.type); | |
161 assertEquals(number, response.body.index); | |
162 if (scope.scopeType() == debug.ScopeType.Local || | |
163 scope.scopeType() == debug.ScopeType.Script || | |
164 scope.scopeType() == debug.ScopeType.Closure) { | |
165 assertTrue(response.body.object.ref < 0); | |
166 } else { | |
167 assertTrue(response.body.object.ref >= 0); | |
168 } | |
169 var found = false; | |
170 for (var i = 0; i < response.refs.length && !found; i++) { | |
171 found = response.refs[i].handle == response.body.object.ref; | |
172 } | |
173 assertTrue(found, "Scope object " + response.body.object.ref + " not found"); | |
174 } | 125 } |
175 | 126 |
176 | 127 |
177 // Simple empty local scope. | 128 // Simple empty local scope. |
178 RunTest("Local 1", | 129 RunTest("Local 1", |
179 ['debugger;'], | 130 ['debugger;'], |
180 [], | 131 [], |
181 function (exec_state) { | 132 function (exec_state) { |
182 CheckScopeChain([debug.ScopeType.Local, | 133 CheckScopeChain([debug.ScopeType.Local, |
183 debug.ScopeType.Script, | 134 debug.ScopeType.Script, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 debug.ScopeType.With, | 267 debug.ScopeType.With, |
317 debug.ScopeType.Closure, | 268 debug.ScopeType.Closure, |
318 debug.ScopeType.Closure, | 269 debug.ScopeType.Closure, |
319 debug.ScopeType.Script, | 270 debug.ScopeType.Script, |
320 debug.ScopeType.Global], exec_state); | 271 debug.ScopeType.Global], exec_state); |
321 CheckScopeContent({b:16}, 0, exec_state); | 272 CheckScopeContent({b:16}, 0, exec_state); |
322 CheckScopeContent({a:15}, 1, exec_state); | 273 CheckScopeContent({a:15}, 1, exec_state); |
323 CheckScopeContent({x:14}, 2, exec_state); | 274 CheckScopeContent({x:14}, 2, exec_state); |
324 CheckScopeContent({j:13}, 3, exec_state); | 275 CheckScopeContent({j:13}, 3, exec_state); |
325 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); | 276 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); |
326 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_st
ate); | 277 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, |
| 278 exec_state); |
327 }, | 279 }, |
328 function (result) { result() }); | 280 function (result) { result() }); |
329 | 281 |
330 RunTest("Catch block 1", | 282 RunTest("Catch block 1", |
331 ["try { throw 'Exception'; } catch (e) { debugger; }"], | 283 ["try { throw 'Exception'; } catch (e) { debugger; }"], |
332 [], | 284 [], |
333 function (exec_state) { | 285 function (exec_state) { |
334 CheckScopeChain([debug.ScopeType.Catch, | 286 CheckScopeChain([debug.ScopeType.Catch, |
335 debug.ScopeType.Local, | 287 debug.ScopeType.Local, |
336 debug.ScopeType.Script, | 288 debug.ScopeType.Script, |
337 debug.ScopeType.Global], exec_state); | 289 debug.ScopeType.Global], exec_state); |
338 CheckScopeContent({e:'Exception'}, 0, exec_state); | 290 CheckScopeContent({e:'Exception'}, 0, exec_state); |
339 }); | 291 }); |
OLD | NEW |