/js/src/jit-test/tests/jaeger/recompile/exotic.js

http://github.com/zpao/v8monkey · JavaScript · 74 lines · 56 code · 12 blank · 6 comment · 10 complexity · 71c8864f4b31aad63f72922e9aab7026 MD5 · raw file

  1. // Test exotic ways of triggering recompilation.
  2. // Lowered native call.
  3. var x = 0;
  4. var y = true;
  5. for (var i = 0; i < 20; i++) {
  6. x += Array.map.apply(undefined, [[0], function(x) { if (i == 10) eval("y = 20"); return 1; }])[0];
  7. }
  8. assertEq(x, 20);
  9. assertEq(y, 20);
  10. // Recompilation triggered by local function.
  11. var o = {};
  12. function what(q) {
  13. function inner() { return q; }
  14. o.f = inner;
  15. var a = o.f();
  16. return a;
  17. }
  18. for (var i = 0; i < 10; i++) {
  19. var a = what(i);
  20. assertEq(a, i);
  21. }
  22. // Lowered scripted call to apply returning code pointer.
  23. var global = 3;
  24. function foo(x, y) {
  25. var q = x.apply(null, y);
  26. if (q != 10)
  27. assertEq(global, true);
  28. }
  29. foo(function(a) { global = a; return 10; }, [1]);
  30. foo(function(a) { global = a; return 10; }, [1]);
  31. foo(function(a) { global = a; return 10; }, [1]);
  32. assertEq(global, 1);
  33. foo(function(a) { global = a; return 3; }, [true]);
  34. assertEq(global, true);
  35. // Lowered scripted call returning NULL.
  36. var oglobal = 3;
  37. function xfoo(x, y) {
  38. var q = x.apply(null, y);
  39. if (q != 10)
  40. assertEq(oglobal, true);
  41. }
  42. xfoo(function(a) { oglobal = a; return 10; }, [1]);
  43. xfoo(function(a) { oglobal = a; return 10; }, [1]);
  44. xfoo(function(a) { oglobal = a; return 10; }, [1]);
  45. assertEq(oglobal, 1);
  46. xfoo(function(a) { <x></x>; oglobal = a; return 3; }, [true]);
  47. assertEq(oglobal, true);
  48. // Recompilation out of SplatApplyArgs.
  49. weirdarray = [,,1,2,3];
  50. Object.defineProperty(weirdarray, 0, {get: function() { vglobal = 'true'; }});
  51. var vglobal = 3;
  52. function yfoo(x, y) {
  53. var q = x.apply(null, y);
  54. if (q != 10)
  55. assertEq(vglobal, 'true');
  56. else
  57. assertEq(vglobal, 3);
  58. }
  59. yfoo(function(a) { return 10; }, [1]);
  60. yfoo(function(a) { return 10; }, [1]);
  61. yfoo(function(a) { return 10; }, [1]);
  62. yfoo(function() { return 0; }, weirdarray);