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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-debug-as debug | |
29 // The functions used for testing backtraces. They are at the top to make the | 28 // The functions used for testing backtraces. They are at the top to make the |
30 // testing of source line/column easier. | 29 // testing of source line/column easier. |
31 | 30 |
32 | 31 |
33 // Get the Debug object exposed from the debug context global object. | 32 // Get the Debug object exposed from the debug context global object. |
34 Debug = debug.Debug; | 33 Debug = debug.Debug; |
35 | 34 |
36 var test_name; | 35 var test_name; |
37 var listener_delegate; | 36 var listener_delegate; |
38 var listener_called; | 37 var listener_called; |
39 var exception; | 38 var exception; |
40 var begin_test_count = 0; | 39 var begin_test_count = 0; |
41 var end_test_count = 0; | 40 var end_test_count = 0; |
42 var break_count = 0; | 41 var break_count = 0; |
| 42 var global_marker = 7; |
43 | 43 |
44 | 44 |
45 // Debug event listener which delegates. | 45 // Debug event listener which delegates. |
46 function listener(event, exec_state, event_data, data) { | 46 function listener(event, exec_state, event_data, data) { |
47 try { | 47 try { |
48 if (event == Debug.DebugEvent.Break) { | 48 if (event == Debug.DebugEvent.Break) { |
49 break_count++; | 49 break_count++; |
50 listener_called = true; | 50 listener_called = true; |
51 listener_delegate(exec_state); | 51 listener_delegate(exec_state); |
52 } | 52 } |
(...skipping 28 matching lines...) Expand all Loading... |
81 // Check that the scope chain contains the expected types of scopes. | 81 // Check that the scope chain contains the expected types of scopes. |
82 function CheckScopeChain(scopes, exec_state) { | 82 function CheckScopeChain(scopes, exec_state) { |
83 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 83 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
84 for (var i = 0; i < scopes.length; i++) { | 84 for (var i = 0; i < scopes.length; i++) { |
85 var scope = exec_state.frame().scope(i); | 85 var scope = exec_state.frame().scope(i); |
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 assertEquals(scope.scopeObject().value().global_marker, global_marker); |
92 // so just check the properties directly. | |
93 assertPropertiesEqual(this, scope.scopeObject().value()); | |
94 } | 92 } |
95 } | 93 } |
96 } | 94 } |
97 | 95 |
98 // Check that the content of the scope is as expected. For functions just check | 96 // Check that the content of the scope is as expected. For functions just check |
99 // that there is a function. | 97 // that there is a function. |
100 function CheckScopeContent(content, number, exec_state) { | 98 function CheckScopeContent(content, number, exec_state) { |
101 var scope = exec_state.frame().scope(number); | 99 var scope = exec_state.frame().scope(number); |
102 var count = 0; | 100 var count = 0; |
103 for (var p in content) { | 101 for (var p in content) { |
104 var property_mirror = scope.scopeObject().property(p); | 102 var property_mirror = scope.scopeObject().property(p); |
105 if (property_mirror.isUndefined()) { | 103 if (property_mirror.isUndefined()) { |
106 print('property ' + p + ' not found in scope'); | 104 print('property ' + p + ' not found in scope'); |
107 } | 105 } |
108 assertFalse(property_mirror.isUndefined(), | 106 assertFalse(property_mirror.isUndefined(), |
109 'property ' + p + ' not found in scope'); | 107 'property ' + p + ' not found in scope'); |
110 if (typeof(content[p]) === 'function') { | 108 assertEquals(content[p], property_mirror.value().value(), |
111 assertTrue(property_mirror.value().isFunction()); | 109 'property ' + p + ' has unexpected value'); |
112 } else { | |
113 assertEquals(content[p], property_mirror.value().value(), | |
114 'property ' + p + ' has unexpected value'); | |
115 } | |
116 count++; | 110 count++; |
117 } | 111 } |
118 | 112 |
119 // 'arguments' and might be exposed in the local and closure scope. Just | 113 // 'arguments' and might be exposed in the local and closure scope. Just |
120 // ignore this. | 114 // ignore this. |
121 var scope_size = scope.scopeObject().properties().length; | 115 var scope_size = scope.scopeObject().properties().length; |
122 if (!scope.scopeObject().property('arguments').isUndefined()) { | 116 if (!scope.scopeObject().property('arguments').isUndefined()) { |
123 scope_size--; | 117 scope_size--; |
124 } | 118 } |
125 // Skip property with empty name. | 119 // Skip property with empty name. |
126 if (!scope.scopeObject().property('').isUndefined()) { | 120 if (!scope.scopeObject().property('').isUndefined()) { |
127 scope_size--; | 121 scope_size--; |
128 } | 122 } |
129 | 123 |
130 if (count != scope_size) { | 124 if (scope_size < count) { |
131 print('Names found in scope:'); | 125 print('Names found in scope:'); |
132 var names = scope.scopeObject().propertyNames(); | 126 var names = scope.scopeObject().propertyNames(); |
133 for (var i = 0; i < names.length; i++) { | 127 for (var i = 0; i < names.length; i++) { |
134 print(names[i]); | 128 print(names[i]); |
135 } | 129 } |
136 } | 130 } |
137 assertEquals(count, scope_size); | 131 assertTrue(scope_size >= count); |
138 } | 132 } |
139 | 133 |
140 | 134 |
141 // Simple closure formed by returning an inner function referering to an outer | 135 // Simple closure formed by returning an inner function referering to an outer |
142 // block local variable and an outer function's parameter. Due to VM | 136 // block local variable and an outer function's parameter. Due to VM |
143 // optimizations parts of the actual closure is missing from the debugger | 137 // optimizations parts of the actual closure is missing from the debugger |
144 // information. | 138 // information. |
145 BeginTest("Closure 1"); | 139 BeginTest("Closure 1"); |
146 | 140 |
147 function closure_1(a) { | 141 function closure_1(a) { |
(...skipping 13 matching lines...) Expand all Loading... |
161 CheckScopeChain([debug.ScopeType.Local, | 155 CheckScopeChain([debug.ScopeType.Local, |
162 debug.ScopeType.Block, | 156 debug.ScopeType.Block, |
163 debug.ScopeType.Closure, | 157 debug.ScopeType.Closure, |
164 debug.ScopeType.Global], exec_state); | 158 debug.ScopeType.Global], exec_state); |
165 CheckScopeContent({}, 0, exec_state); | 159 CheckScopeContent({}, 0, exec_state); |
166 CheckScopeContent({z:4}, 1, exec_state); | 160 CheckScopeContent({z:4}, 1, exec_state); |
167 CheckScopeContent({a:1,x:2,y:3}, 2, exec_state); | 161 CheckScopeContent({a:1,x:2,y:3}, 2, exec_state); |
168 }; | 162 }; |
169 closure_1(1)(); | 163 closure_1(1)(); |
170 EndTest(); | 164 EndTest(); |
OLD | NEW |