Debian Codegraph @

js/src/jit-test/tests/explicit-resource-management/async-disposal-in-async-function-preserves-return-value.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 disposed = [];
7 let thenCalled = false;
8 async function testReturnValueIsPreserved() {
9 await using a = {
10 [Symbol.asyncDispose]: () => disposed.push("a")
11 };
12 await using b = {
13 [Symbol.asyncDispose]: () => disposed.push("b")
14 };
15 return 200;
16 }
17 testReturnValueIsPreserved().then((val) => {
18 thenCalled = true;
19 assertEq(val, 200);
20 });
21 drainJobQueue();
22 assertEq(thenCalled, true);
23 assertArrayEq(disposed, ["b", "a"]);
24 }
25
26 {
27 const disposed = [];
28 let thenCalled = false;
29 async function testReturnValuePreservedWhenWithFinally() {
30 try {
31 await using a = {
32 [Symbol.asyncDispose]: () => disposed.push("a")
33 }
34 return 1;
35 } finally {
36 await using b = {
37 [Symbol.asyncDispose]: () => disposed.push("b")
38 }
39 return 2;
40 }
41 }
42 testReturnValuePreservedWhenWithFinally().then((val) => {
43 thenCalled = true;
44 assertEq(val, 2);
45 });
46 drainJobQueue();
47 assertEq(thenCalled, true);
48 assertArrayEq(disposed, ["a", "b"]);
49 }