2
0

EngineLimitTests.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 (OperatingSystem.IsMacOS())
  10. {
  11. // stack limit differ quite a lot
  12. return;
  13. }
  14. #if RELEASE
  15. const int FunctionNestingCount = 960;
  16. #else
  17. const int FunctionNestingCount = 520;
  18. #endif
  19. // generate call tree
  20. var sb = new StringBuilder();
  21. sb.AppendLine("var x = 10;");
  22. sb.AppendLine();
  23. for (var i = 1; i <= FunctionNestingCount; ++i)
  24. {
  25. sb.Append("function func").Append(i).Append("(func").Append(i).AppendLine("Param) {");
  26. sb.Append(" ");
  27. if (i != FunctionNestingCount)
  28. {
  29. // just to create a bit more nesting add some constructs
  30. sb.Append("return x++ > 1 ? func").Append(i + 1).Append("(func").Append(i).AppendLine("Param): undefined;");
  31. }
  32. else
  33. {
  34. // use known CLR function to add breakpoint
  35. sb.Append("return Math.max(0, func").Append(i).AppendLine("Param);");
  36. }
  37. sb.AppendLine("}");
  38. sb.AppendLine();
  39. }
  40. var engine = new Engine();
  41. engine.Execute(sb.ToString());
  42. Assert.Equal(123, engine.Evaluate("func1(123);").AsNumber());
  43. }
  44. }
  45. #endif