Debian Codegraph @

js/src/jit-test/tests/explicit-resource-management/await-using-for-of-loop-head-causes-awaits.js

raw
1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management
2
3 load(libdir + "asserts.js");
4
5 {
6 const values = [];
7 async function testAwaitUsingInForOfLoopHeadAwaitsPromise() {
8 const obj = {
9 [Symbol.asyncDispose]() {
10 values.push(1);
11 return new Promise(() => {});
12 }
13 };
14
15 // The dispose operation here should wait forever.
16 for (await using u of [obj]) {}
17
18 values.push(2);
19 }
20 testAwaitUsingInForOfLoopHeadAwaitsPromise();
21 drainJobQueue();
22 assertArrayEq(values, [1]);
23 }
24
25 {
26 const disposed = [];
27 let caught;
28 async function testAwaitUsingInForOfLoopHeadAwaitsPromiseRejection() {
29 const obj = {
30 [Symbol.asyncDispose]() {
31 disposed.push(1);
32 return new Promise((res, rej) => {
33 rej('err');
34 });
35 }
36 };
37
38 try {
39 for (await using u of [obj]) {}
40 } catch (e) {
41 caught = e;
42 }
43 }
44 testAwaitUsingInForOfLoopHeadAwaitsPromiseRejection();
45 drainJobQueue();
46 assertArrayEq(disposed, [1]);
47 assertEq(caught, 'err');
48 }