Debian Codegraph @

js/src/jit-test/tests/parser/stencil.js

raw
1 const optionsFull = {
2 fileName: "compileToStencil-DATA.js",
3 lineNumber: 1,
4 eagerDelazificationStrategy: "ParseEverythingEagerly",
5 };
6
7 const optionsLazy = {
8 fileName: "compileToStencil-DATA.js",
9 lineNumber: 1,
10 eagerDelazificationStrategy: "OnDemandOnly",
11 };
12
13 const optionsLazyCache = {
14 fileName: "compileToStencil-DATA.js",
15 lineNumber: 1,
16 eagerDelazificationStrategy: "ConcurrentDepthFirst",
17 };
18
19 function testMainThread(script_str) {
20 const eval_f = eval;
21 const stencil = compileToStencil(script_str, optionsFull);
22 const result = evalStencil(stencil, optionsFull);
23 assertEq(result, eval_f(script_str));
24 }
25
26 function testMainThreadDelazifyAll(script_str) {
27 if (isLcovEnabled()) {
28 // Code-coverage implies forceFullParse = true, and as such it cannot be
29 // used while testing to incrementally delazify.
30 return;
31 }
32 const eval_f = eval;
33 const stencil = compileToStencil(script_str, optionsLazy);
34 const result = evalStencil(stencil, optionsLazy);
35 assertEq(result, eval_f(script_str));
36 }
37
38 function testMainThreadCacheAll(script_str) {
39 if (isLcovEnabled() || helperThreadCount() === 0) {
40 // Code-coverage implies forceFullParse = true, and as such it cannot be
41 // used while testing to incrementally delazify.
42 // Similarly, concurrent delazification requires off-threads processing.
43 return;
44 }
45 const eval_f = eval;
46 const stencil = compileToStencil(script_str, optionsLazyCache);
47 const result = evalStencil(stencil, optionsLazyCache);
48 assertEq(result, eval_f(script_str));
49 }
50
51 function testOffThread(script_str) {
52 const eval_f = eval;
53 const job = offThreadCompileToStencil(script_str, optionsFull);
54 const stencil = finishOffThreadStencil(job);
55 const result = evalStencil(stencil, optionsFull);
56 assertEq(result, eval_f(script_str));
57 }
58
59 testMainThread(`
60 var a = 10;
61 let b = 20, c = 30;
62 const d = 40;
63 function f() {
64 return a + b + c + d;
65 }
66 f();
67 `);
68
69 testMainThreadDelazifyAll(`
70 var a1 = 10;
71 let b1 = 20, c1 = 30;
72 const d1 = 40;
73 function g1() {
74 function h1() {
75 return a1 + b1;
76 }
77 return h1() + c1;
78 }
79 function f1() {
80 return a1 + b1 + c1 + d1;
81 }
82 f1();
83 `);
84
85 testMainThreadCacheAll(`
86 var a3 = 10;
87 let b3 = 20, c3 = 30;
88 const d3 = 40;
89 function g3() {
90 function h3() {
91 return a3 + b3;
92 }
93 return h3() + c3;
94 }
95 function f3() {
96 return a3 + b3 + c3 + d3;
97 }
98 f3();
99 `);
100
101 if (helperThreadCount() > 0) {
102 testOffThread(`
103 var a2 = 10;
104 let b2 = 20, c2 = 30;
105 const d2 = 40;
106 function f2() {
107 return a2 + b2 + c2 + d2;
108 }
109 f2();
110 `);
111 }