Index: test/mjsunit/debug-scopes.js |
diff --git a/test/mjsunit/debug-scopes.js b/test/mjsunit/debug-scopes.js |
index 8cde95194a9057b4549f54939452fcca504bf00c..6ddd6a223ccef9ed81b046350860a7a0c4906ddf 100644 |
--- a/test/mjsunit/debug-scopes.js |
+++ b/test/mjsunit/debug-scopes.js |
@@ -223,6 +223,21 @@ function CheckScopeContent(content, number, exec_state) { |
assertTrue(found, "Scope object " + response.body.object.ref + " not found"); |
} |
+// Check that the scopes have positions as expected. |
+function CheckScopeChainPositions(positions, exec_state) { |
+ var all_scopes = exec_state.frame().allScopes(); |
+ assertEquals(positions.length, all_scopes.length, "FrameMirror.allScopes length"); |
+ for (var i = 0; i < positions.length; i++) { |
+ var scope = exec_state.frame().scope(i); |
+ assertTrue(scope.isScope()); |
+ var position = positions[i]; |
+ if (!position) |
+ continue; |
+ |
+ assertEquals(position.start, scope.details().startPosition()) |
+ assertEquals(position.end, scope.details().endPosition()) |
+ } |
+} |
// Simple empty local scope. |
BeginTest("Local 1"); |
@@ -1109,6 +1124,70 @@ listener_delegate = function(exec_state) { |
EndTest(); |
+BeginTest("Scope positions"); |
+var code1 = "function f() { \n" + |
+ " var a = 1; \n" + |
+ " function b() { \n" + |
+ " debugger; \n" + |
+ " return a + 1; \n" + |
+ " } \n" + |
+ " b(); \n" + |
+ "} \n" + |
+ "f(); \n"; |
+ |
+listener_delegate = function(exec_state) { |
+ CheckScopeChainPositions([{start: 58, end: 118}, {start: 10, end: 162}, {}, {}], exec_state); |
+} |
+eval(code1); |
+EndTest(); |
+ |
+ |
+function catch_block_2() { |
+ try { |
+ throw 'Exception'; |
+ } catch (e) { |
+ with({n:10}) { |
+ debugger; |
+ } |
+ } |
+}; |
+ |
+BeginTest("Scope positions in catch and 'with' statement"); |
+var code2 = "function catch_block() { \n" + |
+ " try { \n" + |
+ " throw 'Exception'; \n" + |
+ " } catch (e) { \n" + |
+ " with({n : 10}) { \n" + |
+ " debugger; \n" + |
+ " } \n" + |
+ " } \n" + |
+ "} \n" + |
+ "catch_block(); \n"; |
+ |
+listener_delegate = function(exec_state) { |
+ CheckScopeChainPositions([{start: 131, end: 173}, {start: 94, end: 199}, {start: 20, end: 225}, {}, {}], exec_state); |
+} |
+eval(code2); |
+EndTest(); |
+ |
+BeginTest("Scope positions in for statement"); |
+var code3 = "function for_statement() { \n" + |
+ " for (let i = 0; i < 1; i++) { \n" + |
+ " debugger; \n" + |
+ " } \n" + |
+ "} \n" + |
+ "for_statement(); \n"; |
+ |
+listener_delegate = function(exec_state) { |
+ CheckScopeChain([debug.ScopeType.Block, |
+ debug.ScopeType.Block, |
+ debug.ScopeType.Local, |
+ debug.ScopeType.Script, |
+ debug.ScopeType.Global], exec_state); |
+ CheckScopeChainPositions([{start: 52, end: 111}, {start: 42, end: 111}, {start: 22, end: 145}, {}, {}], exec_state); |
+} |
+eval(code3); |
+EndTest(); |
assertEquals(begin_test_count, break_count, |
'one or more tests did not enter the debugger'); |