Browse Source

Have single recursion related excecption instead of two of them

auz34 11 years ago
parent
commit
e6c3234074

+ 6 - 6
Jint.Tests/Runtime/EngineTests.cs

@@ -615,7 +615,7 @@ namespace Jint.Tests.Runtime
 
 
 
 
         [Fact]
         [Fact]
-        public void ShouldDiscardRecursion()
+        public void CanDiscardRecursion()
         {
         {
             var script = @"var factorial = function(n) {
             var script = @"var factorial = function(n) {
                 if (n>1) {
                 if (n>1) {
@@ -626,7 +626,7 @@ namespace Jint.Tests.Runtime
             var result = factorial(500);
             var result = factorial(500);
             ";
             ";
 
 
-            Assert.Throws<RecursionDiscardedException>(
+            Assert.Throws<RecursionDepthOverflowException>(
                 () => new Engine(cfg => cfg.MaxRecursionDepth(0)).Execute(script)
                 () => new Engine(cfg => cfg.MaxRecursionDepth(0)).Execute(script)
             );
             );
         }
         }
@@ -645,7 +645,7 @@ namespace Jint.Tests.Runtime
             });
             });
             ";
             ";
 
 
-            Assert.Throws<RecursionDiscardedException>(
+            Assert.Throws<RecursionDepthOverflowException>(
                 () => new Engine(cfg => cfg.MaxRecursionDepth(0)).Execute(script)
                 () => new Engine(cfg => cfg.MaxRecursionDepth(0)).Execute(script)
             );
             );
         }
         }
@@ -678,7 +678,7 @@ namespace Jint.Tests.Runtime
             funcRoot();
             funcRoot();
             ";
             ";
 
 
-            Assert.Throws<RecursionDiscardedException>(
+            Assert.Throws<RecursionDepthOverflowException>(
                 () => new Engine(cfg => cfg.MaxRecursionDepth(0)).Execute(script)
                 () => new Engine(cfg => cfg.MaxRecursionDepth(0)).Execute(script)
             );
             );
         }
         }
@@ -711,13 +711,13 @@ namespace Jint.Tests.Runtime
             funcRoot();
             funcRoot();
             ";
             ";
 
 
-            RecursionDiscardedException exception = null;
+            RecursionDepthOverflowException exception = null;
 
 
             try
             try
             {
             {
                 new Engine(cfg => cfg.MaxRecursionDepth(0)).Execute(script);
                 new Engine(cfg => cfg.MaxRecursionDepth(0)).Execute(script);
             }
             }
-            catch (RecursionDiscardedException ex)
+            catch (RecursionDepthOverflowException ex)
             {
             {
                 exception = ex;
                 exception = ex;
             }
             }

+ 0 - 1
Jint/Jint.csproj

@@ -190,7 +190,6 @@
     <Compile Include="Runtime\Interop\TypeReferencePrototype.cs" />
     <Compile Include="Runtime\Interop\TypeReferencePrototype.cs" />
     <Compile Include="Runtime\JavaScriptException.cs" />
     <Compile Include="Runtime\JavaScriptException.cs" />
     <Compile Include="Runtime\RecursionDepthOverflowException.cs" />
     <Compile Include="Runtime\RecursionDepthOverflowException.cs" />
-    <Compile Include="Runtime\RecursionDiscardedException.cs" />
     <Compile Include="Runtime\References\Reference.cs" />
     <Compile Include="Runtime\References\Reference.cs" />
     <Compile Include="Runtime\StatementInterpreter.cs" />
     <Compile Include="Runtime\StatementInterpreter.cs" />
     <Compile Include="Runtime\StatementsCountOverflowException.cs" />
     <Compile Include="Runtime\StatementsCountOverflowException.cs" />

+ 0 - 5
Jint/Runtime/ExpressionIntepreter.cs

@@ -808,11 +808,6 @@ namespace Jint.Runtime
                 if (recursionDepth > _engine.Options.GetMaxRecursionDepth())
                 if (recursionDepth > _engine.Options.GetMaxRecursionDepth())
                 {
                 {
                     _engine.CallStack.Pop();
                     _engine.CallStack.Pop();
-                    if (recursionDepth == 1)
-                    {
-                        throw new RecursionDiscardedException(_engine.CallStack, stackItem.ToString());
-                    }
-                    
                     throw new RecursionDepthOverflowException(_engine.CallStack, stackItem.ToString());
                     throw new RecursionDepthOverflowException(_engine.CallStack, stackItem.ToString());
                 }
                 }
             }
             }

+ 0 - 25
Jint/Runtime/RecursionDiscardedException.cs

@@ -1,25 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Jint.Native;
-using Jint.Parser.Ast;
-
-namespace Jint.Runtime
-{
-    using Jint.Runtime.CallStack;
-
-    public class RecursionDiscardedException : Exception 
-    {
-        public string CallChain { get; private set; }
-
-        public string CallExpressionReference { get; private set; }
-
-        public RecursionDiscardedException(JintCallStack currentStack, string currentExpressionReference)
-            : base("The recursion is forbidden by script host.")
-        {
-            CallExpressionReference = currentExpressionReference;
-
-            CallChain = currentStack.ToString();
-        }
-    }
-}