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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/lib/bytecode-cache.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +
     1.5 +function evalWithCache(code, ctx) {
     1.6 +  ctx = ctx || {};
     1.7 +  ctx = Object.create(ctx, {
     1.8 +    fileName: { value: "evalWithCacheCode.js" },
     1.9 +    lineNumber: { value: 0 }
    1.10 +  });
    1.11 +  code = code instanceof Object ? code : cacheEntry(code);
    1.12 +
    1.13 +  // We create a new global ...
    1.14 +  if (!("global" in ctx))
    1.15 +    ctx.global = newGlobal();
    1.16 +
    1.17 +  // ... and by default enable compileAndGo.
    1.18 +  if (!("compileAndGo" in ctx))
    1.19 +    ctx.compileAndGo = true;
    1.20 +
    1.21 +  // Fetch the verification function from the evaluation context.  This function
    1.22 +  // is used to assert the state of the script/function after each run of the
    1.23 +  // evaluate function.
    1.24 +  var checkAfter = ctx.checkAfter || function(ctx) {};
    1.25 +
    1.26 +  // The generation counter is used to represent environment variations which
    1.27 +  // might cause the program to run differently, and thus to have a different
    1.28 +  // set of functions executed.
    1.29 +  ctx.global.generation = 0;
    1.30 +  var res1 = evaluate(code, Object.create(ctx, {saveBytecode: { value: true } }));
    1.31 +  checkAfter(ctx);
    1.32 +
    1.33 +  ctx.global.generation = 1;
    1.34 +  var res2 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true }, saveBytecode: { value: true } }));
    1.35 +  checkAfter(ctx);
    1.36 +
    1.37 +  ctx.global.generation = 2;
    1.38 +  var res3 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true } }));
    1.39 +  checkAfter(ctx);
    1.40 +
    1.41 +  ctx.global.generation = 3;
    1.42 +  var res0 = evaluate(code, ctx);
    1.43 +  checkAfter(ctx);
    1.44 +
    1.45 +  if (ctx.assertEqResult) {
    1.46 +    assertEq(res0, res1);
    1.47 +    assertEq(res0, res2);
    1.48 +    assertEq(res0, res3);
    1.49 +  }
    1.50 +}

mercurial