diff -r 000000000000 -r 6474c204b198 js/src/jit-test/lib/bytecode-cache.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/js/src/jit-test/lib/bytecode-cache.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,47 @@ + +function evalWithCache(code, ctx) { + ctx = ctx || {}; + ctx = Object.create(ctx, { + fileName: { value: "evalWithCacheCode.js" }, + lineNumber: { value: 0 } + }); + code = code instanceof Object ? code : cacheEntry(code); + + // We create a new global ... + if (!("global" in ctx)) + ctx.global = newGlobal(); + + // ... and by default enable compileAndGo. + if (!("compileAndGo" in ctx)) + ctx.compileAndGo = true; + + // Fetch the verification function from the evaluation context. This function + // is used to assert the state of the script/function after each run of the + // evaluate function. + var checkAfter = ctx.checkAfter || function(ctx) {}; + + // The generation counter is used to represent environment variations which + // might cause the program to run differently, and thus to have a different + // set of functions executed. + ctx.global.generation = 0; + var res1 = evaluate(code, Object.create(ctx, {saveBytecode: { value: true } })); + checkAfter(ctx); + + ctx.global.generation = 1; + var res2 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true }, saveBytecode: { value: true } })); + checkAfter(ctx); + + ctx.global.generation = 2; + var res3 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true } })); + checkAfter(ctx); + + ctx.global.generation = 3; + var res0 = evaluate(code, ctx); + checkAfter(ctx); + + if (ctx.assertEqResult) { + assertEq(res0, res1); + assertEq(res0, res2); + assertEq(res0, res3); + } +}