Debian Codegraph @

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

raw
1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management
2
3 load(libdir + "asserts.js");
4
5 const disposedInGenerator = [];
6 function* gen() {
7 using x = {
8 value: 1,
9 [Symbol.dispose]() {
10 disposedInGenerator.push(42);
11 }
12 };
13 yield x;
14 }
15 function testDisposalsInGenerator() {
16 let iter = gen();
17 iter.next();
18 iter.next();
19 disposedInGenerator.push(43);
20 }
21 testDisposalsInGenerator();
22 assertArrayEq(disposedInGenerator, [42, 43]);
23
24 const disposedInGeneratorWithForcedReturn = [];
25 function* gen2() {
26 using x = {
27 value: 1,
28 [Symbol.dispose]() {
29 disposedInGeneratorWithForcedReturn.push(42);
30 }
31 };
32 yield 1;
33 yield 2;
34 }
35 function testDisposalsInGeneratorWithForcedReturn() {
36 const gen = gen2();
37 gen.next();
38 gen.return();
39 disposedInGeneratorWithForcedReturn.push(43);
40 }
41 testDisposalsInGeneratorWithForcedReturn();
42 assertArrayEq(disposedInGeneratorWithForcedReturn, [42, 43]);