newBuiltin.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. var failed = 0;
  6. function runtest(name, func, throwException)
  7. {
  8. try
  9. {
  10. func();
  11. if (throwException)
  12. {
  13. WScript.Echo(name + ": Test failed, unexpected no exception thrown");
  14. failed++;
  15. }
  16. else
  17. {
  18. WScript.Echo(name + ": Test passed, expected no exception thrown");
  19. }
  20. }
  21. catch (e)
  22. {
  23. if (!throwException || (e.name != "TypeError" && e.name != "ReferenceError"))
  24. {
  25. WScript.Echo(name + ": test failed, unexpected " + e.name + "-" + e.message);
  26. failed++;
  27. }
  28. else
  29. {
  30. WScript.Echo(name + ": Test passed, expected " + e.name + "-" + e.message);
  31. }
  32. }
  33. }
  34. function assert(cond)
  35. {
  36. if (!cond)
  37. {
  38. throw new Error("AssertFailed");
  39. }
  40. }
  41. //-------------------------------------------------------------
  42. // Test 0 - check stuff
  43. //-------------------------------------------------------------
  44. function test0()
  45. {
  46. assert(eval.prototype == undefined);
  47. }
  48. //-------------------------------------------------
  49. // Test 1 - throw, new built in function eval()
  50. //-------------------------------------------------
  51. function test1()
  52. {
  53. new eval();
  54. }
  55. runtest("test0", test0, false);
  56. runtest("test1", test1, true);
  57. if (failed == 0)
  58. {
  59. WScript.Echo("Passed");
  60. }