| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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 // MODULE | 5 // MODULE |
| 6 // Flags: --expose-debug-as debug | |
| 7 | 6 |
| 8 | 7 |
| 9 var Debug = debug.Debug; | 8 var Debug = debug.Debug; |
| 10 | 9 |
| 11 var test_name; | 10 var test_name; |
| 12 var listener_delegate; | 11 var listener_delegate; |
| 13 var listener_called; | 12 var listener_called; |
| 14 var exception; | 13 var exception; |
| 15 var begin_test_count = 0; | 14 var begin_test_count = 0; |
| 16 var end_test_count = 0; | 15 var end_test_count = 0; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 44 assertNull(exception, test_name + " / " + exception); | 43 assertNull(exception, test_name + " / " + exception); |
| 45 end_test_count++; | 44 end_test_count++; |
| 46 } | 45 } |
| 47 | 46 |
| 48 | 47 |
| 49 // Check that two scope are the same. | 48 // Check that two scope are the same. |
| 50 function assertScopeMirrorEquals(scope1, scope2) { | 49 function assertScopeMirrorEquals(scope1, scope2) { |
| 51 assertEquals(scope1.scopeType(), scope2.scopeType()); | 50 assertEquals(scope1.scopeType(), scope2.scopeType()); |
| 52 assertEquals(scope1.frameIndex(), scope2.frameIndex()); | 51 assertEquals(scope1.frameIndex(), scope2.frameIndex()); |
| 53 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); | 52 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); |
| 54 assertPropertiesEqual(scope1.scopeObject().value(), scope2.scopeObject().value
()); | 53 assertPropertiesEqual(scope1.scopeObject().value(), |
| 54 scope2.scopeObject().value()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 function CheckFastAllScopes(scopes, exec_state) | 57 function CheckFastAllScopes(scopes, exec_state) |
| 58 { | 58 { |
| 59 var fast_all_scopes = exec_state.frame().allScopes(true); | 59 var fast_all_scopes = exec_state.frame().allScopes(true); |
| 60 var length = fast_all_scopes.length; | 60 var length = fast_all_scopes.length; |
| 61 assertTrue(scopes.length >= length); | 61 assertTrue(scopes.length >= length); |
| 62 for (var i = 0; i < scopes.length && i < length; i++) { | 62 for (var i = 0; i < scopes.length && i < length; i++) { |
| 63 var scope = fast_all_scopes[length - i - 1]; | 63 var scope = fast_all_scopes[length - i - 1]; |
| 64 assertTrue(scope.isScope()); | |
| 65 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); | 64 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); |
| 66 } | 65 } |
| 67 } | 66 } |
| 68 | 67 |
| 69 | 68 |
| 70 // Check that the scope chain contains the expected types of scopes. | 69 // Check that the scope chain contains the expected types of scopes. |
| 71 function CheckScopeChain(scopes, exec_state) { | 70 function CheckScopeChain(scopes, exec_state) { |
| 72 var all_scopes = exec_state.frame().allScopes(); | 71 var all_scopes = exec_state.frame().allScopes(); |
| 73 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 72 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
| 74 assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length")
; | 73 assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length")
; |
| 75 for (var i = 0; i < scopes.length; i++) { | 74 for (var i = 0; i < scopes.length; i++) { |
| 76 var scope = exec_state.frame().scope(i); | 75 var scope = exec_state.frame().scope(i); |
| 77 assertTrue(scope.isScope()); | |
| 78 assertEquals(scopes[i], scope.scopeType()); | 76 assertEquals(scopes[i], scope.scopeType()); |
| 79 assertScopeMirrorEquals(all_scopes[i], scope); | 77 assertScopeMirrorEquals(all_scopes[i], scope); |
| 80 } | 78 } |
| 81 CheckFastAllScopes(scopes, exec_state); | 79 CheckFastAllScopes(scopes, exec_state); |
| 82 } | 80 } |
| 83 | 81 |
| 84 | 82 |
| 85 function CheckScopeDoesNotHave(properties, number, exec_state) { | 83 function CheckScopeDoesNotHave(properties, number, exec_state) { |
| 86 var scope = exec_state.frame().scope(number); | 84 var scope = exec_state.frame().scope(number); |
| 87 for (var p of properties) { | 85 for (var p of properties) { |
| 88 var property_mirror = scope.scopeObject().property(p); | 86 var property_mirror = scope.scopeObject().property(p); |
| 89 assertTrue(property_mirror.isUndefined(), 'property ' + p + ' found in scope
'); | 87 assertTrue(property_mirror.isUndefined(), |
| 88 'property ' + p + ' found in scope'); |
| 90 } | 89 } |
| 91 } | 90 } |
| 92 | 91 |
| 93 | 92 |
| 94 // Check that the scope contains at least minimum_content. For functions just | 93 // Check that the scope contains at least minimum_content. For functions just |
| 95 // check that there is a function. | 94 // check that there is a function. |
| 96 function CheckScopeContent(minimum_content, number, exec_state) { | 95 function CheckScopeContent(minimum_content, number, exec_state) { |
| 97 var scope = exec_state.frame().scope(number); | 96 var scope = exec_state.frame().scope(number); |
| 98 var minimum_count = 0; | 97 var minimum_count = 0; |
| 99 for (var p in minimum_content) { | 98 for (var p in minimum_content) { |
| 100 var property_mirror = scope.scopeObject().property(p); | 99 var property_mirror = scope.scopeObject().property(p); |
| 101 assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in
scope'); | 100 assertFalse(property_mirror.isUndefined(), |
| 102 if (typeof(minimum_content[p]) === 'function') { | 101 'property ' + p + ' not found in scope'); |
| 103 assertTrue(property_mirror.value().isFunction()); | 102 assertEquals(minimum_content[p], property_mirror.value().value(), |
| 104 } else { | 103 'property ' + p + ' has unexpected value'); |
| 105 assertEquals(minimum_content[p], property_mirror.value().value(), 'propert
y ' + p + ' has unexpected value'); | |
| 106 } | |
| 107 minimum_count++; | 104 minimum_count++; |
| 108 } | 105 } |
| 109 | 106 |
| 110 // 'arguments' and might be exposed in the local and closure scope. Just | 107 // 'arguments' and might be exposed in the local and closure scope. Just |
| 111 // ignore this. | 108 // ignore this. |
| 112 var scope_size = scope.scopeObject().properties().length; | 109 var scope_size = scope.scopeObject().properties().length; |
| 113 if (!scope.scopeObject().property('arguments').isUndefined()) { | 110 if (!scope.scopeObject().property('arguments').isUndefined()) { |
| 114 scope_size--; | 111 scope_size--; |
| 115 } | 112 } |
| 116 // Ditto for 'this'. | 113 // Ditto for 'this'. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 listener_delegate = function(exec_state) { | 176 listener_delegate = function(exec_state) { |
| 180 CheckScopeChain([debug.ScopeType.Module, | 177 CheckScopeChain([debug.ScopeType.Module, |
| 181 debug.ScopeType.Script, | 178 debug.ScopeType.Script, |
| 182 debug.ScopeType.Global], exec_state); | 179 debug.ScopeType.Global], exec_state); |
| 183 CheckScopeContent( | 180 CheckScopeContent( |
| 184 {local_let: 11, local_var: 12, exported_let: 13, exported_var: 14, | 181 {local_let: 11, local_var: 12, exported_let: 13, exported_var: 14, |
| 185 imported_let: 13, imported_var: 14}, 0, exec_state); | 182 imported_let: 13, imported_var: 14}, 0, exec_state); |
| 186 }; | 183 }; |
| 187 debugger; | 184 debugger; |
| 188 EndTest(); | 185 EndTest(); |
| OLD | NEW |