summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/xdr/stencil-can-lazily-parse-mismatch.js
blob: 351dbc9648165aa7506cf468d60954f55850d300 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// |jit-test| skip-if: isLcovEnabled()
// Code coverage forces full-parse.

load(libdir + 'asserts.js');

const code = `var a = 10;`;

function testCompile(sourceIsLazy1, sourceIsLazy2,
                     forceFullParse1, forceFullParse2) {
  const stencil = compileToStencil(code, { sourceIsLazy: sourceIsLazy1,
                                           forceFullParse: forceFullParse1 });
  // The laziness options are ignored for instantiation, and no error is thrown.
  evalStencil(stencil, { sourceIsLazy: sourceIsLazy2,
                         forceFullParse: forceFullParse2 });
}

function testOffThreadCompile(sourceIsLazy1, sourceIsLazy2,
                              forceFullParse1, forceFullParse2) {
  offThreadCompileToStencil(code, { sourceIsLazy: sourceIsLazy1,
                                    forceFullParse: forceFullParse1 });
  const stencil = finishOffThreadStencil();
  // The laziness options are ignored for instantiation, and no error is thrown.
  evalStencil(stencil, { sourceIsLazy: sourceIsLazy2,
                         forceFullParse: forceFullParse2 });
}

function testXDR(sourceIsLazy1, sourceIsLazy2,
                 forceFullParse1, forceFullParse2) {
  const xdr = compileToStencilXDR(code, { sourceIsLazy: sourceIsLazy1,
                                          forceFullParse: forceFullParse1 });
  // The compile options are ignored when decoding, and no error is thrown.
  evalStencilXDR(xdr, { sourceIsLazy: sourceIsLazy2,
                        forceFullParse: forceFullParse2 });
}

function testOffThreadXDR(sourceIsLazy1, sourceIsLazy2,
                          forceFullParse1, forceFullParse2) {
  const t = cacheEntry(code);
  evaluate(t, { sourceIsLazy: sourceIsLazy1,
                forceFullParse: forceFullParse1,
                saveIncrementalBytecode: true });

  // The compile options are ignored when decoding, and no error is thrown.
  offThreadDecodeStencil(t, { sourceIsLazy: sourceIsLazy2,
                             forceFullParse: forceFullParse2 });
  const stencil = finishOffThreadStencil();

  // The laziness options are ignored for instantiation, and no error is thrown.
  evalStencil(stencil, { sourceIsLazy: sourceIsLazy2,
                         forceFullParse: forceFullParse2 });
}

const optionsList = [
  [true, false, false, false],
  [false, true, false, false],
  [false, false, true, false],
  [false, false, false, true],
  [true, false, true, false],
  [false, true, false, true],
];

for (const options of optionsList) {
  testCompile(...options);
  if (helperThreadCount() > 0) {
    testOffThreadCompile(...options);
  }
  testXDR(...options);
  if (helperThreadCount() > 0) {
    testOffThreadXDR(...options);
  }
}