stack.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 printError(e) {
  6. print(e.name);
  7. print(e.number);
  8. print(e.description);
  9. }
  10. function print(str) {
  11. if (typeof (WScript) == "undefined") {
  12. print(str);
  13. }
  14. else {
  15. WScript.Echo(str);
  16. }
  17. }
  18. for (var i = 1; i < 4; i++) {
  19. print("\n#" + i);
  20. try {
  21. try {
  22. function f() {
  23. f();
  24. }
  25. f();
  26. } finally {
  27. print("In finally");
  28. }
  29. }
  30. catch (e) {
  31. printError(e);
  32. }
  33. }
  34. print("testing stack overflow handling with catch block");
  35. try {
  36. function stackOverFlowCatch() {
  37. try {
  38. stackOverFlowCatch();
  39. while (true) {
  40. }
  41. }
  42. catch (e) {
  43. throw e;
  44. }
  45. }
  46. stackOverFlowCatch();
  47. }
  48. catch (e) {
  49. printError(e);
  50. }
  51. print("testing stack overflow handling with finally block");
  52. try
  53. {
  54. function stackOverFlowFinally() {
  55. try {
  56. stackOverFlowFinally();
  57. while (true) {
  58. }
  59. }
  60. finally {
  61. DoSomething();
  62. }
  63. }
  64. stackOverFlowFinally();
  65. }
  66. catch(e) {
  67. printError(e);
  68. }
  69. function DoSomething()
  70. {
  71. }
  72. try
  73. {
  74. var count = 10000;
  75. var a = {};
  76. var b = a;
  77. for (var i = 0; i < count; i++)
  78. {
  79. a.x = {};
  80. a = a.x;
  81. }
  82. eval("JSON.stringify(b)");
  83. }
  84. catch(e) {
  85. printError(e);
  86. }