OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 assertTrue(scope.isScope()); | 86 assertTrue(scope.isScope()); |
87 assertEquals(scopes[i], scope.scopeType()); | 87 assertEquals(scopes[i], scope.scopeType()); |
88 | 88 |
89 // Check the global object when hitting the global scope. | 89 // Check the global object when hitting the global scope. |
90 if (scopes[i] == debug.ScopeType.Global) { | 90 if (scopes[i] == debug.ScopeType.Global) { |
91 // Objects don't have same class (one is "global", other is "Object", | 91 // Objects don't have same class (one is "global", other is "Object", |
92 // so just check the properties directly. | 92 // so just check the properties directly. |
93 assertPropertiesEqual(this, scope.scopeObject().value()); | 93 assertPropertiesEqual(this, scope.scopeObject().value()); |
94 } | 94 } |
95 } | 95 } |
96 | |
97 // Get the debug command processor. | |
98 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | |
99 | |
100 // Send a scopes request and check the result. | |
101 var json; | |
102 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; | |
103 var response_json = dcp.processDebugJSONRequest(request_json); | |
104 var response = JSON.parse(response_json); | |
105 assertEquals(scopes.length, response.body.scopes.length); | |
106 for (var i = 0; i < scopes.length; i++) { | |
107 assertEquals(i, response.body.scopes[i].index); | |
108 assertEquals(scopes[i], response.body.scopes[i].type); | |
109 if (scopes[i] == debug.ScopeType.Local || | |
110 scopes[i] == debug.ScopeType.Closure) { | |
111 assertTrue(response.body.scopes[i].object.ref < 0); | |
112 } else { | |
113 assertTrue(response.body.scopes[i].object.ref >= 0); | |
114 } | |
115 var found = false; | |
116 for (var j = 0; j < response.refs.length && !found; j++) { | |
117 found = response.refs[j].handle == response.body.scopes[i].object.ref; | |
118 } | |
119 assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " n
ot found"); | |
120 } | |
121 } | 96 } |
122 | 97 |
123 // Check that the content of the scope is as expected. For functions just check | 98 // Check that the content of the scope is as expected. For functions just check |
124 // that there is a function. | 99 // that there is a function. |
125 function CheckScopeContent(content, number, exec_state) { | 100 function CheckScopeContent(content, number, exec_state) { |
126 var scope = exec_state.frame().scope(number); | 101 var scope = exec_state.frame().scope(number); |
127 var count = 0; | 102 var count = 0; |
128 for (var p in content) { | 103 for (var p in content) { |
129 var property_mirror = scope.scopeObject().property(p); | 104 var property_mirror = scope.scopeObject().property(p); |
130 if (property_mirror.isUndefined()) { | 105 if (property_mirror.isUndefined()) { |
131 print('property ' + p + ' not found in scope'); | 106 print('property ' + p + ' not found in scope'); |
132 } | 107 } |
133 assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in
scope'); | 108 assertFalse(property_mirror.isUndefined(), |
| 109 'property ' + p + ' not found in scope'); |
134 if (typeof(content[p]) === 'function') { | 110 if (typeof(content[p]) === 'function') { |
135 assertTrue(property_mirror.value().isFunction()); | 111 assertTrue(property_mirror.value().isFunction()); |
136 } else { | 112 } else { |
137 assertEquals(content[p], property_mirror.value().value(), 'property ' + p
+ ' has unexpected value'); | 113 assertEquals(content[p], property_mirror.value().value(), |
| 114 'property ' + p + ' has unexpected value'); |
138 } | 115 } |
139 count++; | 116 count++; |
140 } | 117 } |
141 | 118 |
142 // 'arguments' and might be exposed in the local and closure scope. Just | 119 // 'arguments' and might be exposed in the local and closure scope. Just |
143 // ignore this. | 120 // ignore this. |
144 var scope_size = scope.scopeObject().properties().length; | 121 var scope_size = scope.scopeObject().properties().length; |
145 if (!scope.scopeObject().property('arguments').isUndefined()) { | 122 if (!scope.scopeObject().property('arguments').isUndefined()) { |
146 scope_size--; | 123 scope_size--; |
147 } | 124 } |
148 // Skip property with empty name. | 125 // Skip property with empty name. |
149 if (!scope.scopeObject().property('').isUndefined()) { | 126 if (!scope.scopeObject().property('').isUndefined()) { |
150 scope_size--; | 127 scope_size--; |
151 } | 128 } |
152 | 129 |
153 if (count != scope_size) { | 130 if (count != scope_size) { |
154 print('Names found in scope:'); | 131 print('Names found in scope:'); |
155 var names = scope.scopeObject().propertyNames(); | 132 var names = scope.scopeObject().propertyNames(); |
156 for (var i = 0; i < names.length; i++) { | 133 for (var i = 0; i < names.length; i++) { |
157 print(names[i]); | 134 print(names[i]); |
158 } | 135 } |
159 } | 136 } |
160 assertEquals(count, scope_size); | 137 assertEquals(count, scope_size); |
161 | |
162 // Get the debug command processor. | |
163 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | |
164 | |
165 // Send a scope request for information on a single scope and check the | |
166 // result. | |
167 var request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"
number":'; | |
168 request_json += scope.scopeIndex(); | |
169 request_json += '}}'; | |
170 var response_json = dcp.processDebugJSONRequest(request_json); | |
171 var response = JSON.parse(response_json); | |
172 assertEquals(scope.scopeType(), response.body.type); | |
173 assertEquals(number, response.body.index); | |
174 if (scope.scopeType() == debug.ScopeType.Local || | |
175 scope.scopeType() == debug.ScopeType.Closure) { | |
176 assertTrue(response.body.object.ref < 0); | |
177 } else { | |
178 assertTrue(response.body.object.ref >= 0); | |
179 } | |
180 var found = false; | |
181 for (var i = 0; i < response.refs.length && !found; i++) { | |
182 found = response.refs[i].handle == response.body.object.ref; | |
183 } | |
184 assertTrue(found, "Scope object " + response.body.object.ref + " not found"); | |
185 } | 138 } |
186 | 139 |
187 | 140 |
188 // Simple closure formed by returning an inner function referering to an outer | 141 // Simple closure formed by returning an inner function referering to an outer |
189 // block local variable and an outer function's parameter. Due to VM | 142 // block local variable and an outer function's parameter. Due to VM |
190 // optimizations parts of the actual closure is missing from the debugger | 143 // optimizations parts of the actual closure is missing from the debugger |
191 // information. | 144 // information. |
192 BeginTest("Closure 1"); | 145 BeginTest("Closure 1"); |
193 | 146 |
194 function closure_1(a) { | 147 function closure_1(a) { |
(...skipping 13 matching lines...) Expand all Loading... |
208 CheckScopeChain([debug.ScopeType.Local, | 161 CheckScopeChain([debug.ScopeType.Local, |
209 debug.ScopeType.Block, | 162 debug.ScopeType.Block, |
210 debug.ScopeType.Closure, | 163 debug.ScopeType.Closure, |
211 debug.ScopeType.Global], exec_state); | 164 debug.ScopeType.Global], exec_state); |
212 CheckScopeContent({}, 0, exec_state); | 165 CheckScopeContent({}, 0, exec_state); |
213 CheckScopeContent({z:4}, 1, exec_state); | 166 CheckScopeContent({z:4}, 1, exec_state); |
214 CheckScopeContent({a:1,x:2,y:3}, 2, exec_state); | 167 CheckScopeContent({a:1,x:2,y:3}, 2, exec_state); |
215 }; | 168 }; |
216 closure_1(1)(); | 169 closure_1(1)(); |
217 EndTest(); | 170 EndTest(); |
OLD | NEW |