offThreadCompileToStencil-03.js (1368B)
1 // |jit-test| skip-if: helperThreadCount() === 0 2 3 // Test offThreadCompileToStencil for different function types. 4 5 load(libdir + 'asserts.js'); 6 7 var id, stencil; 8 9 id = offThreadCompileToStencil(` 10 function f() { return "pass"; } 11 f(); 12 `); 13 stencil = finishOffThreadStencil(id); 14 assertEq(evalStencil(stencil), "pass"); 15 16 id = offThreadCompileToStencil(` 17 function* f() { return "pass"; } 18 f().next(); 19 `); 20 stencil = finishOffThreadStencil(id); 21 assertDeepEq(evalStencil(stencil), {value: "pass", done: true}); 22 23 id = offThreadCompileToStencil(` 24 async function f() { return "pass"; } 25 f(); 26 `); 27 stencil = finishOffThreadStencil(id); 28 assertEventuallyEq(evalStencil(stencil), "pass"); 29 30 id = offThreadCompileToStencil(` 31 async function* f() { return "pass"; } 32 f().next(); 33 `); 34 stencil = finishOffThreadStencil(id); 35 assertEventuallyDeepEq(evalStencil(stencil), {value: "pass", done: true}); 36 37 // Copied from js/src/tests/shell.js 38 function getPromiseResult(promise) { 39 var result, error, caught = false; 40 promise.then(r => { result = r; }, 41 e => { caught = true; error = e; }); 42 drainJobQueue(); 43 if (caught) 44 throw error; 45 return result; 46 } 47 48 function assertEventuallyEq(promise, expected) { 49 assertEq(getPromiseResult(promise), expected); 50 } 51 52 function assertEventuallyDeepEq(promise, expected) { 53 assertDeepEq(getPromiseResult(promise), expected); 54 }