| 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 |
var collectDelazifications = ctx.collectDelazifications || false; |
| 11 |
|
| 12 |
// We create a new global ... |
| 13 |
if (!("global" in ctx)) |
| 14 |
ctx.global = newGlobal({newCompartment: ctx.newCompartment}); |
| 15 |
|
| 16 |
var ctx_save = Object.create(ctx, { |
| 17 |
saveBytecodeWithDelazifications: { value: true } |
| 18 |
}); |
| 19 |
|
| 20 |
// Fetch the verification function from the evaluation context. This function |
| 21 |
// is used to assert the state of the script/function after each run of the |
| 22 |
// evaluate function. |
| 23 |
var checkAfter = ctx.checkAfter || function(ctx) {}; |
| 24 |
|
| 25 |
// The generation counter is used to represent environment variations which |
| 26 |
// might cause the program to run differently, and thus to have a different |
| 27 |
// set of functions executed. |
| 28 |
ctx.global.generation = 0; |
| 29 |
var res1 = evaluate(code, ctx_save); |
| 30 |
checkAfter(ctx); |
| 31 |
|
| 32 |
ctx.global.generation = 1; |
| 33 |
var res2 = evaluate(code, Object.create(ctx_save, {loadBytecode: { value: true } })); |
| 34 |
checkAfter(ctx); |
| 35 |
|
| 36 |
ctx.global.generation = 2; |
| 37 |
var res3 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true } })); |
| 38 |
checkAfter(ctx); |
| 39 |
|
| 40 |
ctx.global.generation = 3; |
| 41 |
var res0 = evaluate(code, ctx); |
| 42 |
checkAfter(ctx); |
| 43 |
|
| 44 |
if (ctx.assertEqResult) { |
| 45 |
assertEq(res0, res1); |
| 46 |
assertEq(res0, res2); |
| 47 |
assertEq(res0, res3); |
| 48 |
} |
| 49 |
|
| 50 |
if (ctx.checkFrozen) { |
| 51 |
assertEq(Object.isFrozen(res0), Object.isFrozen(res1)); |
| 52 |
assertEq(Object.isFrozen(res0), Object.isFrozen(res2)); |
| 53 |
assertEq(Object.isFrozen(res0), Object.isFrozen(res3)); |
| 54 |
} |
| 55 |
} |