generator-jit-bugs.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Copyright (c) ChakraCore Project Contributors. All rights reserved.
  4. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. //-------------------------------------------------------------------------------------------------------
  6. // Simpler mini-test harness to avoid any complicating factors when testing these jit bugs
  7. var results = 0;
  8. var test = 0;
  9. const verbose = WScript.Arguments[0] != "summary";
  10. function check(actual, expected) {
  11. if (actual != expected)
  12. throw new Error("Generator produced " + actual + " instead of " + expected);
  13. if (verbose)
  14. print('Result ' + ++results + ' Generator correctly produced ' + actual);
  15. }
  16. function title (name) {
  17. if (verbose) {
  18. print("Beginning Test " + ++test + ": " + name);
  19. results = 0;
  20. }
  21. }
  22. // Test 1 - const that is unused/replaced with undefined
  23. title("const that is unused/replaced with undefined");
  24. function* gf1() {
  25. const temp2 = null;
  26. while (true) {
  27. yield temp2;
  28. }
  29. }
  30. const gen = gf1();
  31. check(gen.next().value, null);
  32. check(gen.next().value, null);
  33. check(gen.next().value, null);
  34. // Test 2 - load for-in enumerator in nested for-in loop
  35. title("load for-in enumerator in nested for-in loop");
  36. const arr = [0, 1, 2];
  37. function* gf2() {
  38. for (let a in arr) {
  39. for (let b in arr) {
  40. yield a + b;
  41. }
  42. }
  43. }
  44. const gen2 = gf2();
  45. check(gen2.next().value, "00");
  46. check(gen2.next().value, "01");
  47. check(gen2.next().value, "02");
  48. check(gen2.next().value, "10");
  49. check(gen2.next().value, "11");
  50. check(gen2.next().value, "12");
  51. check(gen2.next().value, "20");
  52. check(gen2.next().value, "21");
  53. check(gen2.next().value, "22");
  54. check(gen2.next().value, undefined);
  55. // Test 3 - Bail on no profile losing loop control variable
  56. title("Bail on no profile losing loop control variable");
  57. function* gf3() {
  58. for (let i = 0; i < 3; ++i) {
  59. yield i;
  60. }
  61. }
  62. const gen3 = gf3();
  63. check(gen3.next().value, 0);
  64. check(gen3.next().value, 1);
  65. check(gen3.next().value, 2);
  66. // Test 4 - yield* iterator fails to be restored after Bail on No Profile
  67. title("Bail on no profile losing yield* iterator");
  68. function* gf4() {
  69. yield 0;
  70. yield* [1,2,3];
  71. }
  72. const gen4 = gf4();
  73. check(gen4.next().value, 0);
  74. check(gen4.next().value, 1);
  75. check(gen4.next().value, 2);
  76. check(gen4.next().value, 3);
  77. // Test 5 - scope slots fail to load inside for-in loop
  78. title("Load Scope Slots in presence of for-in");
  79. function* gf5(v1) {
  80. for(v0 in v1) {
  81. yield undefined;
  82. let v2 = {}
  83. function v3() { v2;}
  84. }
  85. }
  86. const gen5 = gf5([0, 1]);
  87. check(gen5.next().value, undefined);
  88. check(gen5.next().value, undefined);
  89. check(gen5.next().value, undefined);
  90. check(gen5.next().value, undefined);
  91. // Test 6 - scope slots used in loop control have invalid values
  92. title("Load Scope Slots used in loop control");
  93. function* gf6 () {
  94. for (let v1 = 0; v1 < 1000; ++v1) {
  95. function foo() {v1;}
  96. yield v1;
  97. }
  98. }
  99. const gen6 = gf6();
  100. check(gen6.next().value, 0);
  101. check(gen6.next().value, 1);
  102. check(gen6.next().value, 2);
  103. check(gen6.next().value, 3);
  104. // Test 7 - storing scoped slot from loop control in array
  105. title("Load Scope Slots used in loop control and captured indirectly");
  106. function* gf7(v1) {
  107. for (const v2 in v1) {
  108. yield v2;
  109. const v4 = [v2];
  110. function foo() { v4; }
  111. }
  112. }
  113. const gen7 = gf7([0, 1, 2]);
  114. check(gen7.next().value, 0);
  115. check(gen7.next().value, 1);
  116. check(gen7.next().value, 2);
  117. check(gen7.next().value, undefined);
  118. // Test 8 - copy prop'd sym is counted as two values - hits bookkeeping FailFast
  119. title("Copy prop sym double counted in unrestorable symbols hits FailFast");
  120. function* gf8() {
  121. var v8 = 1.1;
  122. yield* [];
  123. yield {v8};
  124. }
  125. check(gf8().next().value.v8, 1.1);
  126. check(gf8().next().value.v8, 1.1);
  127. check(gf8().next().value.v8, 1.1);
  128. print("pass");