OLD | NEW |
| (Empty) |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // MODULE | |
6 // Flags: --expose-debug-as debug | |
7 | |
8 | |
9 var Debug = debug.Debug; | |
10 | |
11 var test_name; | |
12 var listener_delegate; | |
13 var listener_called; | |
14 var exception; | |
15 var begin_test_count = 0; | |
16 var end_test_count = 0; | |
17 var break_count = 0; | |
18 | |
19 function listener(event, exec_state, event_data, data) { | |
20 try { | |
21 if (event == Debug.DebugEvent.Break) { | |
22 break_count++; | |
23 listener_called = true; | |
24 listener_delegate(exec_state); | |
25 } | |
26 } catch (e) { | |
27 exception = e; | |
28 } | |
29 } | |
30 | |
31 Debug.setListener(listener); | |
32 | |
33 | |
34 function BeginTest(name) { | |
35 test_name = name; | |
36 listener_delegate = null; | |
37 listener_called = false; | |
38 exception = null; | |
39 begin_test_count++; | |
40 } | |
41 | |
42 function EndTest() { | |
43 assertTrue(listener_called, "listener not called for " + test_name); | |
44 assertNull(exception, test_name + " / " + exception); | |
45 end_test_count++; | |
46 } | |
47 | |
48 | |
49 // Check that two scope are the same. | |
50 function assertScopeMirrorEquals(scope1, scope2) { | |
51 assertEquals(scope1.scopeType(), scope2.scopeType()); | |
52 assertEquals(scope1.frameIndex(), scope2.frameIndex()); | |
53 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); | |
54 assertPropertiesEqual(scope1.scopeObject().value(), scope2.scopeObject().value
()); | |
55 } | |
56 | |
57 function CheckFastAllScopes(scopes, exec_state) | |
58 { | |
59 var fast_all_scopes = exec_state.frame().allScopes(true); | |
60 var length = fast_all_scopes.length; | |
61 assertTrue(scopes.length >= length); | |
62 for (var i = 0; i < scopes.length && i < length; i++) { | |
63 var scope = fast_all_scopes[length - i - 1]; | |
64 assertTrue(scope.isScope()); | |
65 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); | |
66 } | |
67 } | |
68 | |
69 | |
70 // Check that the scope chain contains the expected types of scopes. | |
71 function CheckScopeChain(scopes, exec_state) { | |
72 var all_scopes = exec_state.frame().allScopes(); | |
73 assertEquals(scopes.length, exec_state.frame().scopeCount()); | |
74 assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length")
; | |
75 for (var i = 0; i < scopes.length; i++) { | |
76 var scope = exec_state.frame().scope(i); | |
77 assertTrue(scope.isScope()); | |
78 assertEquals(scopes[i], scope.scopeType()); | |
79 assertScopeMirrorEquals(all_scopes[i], scope); | |
80 } | |
81 CheckFastAllScopes(scopes, exec_state); | |
82 } | |
83 | |
84 | |
85 function CheckScopeDoesNotHave(properties, number, exec_state) { | |
86 var scope = exec_state.frame().scope(number); | |
87 for (var p of properties) { | |
88 var property_mirror = scope.scopeObject().property(p); | |
89 assertTrue(property_mirror.isUndefined(), 'property ' + p + ' found in scope
'); | |
90 } | |
91 } | |
92 | |
93 | |
94 // Check that the scope contains at least minimum_content. For functions just | |
95 // check that there is a function. | |
96 function CheckScopeContent(minimum_content, number, exec_state) { | |
97 var scope = exec_state.frame().scope(number); | |
98 var minimum_count = 0; | |
99 for (var p in minimum_content) { | |
100 var property_mirror = scope.scopeObject().property(p); | |
101 assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in
scope'); | |
102 if (typeof(minimum_content[p]) === 'function') { | |
103 assertTrue(property_mirror.value().isFunction()); | |
104 } else { | |
105 assertEquals(minimum_content[p], property_mirror.value().value(), 'propert
y ' + p + ' has unexpected value'); | |
106 } | |
107 minimum_count++; | |
108 } | |
109 | |
110 // 'arguments' and might be exposed in the local and closure scope. Just | |
111 // ignore this. | |
112 var scope_size = scope.scopeObject().properties().length; | |
113 if (!scope.scopeObject().property('arguments').isUndefined()) { | |
114 scope_size--; | |
115 } | |
116 // Ditto for 'this'. | |
117 if (!scope.scopeObject().property('this').isUndefined()) { | |
118 scope_size--; | |
119 } | |
120 // Temporary variables introduced by the parser have not been materialized. | |
121 assertTrue(scope.scopeObject().property('').isUndefined()); | |
122 | |
123 if (scope_size < minimum_count) { | |
124 print('Names found in scope:'); | |
125 var names = scope.scopeObject().propertyNames(); | |
126 for (var i = 0; i < names.length; i++) { | |
127 print(names[i]); | |
128 } | |
129 } | |
130 assertTrue(scope_size >= minimum_count); | |
131 } | |
132 | |
133 | |
134 //////////////////////////////////////////////////////////////////////////////// | |
135 // Actual tests. | |
136 //////////////////////////////////////////////////////////////////////////////// | |
137 | |
138 | |
139 BeginTest(); | |
140 listener_delegate = function(exec_state) { | |
141 CheckScopeChain([debug.ScopeType.Module, | |
142 debug.ScopeType.Script, | |
143 debug.ScopeType.Global], exec_state); | |
144 CheckScopeContent( | |
145 {local_var: undefined, exported_var: undefined, imported_var: undefined}, | |
146 0, exec_state); | |
147 CheckScopeDoesNotHave( | |
148 ["doesnotexist", "local_let", "exported_let", "imported_let"], | |
149 0, exec_state); | |
150 }; | |
151 debugger; | |
152 EndTest(); | |
153 | |
154 let local_let = 1; | |
155 var local_var = 2; | |
156 export let exported_let = 3; | |
157 export var exported_var = 4; | |
158 import {exported_let as imported_let} from "modules-debug-scopes2.js"; | |
159 import {exported_var as imported_var} from "modules-debug-scopes2.js"; | |
160 | |
161 BeginTest(); | |
162 listener_delegate = function(exec_state) { | |
163 CheckScopeChain([debug.ScopeType.Module, | |
164 debug.ScopeType.Script, | |
165 debug.ScopeType.Global], exec_state); | |
166 CheckScopeContent( | |
167 {local_let: 1, local_var: 2, exported_let: 3, exported_var: 4, | |
168 imported_let: 3, imported_var: 4}, 0, exec_state); | |
169 }; | |
170 debugger; | |
171 EndTest(); | |
172 | |
173 local_let += 10; | |
174 local_var += 10; | |
175 exported_let += 10; | |
176 exported_var += 10; | |
177 | |
178 BeginTest(); | |
179 listener_delegate = function(exec_state) { | |
180 CheckScopeChain([debug.ScopeType.Module, | |
181 debug.ScopeType.Script, | |
182 debug.ScopeType.Global], exec_state); | |
183 CheckScopeContent( | |
184 {local_let: 11, local_var: 12, exported_let: 13, exported_var: 14, | |
185 imported_let: 13, imported_var: 14}, 0, exec_state); | |
186 }; | |
187 debugger; | |
188 EndTest(); | |
OLD | NEW |