SimpleThrow.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 throwException()
  17. {
  18. try
  19. {
  20. BadType.someProperty = 0;
  21. }
  22. catch(e)
  23. {
  24. Dump(TrimStackTracePath(e.stack));
  25. Dump("");
  26. }
  27. }
  28. function throwExceptionWithFinally()
  29. {
  30. try
  31. {
  32. BadTypeWithFinally.someProperty = 0;
  33. }
  34. catch(e)
  35. {
  36. Dump(TrimStackTracePath(e.stack));
  37. Dump("");
  38. }
  39. finally {} // Do nothing
  40. }
  41. function throwExceptionLineNumber()
  42. {
  43. try
  44. {
  45. StricModeFunction();
  46. }
  47. catch(e)
  48. {
  49. Dump(TrimStackTracePath(e.stack));
  50. }
  51. }
  52. function StricModeFunction()
  53. {
  54. "use strict"
  55. this.nonExistentProperty = 1;
  56. if(1) {}
  57. WScript.Echo("foo");
  58. }
  59. function bar()
  60. {
  61. throwException();
  62. throwExceptionWithFinally();
  63. throwExceptionLineNumber();
  64. }
  65. function foo()
  66. {
  67. bar();
  68. }
  69. function runtest()
  70. {
  71. foo();
  72. }
  73. if (this.WScript && this.WScript.Arguments && this.WScript.LoadScriptFile("../UnitTestFramework/TrimStackTracePath.js"))
  74. {
  75. if (this.WScript.Arguments[0] == "runTest")
  76. {
  77. runtest();
  78. }
  79. }