Răsfoiți Sursa

Merge pull request #199 from mgentile/debug_stepOverSupport

Debug - Support for Step Over
Sébastien Ros 10 ani în urmă
părinte
comite
fa2838f18f

+ 55 - 10
Jint.Tests/Runtime/EngineTests.cs

@@ -1356,16 +1356,16 @@ namespace Jint.Tests.Runtime
         }
 
         [Fact]
-        public void ShouldNotStepInSameLevelStatementsWhenStepOver()
+        public void ShouldNotStepInSameLevelStatementsWhenStepOut()
         {
             countBreak = 0;
-            stepMode = StepMode.Over;
+            stepMode = StepMode.Out;
 
             var engine = new Engine(options => options.DebugMode());
 
             engine.Step += EngineStep;
 
-            engine.Execute(@"function func() // first step - then stepping over
+            engine.Execute(@"function func() // first step - then stepping out
                 {
                     ; // shall not step
                     ; // not even here
@@ -1379,28 +1379,28 @@ namespace Jint.Tests.Runtime
         }
 
         [Fact]
-        public void ShouldNotStepInIfRequiredToStepOver()
+        public void ShouldNotStepInIfRequiredToStepOut()
         {
             countBreak = 0;
             
             var engine = new Engine(options => options.DebugMode());
 
-            engine.Step += EngineStepOverWhenInsideFunction;
+            engine.Step += EngineStepOutWhenInsideFunction;
 
             engine.Execute(@"function func() // first step
                 {
-                    ; // third step - now stepping over
+                    ; // third step - now stepping out
                     ; // it should not step here
                 }
                 func(); // second step                 
                 ; // fourth step ");
 
-            engine.Step -= EngineStepOverWhenInsideFunction;
+            engine.Step -= EngineStepOutWhenInsideFunction;
 
             Assert.Equal(4, countBreak);
         }
 
-        private StepMode EngineStepOverWhenInsideFunction(object sender, DebugInformation debugInfo)
+        private StepMode EngineStepOutWhenInsideFunction(object sender, DebugInformation debugInfo)
         {
             Assert.NotNull(sender);
             Assert.IsType(typeof(Engine), sender);
@@ -1408,7 +1408,7 @@ namespace Jint.Tests.Runtime
 
             countBreak++;
             if (debugInfo.CallStack.Count > 0)
-                return StepMode.Over;
+                return StepMode.Out;
             
             return StepMode.Into;
         }
@@ -1434,6 +1434,51 @@ namespace Jint.Tests.Runtime
             engine.Break -= EngineStep;
 
             Assert.Equal(1, countBreak);
-        }
+        }
+
+        [Fact]
+        public void ShouldNotStepInsideIfRequiredToStepOver()
+        {
+            countBreak = 0;
+            
+            var engine = new Engine(options => options.DebugMode());
+
+            stepMode = StepMode.Over;
+            engine.Step += EngineStep;
+
+            engine.Execute(@"function func() // first step
+                {
+                    ; // third step - it shall not step here
+                    ; // it shall not step here
+                }
+                func(); // second step                 
+                ; // third step ");
+
+            engine.Step -= EngineStep;
+
+            Assert.Equal(3, countBreak);
+        }
+
+        [Fact]
+        public void ShouldStepAllStatementsWithoutInvocationsIfStepOver()
+        {
+            countBreak = 0;
+
+            var engine = new Engine(options => options.DebugMode());
+
+            stepMode = StepMode.Over;
+            engine.Step += EngineStep;
+
+            engine.Execute(@"var step1 = 1; // first step
+                var step2 = 2; // second step                 
+                if (step1 !== step2) // third step
+                { // fourth step
+                    ; // fifth step
+                }");
+
+            engine.Step -= EngineStep;
+
+            Assert.Equal(5, countBreak);
+        }
     }
 }

+ 19 - 2
Jint/Runtime/Debugger/DebugHandler.cs

@@ -28,7 +28,12 @@ namespace Jint.Runtime.Debugger
             {
                 _debugCallStack.Pop();
             }
-            if (_stepMode == StepMode.Over && _debugCallStack.Count < _callBackStepOverDepth)
+            if (_stepMode == StepMode.Out && _debugCallStack.Count < _callBackStepOverDepth)
+            {
+                _callBackStepOverDepth = _debugCallStack.Count;
+                _stepMode = StepMode.Into;
+            }
+            else if (_stepMode == StepMode.Over && _debugCallStack.Count == _callBackStepOverDepth)
             {
                 _callBackStepOverDepth = _debugCallStack.Count;
                 _stepMode = StepMode.Into;
@@ -94,10 +99,22 @@ namespace Jint.Runtime.Debugger
                 }
             }
 
-            if (old == StepMode.Into && _stepMode == StepMode.Over)
+            if (old == StepMode.Into && _stepMode == StepMode.Out)
             {
                 _callBackStepOverDepth = _debugCallStack.Count;
             }
+            else if (old == StepMode.Into && _stepMode == StepMode.Over)
+            {
+                var expressionStatement = statement as ExpressionStatement;
+                if (expressionStatement != null && expressionStatement.Expression is CallExpression)
+                {
+                    _callBackStepOverDepth = _debugCallStack.Count;
+                }
+                else
+                {
+                    _stepMode = StepMode.Into;
+                }
+            }
         }
 
         private bool BpTest(Statement statement, BreakPoint breakpoint)

+ 2 - 1
Jint/Runtime/Debugger/StepMode.cs

@@ -4,6 +4,7 @@
     {
         None,
         Over,
-        Into
+        Into,
+        Out
     }
 }