jit-gen-loop-body.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. let bar = [];
  7. let j = 0;
  8. function printif (text, x, mod) {
  9. if (x % mod == 0) {
  10. print (text + x);
  11. }
  12. }
  13. function* basicGenerator(a, b) {
  14. print("Beginning test of " + arguments.callee.name);
  15. yield "yield 2nd param b =" + b;
  16. var foo = [0.1, 0.2, 0.3, 0.4, 0];
  17. while (a < 100) { // Loop 0 - should be jitted
  18. foo[a] = Math.random();
  19. printif(arguments.callee.name + " Loop 0 a = ", a, 40);
  20. printif(arguments.callee.name + " Loop 0 arguments[0] = ", arguments[0], 40);
  21. for (let k in foo) { bar[k] = a - k;} // Loop 1 - shuld be jitted
  22. ++a;
  23. }
  24. while (true){ // Loop 2 - should not be jitted
  25. for (j = 0; j < 100; ++j) { // Loop 3 - should not be jitted
  26. if (j % 40 == 1)
  27. yield j;
  28. foo[j] = j;
  29. }
  30. print("Loop 3 completed");
  31. for (let k of bar) { // Loop 4 - should be jitted
  32. printif("Loop 4 k = ", k, 40);
  33. foo[0] = foo[1] + 1;
  34. }
  35. print("Loop 4 completed");
  36. yield* bar; // Loop 5 - should not be jitted
  37. return j;
  38. }
  39. }
  40. const gen = basicGenerator(5, 1);
  41. for (let x = gen.next(); !x.done; x = gen.next() ) {
  42. printif("yielded value = ", x.value, 40);
  43. }