Debugger: show local scope before with for functions created inside with block
authoryurys@chromium.org <yurys@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 6 Apr 2011 17:54:39 +0000 (17:54 +0000)
committeryurys@chromium.org <yurys@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 6 Apr 2011 17:54:39 +0000 (17:54 +0000)
Review URL: http://codereview.chromium.org/6804015

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7518 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/runtime.cc
test/mjsunit/debug-scopes.js

index 2a58e76c9a9e905f4e7ed0dd87c1de321654db42..a1d70767881c1e77f6cf71108570d2f3e5640473 100644 (file)
@@ -9820,6 +9820,10 @@ class ScopeIterator {
       at_local_ = index < 0;
     } else if (context_->is_function_context()) {
       at_local_ = true;
+    } else if (context_->closure() != *function_) {
+      // The context_ is a with block from the outer function.
+      ASSERT(context_->has_extension());
+      at_local_ = true;
     }
   }
 
index 37cefd1a93e56e7bf79746014b79ebb6c326099b..674f2da0f93e00459283aeb04a270d47e99bc040 100644 (file)
@@ -144,6 +144,10 @@ function CheckScopeContent(content, number, exec_state) {
   if (!scope.scopeObject().property('.catch-var').isUndefined()) {
     scope_size--;
   }
+  // Skip property with empty name.
+  if (!scope.scopeObject().property('').isUndefined()) {
+    scope_size--;
+  }
 
   if (count != scope_size) {
     print('Names found in scope:');
@@ -607,6 +611,43 @@ closure_7(1, 2)()
 EndTest();
 
 
+// Closure that may be optimized out.
+BeginTest("Closure 8");
+function closure_8() {
+  (function inner(x) {
+    debugger;
+  })(2);
+}
+
+listener_delegate = function(exec_state) {
+  CheckScopeChain([debug.ScopeType.Local,
+                   debug.ScopeType.Global], exec_state);
+  CheckScopeContent({x: 2}, 0, exec_state);
+}
+closure_8();
+EndTest();
+
+
+BeginTest("Closure 9");
+function closure_9() {
+  eval("var y = 1;");
+  eval("var z = 1;");
+  (function inner(x) {
+    y++; 
+    z++;
+    debugger;
+  })(2);
+}
+
+listener_delegate = function(exec_state) {
+  CheckScopeChain([debug.ScopeType.Local,
+                   debug.ScopeType.Closure,
+                   debug.ScopeType.Global], exec_state);
+}
+closure_9();
+EndTest();
+
+
 // Test a mixture of scopes.
 BeginTest("The full monty");
 function the_full_monty(a, b) {
@@ -653,6 +694,81 @@ listener_delegate = function(exec_state) {
 the_full_monty(1, 2)()
 EndTest();
 
+
+BeginTest("Closure inside With 1");
+function closure_in_with_1() {
+  with({x:1}) {
+    (function inner(x) {
+      debugger;
+    })(2);
+  }
+}
+
+listener_delegate = function(exec_state) {
+  CheckScopeChain([debug.ScopeType.Local,
+                   debug.ScopeType.With,
+                   debug.ScopeType.Closure,
+                   debug.ScopeType.Global], exec_state);
+  CheckScopeContent({x: 2}, 0, exec_state);
+}
+closure_in_with_1();
+EndTest();
+
+
+BeginTest("Closure inside With 2");
+function closure_in_with_2() {
+  with({x:1}) {
+    (function inner(x) {
+      with({x:3}) {
+        debugger;
+      }
+    })(2);
+  }
+}
+
+listener_delegate = function(exec_state) {
+  CheckScopeChain([debug.ScopeType.With,
+                   debug.ScopeType.Local,
+                   debug.ScopeType.With,
+                   debug.ScopeType.Closure,
+                   debug.ScopeType.Global], exec_state);
+  CheckScopeContent({x: 3}, 0, exec_state);
+  CheckScopeContent({x: 2}, 1, exec_state);
+  CheckScopeContent({x: 1}, 2, exec_state);
+}
+closure_in_with_2();
+EndTest();
+
+
+BeginTest("Closure inside With 3");
+function createClosure(a) {
+   var b = a + 1;
+   return function closure() {
+     var c = b;
+     (function inner(x) {
+       with({x:c}) {
+         debugger;
+       }
+     })(2);
+   }
+}
+
+function closure_in_with_3() {
+  var f = createClosure(0);
+  f();
+}
+
+listener_delegate = function(exec_state) {
+  CheckScopeChain([debug.ScopeType.With,
+                   debug.ScopeType.Local,
+                   debug.ScopeType.Closure,
+                   debug.ScopeType.Closure,
+                   debug.ScopeType.Global], exec_state);
+}
+closure_in_with_3();
+EndTest();
+
+
 // Test global scope.
 BeginTest("Global");
 listener_delegate = function(exec_state) {