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 --noanalyze-environment-liveness | 5 // Flags: --noanalyze-environment-liveness |
6 | 6 |
7 var Debug = debug.Debug; | 7 var Debug = debug.Debug; |
| 8 var global_marker = 7; |
8 | 9 |
9 function RunTest(name, formals_and_body, args, handler, continuation) { | 10 function RunTest(name, formals_and_body, args, handler, continuation) { |
10 var handler_called = false; | 11 var handler_called = false; |
11 var exception = null; | 12 var exception = null; |
12 | 13 |
13 function listener(event, exec_state, event_data, data) { | 14 function listener(event, exec_state, event_data, data) { |
14 try { | 15 try { |
15 if (event == Debug.DebugEvent.Break) { | 16 if (event == Debug.DebugEvent.Break) { |
16 handler_called = true; | 17 handler_called = true; |
17 handler(exec_state); | 18 handler(exec_state); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); | 53 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); |
53 assertPropertiesEqual(scope1.scopeObject().value(), scope2.scopeObject().value
()); | 54 assertPropertiesEqual(scope1.scopeObject().value(), scope2.scopeObject().value
()); |
54 } | 55 } |
55 | 56 |
56 function CheckFastAllScopes(scopes, exec_state) { | 57 function CheckFastAllScopes(scopes, exec_state) { |
57 var fast_all_scopes = exec_state.frame().allScopes(true); | 58 var fast_all_scopes = exec_state.frame().allScopes(true); |
58 var length = fast_all_scopes.length; | 59 var length = fast_all_scopes.length; |
59 assertTrue(scopes.length >= length); | 60 assertTrue(scopes.length >= length); |
60 for (var i = 0; i < scopes.length && i < length; i++) { | 61 for (var i = 0; i < scopes.length && i < length; i++) { |
61 var scope = fast_all_scopes[length - i - 1]; | 62 var scope = fast_all_scopes[length - i - 1]; |
62 assertTrue(scope.isScope()); | |
63 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); | 63 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 // Check that the scope chain contains the expected types of scopes. | 67 // Check that the scope chain contains the expected types of scopes. |
68 function CheckScopeChain(scopes, exec_state) { | 68 function CheckScopeChain(scopes, exec_state) { |
69 var all_scopes = exec_state.frame().allScopes(); | 69 var all_scopes = exec_state.frame().allScopes(); |
70 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 70 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
71 assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length")
; | 71 assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length")
; |
72 for (var i = 0; i < scopes.length; i++) { | 72 for (var i = 0; i < scopes.length; i++) { |
73 var scope = exec_state.frame().scope(i); | 73 var scope = exec_state.frame().scope(i); |
74 assertTrue(scope.isScope()); | |
75 assertEquals(scopes[i], scope.scopeType()); | 74 assertEquals(scopes[i], scope.scopeType()); |
76 assertScopeMirrorEquals(all_scopes[i], scope); | 75 assertScopeMirrorEquals(all_scopes[i], scope); |
77 | 76 |
78 // Check the global object when hitting the global scope. | 77 // Check the global object when hitting the global scope. |
79 if (scopes[i] == debug.ScopeType.Global) { | 78 if (scopes[i] == debug.ScopeType.Global) { |
80 // Objects don't have same class (one is "global", other is "Object", | 79 assertEquals(global_marker, scope.scopeObject().value().global_marker); |
81 // so just check the properties directly. | |
82 assertPropertiesEqual(this, scope.scopeObject().value()); | |
83 } | 80 } |
84 } | 81 } |
85 CheckFastAllScopes(scopes, exec_state); | 82 CheckFastAllScopes(scopes, exec_state); |
86 } | 83 } |
87 | 84 |
88 // Check that the content of the scope is as expected. For functions just check | 85 // Check that the content of the scope is as expected. For functions just check |
89 // that there is a function. | 86 // that there is a function. |
90 function CheckScopeContent(content, number, exec_state) { | 87 function CheckScopeContent(content, number, exec_state) { |
91 var scope = exec_state.frame().scope(number); | 88 var scope = exec_state.frame().scope(number); |
92 var count = 0; | 89 var count = 0; |
93 for (var p in content) { | 90 for (var p in content) { |
94 var property_mirror = scope.scopeObject().property(p); | 91 var property_mirror = scope.scopeObject().property(p); |
95 assertFalse(property_mirror.isUndefined(), | 92 assertFalse(property_mirror.isUndefined(), |
96 'property ' + p + ' not found in scope'); | 93 'property ' + p + ' not found in scope'); |
97 if (typeof(content[p]) === 'function') { | 94 assertEquals(content[p], property_mirror.value().value(), |
98 assertTrue(property_mirror.value().isFunction()); | 95 'property ' + p + ' has unexpected value'); |
99 } else { | |
100 assertEquals(content[p], property_mirror.value().value(), | |
101 'property ' + p + ' has unexpected value'); | |
102 } | |
103 count++; | 96 count++; |
104 } | 97 } |
105 | 98 |
106 // 'arguments' and might be exposed in the local and closure scope. Just | 99 // 'arguments' and might be exposed in the local and closure scope. Just |
107 // ignore this. | 100 // ignore this. |
108 var scope_size = scope.scopeObject().properties().length; | 101 var scope_size = scope.scopeObject().properties().length; |
109 if (!scope.scopeObject().property('arguments').isUndefined()) { | 102 if (!scope.scopeObject().property('arguments').isUndefined()) { |
110 scope_size--; | 103 scope_size--; |
111 } | 104 } |
112 // Skip property with empty name. | 105 // Skip property with empty name. |
113 if (!scope.scopeObject().property('').isUndefined()) { | 106 if (!scope.scopeObject().property('').isUndefined()) { |
114 scope_size--; | 107 scope_size--; |
115 } | 108 } |
116 | 109 |
117 if (count != scope_size) { | 110 if (scope_size < count) { |
118 print('Names found in scope:'); | 111 print('Names found in scope:'); |
119 var names = scope.scopeObject().propertyNames(); | 112 var names = scope.scopeObject().propertyNames(); |
120 for (var i = 0; i < names.length; i++) { | 113 for (var i = 0; i < names.length; i++) { |
121 print(names[i]); | 114 print(names[i]); |
122 } | 115 } |
123 } | 116 } |
124 assertEquals(count, scope_size); | 117 assertTrue(scope_size >= count); |
125 } | 118 } |
126 | 119 |
127 | 120 |
128 // Simple empty local scope. | 121 // Simple empty local scope. |
129 RunTest("Local 1", | 122 RunTest("Local 1", |
130 ['debugger;'], | 123 ['debugger;'], |
131 [], | 124 [], |
132 function (exec_state) { | 125 function (exec_state) { |
133 CheckScopeChain([debug.ScopeType.Local, | 126 CheckScopeChain([debug.ScopeType.Local, |
134 debug.ScopeType.Script, | 127 debug.ScopeType.Script, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 [1, 2], | 194 [1, 2], |
202 function (exec_state) { | 195 function (exec_state) { |
203 CheckScopeChain([debug.ScopeType.Local, | 196 CheckScopeChain([debug.ScopeType.Local, |
204 debug.ScopeType.Script, | 197 debug.ScopeType.Script, |
205 debug.ScopeType.Global], exec_state); | 198 debug.ScopeType.Global], exec_state); |
206 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); | 199 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); |
207 }); | 200 }); |
208 | 201 |
209 // Nested empty with blocks. | 202 // Nested empty with blocks. |
210 RunTest("With", | 203 RunTest("With", |
211 ["with ({}) { with ({}) { debugger; } }"], | 204 ["with ({a:1}) { with ({b:2}) { debugger; } }"], |
212 [], | 205 [], |
213 function (exec_state) { | 206 function (exec_state) { |
214 CheckScopeChain([debug.ScopeType.With, | 207 CheckScopeChain([debug.ScopeType.With, |
215 debug.ScopeType.With, | 208 debug.ScopeType.With, |
216 debug.ScopeType.Local, | 209 debug.ScopeType.Local, |
217 debug.ScopeType.Script, | 210 debug.ScopeType.Script, |
218 debug.ScopeType.Global], exec_state); | 211 debug.ScopeType.Global], exec_state); |
219 CheckScopeContent({}, 0, exec_state); | 212 CheckScopeContent({b:2}, 0, exec_state); |
220 CheckScopeContent({}, 1, exec_state); | 213 CheckScopeContent({a:1}, 1, exec_state); |
221 }); | 214 }); |
222 | 215 |
223 // Simple closure formed by returning an inner function referering the outer | 216 // Simple closure formed by returning an inner function referering the outer |
224 // functions arguments. | 217 // functions arguments. |
225 RunTest("Closure 1", | 218 RunTest("Closure 1", |
226 ['a', 'return function() { debugger; return a; }'], | 219 ['a', 'return function() { debugger; return a; }'], |
227 [1], | 220 [1], |
228 function (exec_state) { | 221 function (exec_state) { |
229 CheckScopeChain([debug.ScopeType.Local, | 222 CheckScopeChain([debug.ScopeType.Local, |
230 debug.ScopeType.Closure, | 223 debug.ScopeType.Closure, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 debug.ScopeType.With, | 260 debug.ScopeType.With, |
268 debug.ScopeType.Closure, | 261 debug.ScopeType.Closure, |
269 debug.ScopeType.Closure, | 262 debug.ScopeType.Closure, |
270 debug.ScopeType.Script, | 263 debug.ScopeType.Script, |
271 debug.ScopeType.Global], exec_state); | 264 debug.ScopeType.Global], exec_state); |
272 CheckScopeContent({b:16}, 0, exec_state); | 265 CheckScopeContent({b:16}, 0, exec_state); |
273 CheckScopeContent({a:15}, 1, exec_state); | 266 CheckScopeContent({a:15}, 1, exec_state); |
274 CheckScopeContent({x:14}, 2, exec_state); | 267 CheckScopeContent({x:14}, 2, exec_state); |
275 CheckScopeContent({j:13}, 3, exec_state); | 268 CheckScopeContent({j:13}, 3, exec_state); |
276 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); | 269 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); |
277 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, | 270 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:undefined}, 5, |
278 exec_state); | 271 exec_state); |
279 }, | 272 }, |
280 function (result) { result() }); | 273 function (result) { result() }); |
281 | 274 |
282 RunTest("Catch block 1", | 275 RunTest("Catch block 1", |
283 ["try { throw 'Exception'; } catch (e) { debugger; }"], | 276 ["try { throw 'Exception'; } catch (e) { debugger; }"], |
284 [], | 277 [], |
285 function (exec_state) { | 278 function (exec_state) { |
286 CheckScopeChain([debug.ScopeType.Catch, | 279 CheckScopeChain([debug.ScopeType.Catch, |
287 debug.ScopeType.Local, | 280 debug.ScopeType.Local, |
288 debug.ScopeType.Script, | 281 debug.ScopeType.Script, |
289 debug.ScopeType.Global], exec_state); | 282 debug.ScopeType.Global], exec_state); |
290 CheckScopeContent({e:'Exception'}, 0, exec_state); | 283 CheckScopeContent({e:'Exception'}, 0, exec_state); |
291 }); | 284 }); |
OLD | NEW |