jit-async-loop-body.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. async function basicAsync(a, b) {
  14. print("Beginning basicAsync")
  15. await b;
  16. var foo = [0.1, 0.2, 0.3, 0.4, 0];
  17. while (a < 200) { // Loop 0 - should be jitted
  18. foo[a] = Math.random();
  19. printif(arguments.callee.name + " Loop 0 a = ", a, 80);
  20. printif(arguments.callee.name + " Loop 0 arguments[0] = ", arguments[0], 80);
  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. await j;
  27. foo[j] = j;
  28. }
  29. print("Loop 3 completed");
  30. for (let k of bar) { // Loop 4 - should be jitted
  31. printif("Loop 4 k = ", k, 80);
  32. foo[0] = foo[1] + 1;
  33. }
  34. print("Loop 4 completed");
  35. return j;
  36. }
  37. }
  38. basicAsync(4, 3).then(x => basicAsync(3, 2));