Debian Codegraph @

js/src/jit-test/tests/explicit-resource-management/using-in-function.js

raw
1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management
2
3 load(libdir + "asserts.js");
4
5 const disposed = [];
6 function testDisposalsInFunction() {
7 using a = { [Symbol.dispose]: () => disposed.push("a") };
8 using b = { [Symbol.dispose]: () => disposed.push("b") };
9 using c = { [Symbol.dispose]: () => disposed.push("c") };
10 disposed.push("d");
11 }
12 testDisposalsInFunction();
13 assertArrayEq(disposed, ["d", "c", "b", "a"]);
14
15 const disposedInFunctionAndBlock = [];
16 function testDisposalsInFunctionAndBlock() {
17 using a = {
18 [Symbol.dispose]: () => disposedInFunctionAndBlock.push("a")
19 };
20
21 using b = {
22 [Symbol.dispose]: () => disposedInFunctionAndBlock.push("b")
23 };
24
25 {
26 using c = {
27 [Symbol.dispose]: () => disposedInFunctionAndBlock.push("c")
28 };
29
30 {
31 using d = {
32 [Symbol.dispose]: () => disposedInFunctionAndBlock.push("d")
33 };
34 }
35
36 using e = {
37 [Symbol.dispose]: () => disposedInFunctionAndBlock.push("e")
38 };
39 }
40
41 using f = {
42 [Symbol.dispose]: () => disposedInFunctionAndBlock.push("f")
43 };
44
45 disposedInFunctionAndBlock.push("g");
46 }
47 testDisposalsInFunctionAndBlock();
48 assertArrayEq(disposedInFunctionAndBlock, ["d", "e", "c", "g", "f", "b", "a"]);