michael@0: michael@0: function evalWithCache(code, ctx) { michael@0: ctx = ctx || {}; michael@0: ctx = Object.create(ctx, { michael@0: fileName: { value: "evalWithCacheCode.js" }, michael@0: lineNumber: { value: 0 } michael@0: }); michael@0: code = code instanceof Object ? code : cacheEntry(code); michael@0: michael@0: // We create a new global ... michael@0: if (!("global" in ctx)) michael@0: ctx.global = newGlobal(); michael@0: michael@0: // ... and by default enable compileAndGo. michael@0: if (!("compileAndGo" in ctx)) michael@0: ctx.compileAndGo = true; michael@0: michael@0: // Fetch the verification function from the evaluation context. This function michael@0: // is used to assert the state of the script/function after each run of the michael@0: // evaluate function. michael@0: var checkAfter = ctx.checkAfter || function(ctx) {}; michael@0: michael@0: // The generation counter is used to represent environment variations which michael@0: // might cause the program to run differently, and thus to have a different michael@0: // set of functions executed. michael@0: ctx.global.generation = 0; michael@0: var res1 = evaluate(code, Object.create(ctx, {saveBytecode: { value: true } })); michael@0: checkAfter(ctx); michael@0: michael@0: ctx.global.generation = 1; michael@0: var res2 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true }, saveBytecode: { value: true } })); michael@0: checkAfter(ctx); michael@0: michael@0: ctx.global.generation = 2; michael@0: var res3 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true } })); michael@0: checkAfter(ctx); michael@0: michael@0: ctx.global.generation = 3; michael@0: var res0 = evaluate(code, ctx); michael@0: checkAfter(ctx); michael@0: michael@0: if (ctx.assertEqResult) { michael@0: assertEq(res0, res1); michael@0: assertEq(res0, res2); michael@0: assertEq(res0, res3); michael@0: } michael@0: }