Debian Codegraph @

js/src/jit-test/tests/xdr/decode-off-thread.js

raw
1 // |jit-test| skip-if: helperThreadCount() === 0
2
3 function evalWithCacheLoadOffThread(code, ctx) {
4 ctx = ctx || {};
5 ctx = Object.create(ctx, {
6 fileName: { value: "evalWithCacheCode.js" },
7 lineNumber: { value: 0 }
8 });
9 code = code instanceof Object ? code : cacheEntry(code);
10
11 // We create a new global ...
12 if (!("global" in ctx))
13 ctx.global = newGlobal();
14
15 var ctx_save = Object.create(ctx, {
16 saveBytecodeWithDelazifications: { value: true }
17 });
18
19 ctx.global.generation = 0;
20 evaluate(code, ctx_save);
21
22 offThreadDecodeStencil(code, ctx);
23 ctx.global.eval(`
24 stencil = finishOffThreadStencil();
25 evalStencil(stencil);
26 `);
27 }
28
29 var test;
30
31 // Decode a constant.
32 test = `
33 1;
34 `;
35 evalWithCacheLoadOffThread(test, {});
36
37 // Decode object literals.
38 test = `
39 var obj = { a: 1, b: 2 };
40 obj.a++;
41 assertEq(obj.a, 2);
42 `;
43 evalWithCacheLoadOffThread(test, {});
44
45 // Decode functions.
46 test = `
47 function g() {
48 return function f() { return 1; };
49 };
50 assertEq(g()(), 1);
51 `;
52 evalWithCacheLoadOffThread(test, {});
53
54