LongCallStackThrow.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. function Dump(output)
  6. {
  7. if (this.WScript)
  8. {
  9. WScript.Echo(output);
  10. }
  11. else
  12. {
  13. alert(output);
  14. }
  15. }
  16. function throwExceptionWithCatch()
  17. {
  18. try
  19. {
  20. throwException();
  21. }
  22. catch(e)
  23. {
  24. Dump(TrimStackTracePath(e.stack));
  25. }
  26. }
  27. var errorObject;
  28. function throwException()
  29. {
  30. errorObject = new Error("this is my error");
  31. throw errorObject;
  32. }
  33. function runtest(max, catchException)
  34. {
  35. var helper = function(i)
  36. {
  37. return function(j)
  38. {
  39. if (j == 0)
  40. {
  41. return catchException == undefined ? throwExceptionWithCatch() : throwException();
  42. }
  43. that["function" + (j-1)](j-1);
  44. }
  45. }
  46. var that = new Object();
  47. var i = 0;
  48. for (i = 0; i < max; i++)
  49. {
  50. that["function" + i] = helper(i);
  51. }
  52. that["function" + (max-1)](max-1);
  53. }
  54. if (this.WScript && this.WScript.Arguments && this.WScript.LoadScriptFile("TrimStackTracePath.js"))
  55. {
  56. if (this.WScript.Arguments[0] == "runTest")
  57. {
  58. runtest(this.WScript.Arguments[1]);
  59. }
  60. }