Browse Source

Additional changes and unit tests

Massimiliano Gentile 10 years ago
parent
commit
b7c87f1145
2 changed files with 86 additions and 6 deletions
  1. 81 0
      Jint.Tests/Runtime/EngineTests.cs
  2. 5 6
      Jint/Runtime/Debugger/DebugHandler.cs

+ 81 - 0
Jint.Tests/Runtime/EngineTests.cs

@@ -1351,6 +1351,87 @@ namespace Jint.Tests.Runtime
 
             engine.Break -= EngineStep;
 
+            Assert.Equal(1, countBreak);
+        }
+
+        [Fact]
+        public void ShouldNotStepInSameLevelStatementsWhenStepOver()
+        {
+            countBreak = 0;
+            stepMode = StepMode.Over;
+
+            var engine = new Engine(options => options.DebugMode());
+
+            engine.Step += EngineStep;
+
+            engine.Execute(@"function func() // first step - then stepping over
+                {
+                    ; // shall not step
+                    ; // not even here
+                }
+                func(); // shall not step                 
+                ; // shall not step ");
+
+            engine.Step -= EngineStep;
+
+            Assert.Equal(1, countBreak);
+        }
+
+        [Fact]
+        public void ShouldNotStepInIfRequiredToStepOver()
+        {
+            countBreak = 0;
+            
+            var engine = new Engine(options => options.DebugMode());
+
+            engine.Step += EngineStepOverWhenInsideFunction;
+
+            engine.Execute(@"function func() // first step
+                {
+                    ; // third step - now stepping over
+                    ; // it should not step here
+                }
+                func(); // second step                 
+                ; // fourth step ");
+
+            engine.Step -= EngineStepOverWhenInsideFunction;
+
+            Assert.Equal(4, countBreak);
+        }
+
+        private StepMode EngineStepOverWhenInsideFunction(object sender, DebugInformation debugInfo)
+        {
+            Assert.NotNull(sender);
+            Assert.IsType(typeof(Engine), sender);
+            Assert.NotNull(debugInfo);
+
+            countBreak++;
+            if (debugInfo.CallStack.Count > 0)
+                return StepMode.Over;
+            
+            return StepMode.Into;
+        }
+
+        [Fact]
+        public void ShouldBreakWhenStatementIsMultiLine()
+        {
+            countBreak = 0;
+            stepMode = StepMode.None;
+
+            var engine = new Engine(options => options.DebugMode());
+            engine.BreakPoints.Add(new BreakPoint(4, 33));
+            engine.Break += EngineStep;
+
+            engine.Execute(@"var global = true;
+                            function func1()
+                            {
+                                var local = 
+                                    false;
+                            }
+                            func1();");
+
+            engine.Break -= EngineStep;
+
             Assert.Equal(1, countBreak);
         }
     }

+ 5 - 6
Jint/Runtime/Debugger/DebugHandler.cs

@@ -28,7 +28,7 @@ namespace Jint.Runtime.Debugger
             {
                 _debugCallStack.Pop();
             }
-            if (_stepMode == StepMode.Over && _debugCallStack.Count <= _callBackStepOverDepth)
+            if (_stepMode == StepMode.Over && _debugCallStack.Count < _callBackStepOverDepth)
             {
                 _callBackStepOverDepth = _debugCallStack.Count;
                 _stepMode = StepMode.Into;
@@ -69,8 +69,6 @@ namespace Jint.Runtime.Debugger
             {
                 return;
             }
-
-            
             
             BreakPoint breakpoint = _engine.BreakPoints.FirstOrDefault(breakPoint => BpTest(statement, breakPoint));
             bool breakpointFound = false;
@@ -107,15 +105,16 @@ namespace Jint.Runtime.Debugger
             bool afterStart, beforeEnd;
 
             afterStart = (breakpoint.Line == statement.Location.Start.Line &&
-                          breakpoint.Char >= statement.Location.Start.Column);
+                             breakpoint.Char >= statement.Location.Start.Column);
 
             if (!afterStart)
             {
                 return false;
             }
 
-            beforeEnd = (breakpoint.Line == statement.Location.End.Line &&
-                         breakpoint.Char <= statement.Location.End.Column);
+            beforeEnd = breakpoint.Line < statement.Location.End.Line
+                        || (breakpoint.Line == statement.Location.End.Line &&
+                            breakpoint.Char <= statement.Location.End.Column);
 
             if (!beforeEnd)
             {