cmbail.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 shouldBailout = false;
  6. var failed = 0;
  7. var valueCalls = 0;
  8. function FAILED(x) {
  9. WScript.Echo("FAILED #", x);
  10. failed++;
  11. }
  12. function test0() {
  13. var func2 = function () {
  14. return (g <= h);
  15. }
  16. var g = 1;
  17. var h = 1;
  18. obj.x = 1;
  19. if (shouldBailout) { h = { valueOf: function () { valueCalls++; return 3; } } }
  20. if ((func2(g))) {
  21. } else {
  22. FAILED(1);
  23. }
  24. return obj.x;
  25. };
  26. function test1() {
  27. var func2 = function () {
  28. return (g <= h);
  29. }
  30. var g = 1;
  31. var h = 1;
  32. obj.x = 1;
  33. if (shouldBailout) { h = { valueOf: function () { valueCalls++; return 3; } } }
  34. if ((!func2(g))) {
  35. FAILED(2);
  36. }
  37. return obj.x;
  38. };
  39. function test2() {
  40. var func2 = function () {
  41. return (g > h);
  42. }
  43. var g = 0;
  44. var h = 1;
  45. obj.x = 1;
  46. if (shouldBailout) { h = { valueOf: function () { valueCalls++; return 3; } } }
  47. if ((func2(g))) {
  48. FAILED(3);
  49. }
  50. return obj.x;
  51. };
  52. function test3() {
  53. var func2 = function () {
  54. return (g == h);
  55. }
  56. var g = 0;
  57. var h = 1;
  58. obj.x = 1;
  59. if (shouldBailout) { h = { valueOf: function () { valueCalls++; return 3; } } }
  60. if ((func2(g))) {
  61. FAILED(4);
  62. }
  63. return obj.x;
  64. };
  65. function test4() {
  66. var func2 = function () {
  67. return (g != h);
  68. }
  69. var g = 3;
  70. var h = 3;
  71. obj.x = 1;
  72. if (shouldBailout) { h = { valueOf: function () { valueCalls++; return 3; } } }
  73. if ((func2(g))) {
  74. FAILED(5);
  75. }
  76. return obj.x;
  77. };
  78. var obj = new Object();
  79. obj.x = 1;
  80. // generate profile
  81. test0();
  82. test1();
  83. test2();
  84. test3();
  85. test4();
  86. // run JITted code
  87. test0();
  88. test1();
  89. test2();
  90. test3();
  91. test4();
  92. // run code with bailouts enabled
  93. shouldBailout = true;
  94. test0();
  95. test1();
  96. test2();
  97. test3();
  98. test4();
  99. if (valueCalls != 5)
  100. {
  101. FAILED(6);
  102. }
  103. if (failed == 0) {
  104. WScript.Echo("Passed");
  105. }