MayHaveSideEffectOnNodeSO.js 1.7 KB

123456789101112131415161718192021222324252627282930313233
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // MayHaveSideEffectOnNode() was a recursive function that could recurse enough times to cause
  6. // an uncaught stack overflow. This was fixed by converting the recursive loop into an iterative
  7. // loop.
  8. //
  9. // An example of a program that caused the stack overflow is:
  10. // eval("var a;a>(" + Array(2 ** 15).fill(0).join(",") + ");");
  11. //
  12. // MayHaveSideEffectOnNode() is originally called because the righthand side of the pNodeBin
  13. // ">" may overwrite the lefthand side of ">". The righthand side of pNodeBin is a deep tree
  14. // in which each pNode of the longest path is a pNodeBin(",").Since children of the original
  15. // pNodeBin -> right are pNodeBins themselves, MayHaveSideEffectOnNode() must check all of
  16. // their children as well.MayHaveSideEffectOnNode's original implementation was recursive and
  17. // thus the stack would overflow while recursing through the path of pNodeBins.
  18. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  19. var tests = [
  20. {
  21. name: "MayHaveSideEffectOnNode() should not cause a stack overflow nor should fail to \
  22. terminate",
  23. body: function () {
  24. eval("var a;a>(" + Array(2 ** 15).fill(0).join(",") + ");");
  25. eval("var a;a===(" + Array(2 ** 15).fill(0).join(",") + ");");
  26. }
  27. }
  28. ]
  29. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });