js/src/jit-test/lib/bytecode-cache.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:fa012d10fe4a
1
2 function evalWithCache(code, ctx) {
3 ctx = ctx || {};
4 ctx = Object.create(ctx, {
5 fileName: { value: "evalWithCacheCode.js" },
6 lineNumber: { value: 0 }
7 });
8 code = code instanceof Object ? code : cacheEntry(code);
9
10 // We create a new global ...
11 if (!("global" in ctx))
12 ctx.global = newGlobal();
13
14 // ... and by default enable compileAndGo.
15 if (!("compileAndGo" in ctx))
16 ctx.compileAndGo = true;
17
18 // Fetch the verification function from the evaluation context. This function
19 // is used to assert the state of the script/function after each run of the
20 // evaluate function.
21 var checkAfter = ctx.checkAfter || function(ctx) {};
22
23 // The generation counter is used to represent environment variations which
24 // might cause the program to run differently, and thus to have a different
25 // set of functions executed.
26 ctx.global.generation = 0;
27 var res1 = evaluate(code, Object.create(ctx, {saveBytecode: { value: true } }));
28 checkAfter(ctx);
29
30 ctx.global.generation = 1;
31 var res2 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true }, saveBytecode: { value: true } }));
32 checkAfter(ctx);
33
34 ctx.global.generation = 2;
35 var res3 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true } }));
36 checkAfter(ctx);
37
38 ctx.global.generation = 3;
39 var res0 = evaluate(code, ctx);
40 checkAfter(ctx);
41
42 if (ctx.assertEqResult) {
43 assertEq(res0, res1);
44 assertEq(res0, res2);
45 assertEq(res0, res3);
46 }
47 }

mercurial