OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 | 79 |
80 // Check that the scope chain contains the expected types of scopes. | 80 // Check that the scope chain contains the expected types of scopes. |
81 function CheckScopeChain(scopes, exec_state) { | 81 function CheckScopeChain(scopes, exec_state) { |
82 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 82 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
83 for (var i = 0; i < scopes.length; i++) { | 83 for (var i = 0; i < scopes.length; i++) { |
84 var scope = exec_state.frame().scope(i); | 84 var scope = exec_state.frame().scope(i); |
85 assertTrue(scope.isScope()); | 85 assertTrue(scope.isScope()); |
86 assertEquals(scopes[i], scope.scopeType()); | 86 assertEquals(scopes[i], scope.scopeType()); |
87 | 87 |
88 // Check the global object when hitting the global scope. | 88 // Check the global object when hitting the global scope. |
89 if (scopes[i] == debug.ScopeType.Global) { | 89 if (scopes[i] == debug.ScopeType.Global) { |
90 assertEquals(this, scope.scopeObject().value()); | 90 assertEquals(this, scope.scopeObject().value()); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 // Get the debug command processor. | 94 // Get the debug command processor. |
95 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | 95 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
96 | 96 |
97 // Send a scopes request and check the result. | 97 // Send a scopes request and check the result. |
98 var json; | 98 var json; |
99 request_json = '{"seq":0,"type":"request","command":"scopes"}' | 99 request_json = '{"seq":0,"type":"request","command":"scopes"}' |
100 var response_json = dcp.processDebugJSONRequest(request_json); | 100 var response_json = dcp.processDebugJSONRequest(request_json); |
101 var response = JSON.parse(response_json); | 101 var response = JSON.parse(response_json); |
102 assertEquals(scopes.length, response.body.scopes.length); | 102 assertEquals(scopes.length, response.body.scopes.length); |
103 for (var i = 0; i < scopes.length; i++) { | 103 for (var i = 0; i < scopes.length; i++) { |
104 assertEquals(i, response.body.scopes[i].index); | 104 assertEquals(i, response.body.scopes[i].index); |
105 assertEquals(scopes[i], response.body.scopes[i].type); | 105 assertEquals(scopes[i], response.body.scopes[i].type); |
106 if (scopes[i] == debug.ScopeType.Local || | 106 if (scopes[i] == debug.ScopeType.Local || |
(...skipping 19 matching lines...) Expand all Loading... |
126 for (var p in content) { | 126 for (var p in content) { |
127 var property_mirror = scope.scopeObject().property(p); | 127 var property_mirror = scope.scopeObject().property(p); |
128 assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in
scope'); | 128 assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in
scope'); |
129 if (typeof(content[p]) === 'function') { | 129 if (typeof(content[p]) === 'function') { |
130 assertTrue(property_mirror.value().isFunction()); | 130 assertTrue(property_mirror.value().isFunction()); |
131 } else { | 131 } else { |
132 assertEquals(content[p], property_mirror.value().value(), 'property ' + p
+ ' has unexpected value'); | 132 assertEquals(content[p], property_mirror.value().value(), 'property ' + p
+ ' has unexpected value'); |
133 } | 133 } |
134 count++; | 134 count++; |
135 } | 135 } |
136 | 136 |
137 // 'arguments' and might be exposed in the local and closure scope. Just | 137 // 'arguments' and might be exposed in the local and closure scope. Just |
138 // ignore this. | 138 // ignore this. |
139 var scope_size = scope.scopeObject().properties().length; | 139 var scope_size = scope.scopeObject().properties().length; |
140 if (!scope.scopeObject().property('arguments').isUndefined()) { | 140 if (!scope.scopeObject().property('arguments').isUndefined()) { |
141 scope_size--; | 141 scope_size--; |
142 } | 142 } |
143 // Also ignore synthetic variable from catch block. | 143 // Also ignore synthetic variable from catch block. |
144 if (!scope.scopeObject().property('.catch-var').isUndefined()) { | 144 if (!scope.scopeObject().property('.catch-var').isUndefined()) { |
145 scope_size--; | 145 scope_size--; |
146 } | 146 } |
147 | 147 |
148 if (count != scope_size) { | 148 if (count != scope_size) { |
149 print('Names found in scope:'); | 149 print('Names found in scope:'); |
150 var names = scope.scopeObject().propertyNames(); | 150 var names = scope.scopeObject().propertyNames(); |
151 for (var i = 0; i < names.length; i++) { | 151 for (var i = 0; i < names.length; i++) { |
152 print(names[i]); | 152 print(names[i]); |
153 } | 153 } |
154 } | 154 } |
155 assertEquals(count, scope_size); | 155 assertEquals(count, scope_size); |
156 | 156 |
157 // Get the debug command processor. | 157 // Get the debug command processor. |
158 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | 158 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
159 | 159 |
160 // Send a scope request for information on a single scope and check the | 160 // Send a scope request for information on a single scope and check the |
161 // result. | 161 // result. |
162 request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"numb
er":' | 162 request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"numb
er":' |
163 request_json += scope.scopeIndex(); | 163 request_json += scope.scopeIndex(); |
164 request_json += '}}' | 164 request_json += '}}' |
165 var response_json = dcp.processDebugJSONRequest(request_json); | 165 var response_json = dcp.processDebugJSONRequest(request_json); |
166 var response = JSON.parse(response_json); | 166 var response = JSON.parse(response_json); |
167 assertEquals(scope.scopeType(), response.body.type); | 167 assertEquals(scope.scopeType(), response.body.type); |
168 assertEquals(number, response.body.index); | 168 assertEquals(number, response.body.index); |
169 if (scope.scopeType() == debug.ScopeType.Local || | 169 if (scope.scopeType() == debug.ScopeType.Local || |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 eval('var i = 5'); | 615 eval('var i = 5'); |
616 eval('var j = 6'); | 616 eval('var j = 6'); |
617 function f(a, b) { | 617 function f(a, b) { |
618 var x = 9; | 618 var x = 9; |
619 var y = 10; | 619 var y = 10; |
620 eval('var i = 11'); | 620 eval('var i = 11'); |
621 eval('var j = 12'); | 621 eval('var j = 12'); |
622 with ({j:13}){ | 622 with ({j:13}){ |
623 return function() { | 623 return function() { |
624 var x = 14; | 624 var x = 14; |
625 with ({a:15}) { | 625 with ({a:15}) { |
626 with ({b:16}) { | 626 with ({b:16}) { |
627 debugger; | 627 debugger; |
628 some_global = a; | 628 some_global = a; |
629 return f; | 629 return f; |
630 } | 630 } |
631 } | 631 } |
632 } | 632 } |
633 } | 633 } |
634 } | 634 } |
635 return f(a, b); | 635 return f(a, b); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 debug.ScopeType.Local, | 700 debug.ScopeType.Local, |
701 debug.ScopeType.Global], exec_state); | 701 debug.ScopeType.Global], exec_state); |
702 CheckScopeContent({n:10}, 0, exec_state); | 702 CheckScopeContent({n:10}, 0, exec_state); |
703 CheckScopeContent({e:'Exception'}, 1, exec_state); | 703 CheckScopeContent({e:'Exception'}, 1, exec_state); |
704 } | 704 } |
705 catch_block_2() | 705 catch_block_2() |
706 EndTest(); | 706 EndTest(); |
707 | 707 |
708 | 708 |
709 BeginTest("Catch block 3"); | 709 BeginTest("Catch block 3"); |
710 function catch_block_1() { | 710 function catch_block_3() { |
711 // Do eval to dynamically declare a local variable so that the context's | 711 // Do eval to dynamically declare a local variable so that the context's |
712 // extension slot is initialized with JSContextExtensionObject. | 712 // extension slot is initialized with JSContextExtensionObject. |
713 eval("var y = 78;"); | 713 eval("var y = 78;"); |
714 try { | 714 try { |
715 throw 'Exception'; | 715 throw 'Exception'; |
716 } catch (e) { | 716 } catch (e) { |
717 debugger; | 717 debugger; |
718 } | 718 } |
719 }; | 719 }; |
720 | 720 |
721 | 721 |
722 listener_delegate = function(exec_state) { | 722 listener_delegate = function(exec_state) { |
723 CheckScopeChain([debug.ScopeType.Catch, | 723 CheckScopeChain([debug.ScopeType.Catch, |
724 debug.ScopeType.Local, | 724 debug.ScopeType.Local, |
725 debug.ScopeType.Global], exec_state); | 725 debug.ScopeType.Global], exec_state); |
726 CheckScopeContent({e:'Exception'}, 0, exec_state); | 726 CheckScopeContent({e:'Exception'}, 0, exec_state); |
727 CheckScopeContent({y:78}, 1, exec_state); | 727 CheckScopeContent({y:78}, 1, exec_state); |
728 } | 728 } |
729 catch_block_1() | 729 catch_block_3() |
730 EndTest(); | 730 EndTest(); |
731 | 731 |
732 | 732 |
733 BeginTest("Catch block 4"); | 733 BeginTest("Catch block 4"); |
734 function catch_block_2() { | 734 function catch_block_4() { |
735 // Do eval to dynamically declare a local variable so that the context's | 735 // Do eval to dynamically declare a local variable so that the context's |
736 // extension slot is initialized with JSContextExtensionObject. | 736 // extension slot is initialized with JSContextExtensionObject. |
737 eval("var y = 98;"); | 737 eval("var y = 98;"); |
738 try { | 738 try { |
739 throw 'Exception'; | 739 throw 'Exception'; |
740 } catch (e) { | 740 } catch (e) { |
741 with({n:10}) { | 741 with({n:10}) { |
742 debugger; | 742 debugger; |
743 } | 743 } |
744 } | 744 } |
745 }; | 745 }; |
746 | 746 |
747 listener_delegate = function(exec_state) { | 747 listener_delegate = function(exec_state) { |
748 CheckScopeChain([debug.ScopeType.With, | 748 CheckScopeChain([debug.ScopeType.With, |
749 debug.ScopeType.Catch, | 749 debug.ScopeType.Catch, |
750 debug.ScopeType.Local, | 750 debug.ScopeType.Local, |
751 debug.ScopeType.Global], exec_state); | 751 debug.ScopeType.Global], exec_state); |
752 CheckScopeContent({n:10}, 0, exec_state); | 752 CheckScopeContent({n:10}, 0, exec_state); |
753 CheckScopeContent({e:'Exception'}, 1, exec_state); | 753 CheckScopeContent({e:'Exception'}, 1, exec_state); |
754 CheckScopeContent({y:98}, 2, exec_state); | 754 CheckScopeContent({y:98}, 2, exec_state); |
755 } | 755 } |
756 catch_block_2() | 756 catch_block_4() |
757 EndTest(); | 757 EndTest(); |
758 | 758 |
759 | 759 |
760 assertEquals(begin_test_count, break_count, 'one or more tests did not enter the
debugger'); | 760 assertEquals(begin_test_count, break_count, 'one or more tests did not enter the
debugger'); |
761 assertEquals(begin_test_count, end_test_count, 'one or more tests did not have i
ts result checked'); | 761 assertEquals(begin_test_count, end_test_count, 'one or more tests did not have i
ts result checked'); |
OLD | NEW |