EngineLimitTests.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #if !NETFRAMEWORK
  2. using System.Text;
  3. namespace Jint.Tests.Runtime;
  4. public class EngineLimitTests
  5. {
  6. [Fact]
  7. public void ShouldAllowReasonableCallStackDepth()
  8. {
  9. #if RELEASE
  10. const int FunctionNestingCount = 990;
  11. #else
  12. const int FunctionNestingCount = 570;
  13. #endif
  14. // generate call tree
  15. var sb = new StringBuilder();
  16. sb.AppendLine("var x = 10;");
  17. sb.AppendLine();
  18. for (var i = 1; i <= FunctionNestingCount; ++i)
  19. {
  20. sb.Append("function func").Append(i).Append("(func").Append(i).AppendLine("Param) {");
  21. sb.Append(" ");
  22. if (i != FunctionNestingCount)
  23. {
  24. // just to create a bit more nesting add some constructs
  25. sb.Append("return x++ > 1 ? func").Append(i + 1).Append("(func").Append(i).AppendLine("Param): undefined;");
  26. }
  27. else
  28. {
  29. // use known CLR function to add breakpoint
  30. sb.Append("return Math.max(0, func").Append(i).AppendLine("Param);");
  31. }
  32. sb.AppendLine("}");
  33. sb.AppendLine();
  34. }
  35. var engine = new Engine();
  36. engine.Execute(sb.ToString());
  37. Assert.Equal(123, engine.Evaluate("func1(123);").AsNumber());
  38. }
  39. }
  40. #endif