PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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