summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib/bytecode-cache.js
blob: 1f8f58643a8f90987b3b8b54cc3e8056c2d808ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function evalWithCache(code, ctx) {
  ctx = ctx || {};
  ctx = Object.create(ctx, {
    fileName: { value: "evalWithCacheCode.js" },
    lineNumber: { value: 0 }
  });
  code = code instanceof Object ? code : cacheEntry(code);

  var incremental = ctx.incremental || false;

  // We create a new global ...
  if (!("global" in ctx))
      ctx.global = newGlobal({newCompartment: ctx.newCompartment});

  var ctx_save = Object.create(ctx, {
    saveIncrementalBytecode: { value: 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, ctx_save);
  checkAfter(ctx);

  ctx.global.generation = 1;
  var res2 = evaluate(code, Object.create(ctx_save, {loadBytecode: { 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);
  }

  if (ctx.checkFrozen) {
    assertEq(Object.isFrozen(res0), Object.isFrozen(res1));
    assertEq(Object.isFrozen(res0), Object.isFrozen(res2));
    assertEq(Object.isFrozen(res0), Object.isFrozen(res3));
  }
}