Debian Codegraph @

js/src/jit-test/tests/explicit-resource-management/await-using-with-promise-prototype-pollution.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 = 0;
8 const originalThen = Promise.prototype.then;
9 Promise.prototype.then = function (onFulfilled, onRejected) {
10 thenCalled++;
11 return originalThen.call(this, onFulfilled, onRejected);
12 };
13 const thenCalls = [];
14 async function testAwaitUsingWithPromisePrototypePollution() {
15 await using x = {
16 [Symbol.asyncDispose]() {
17 return new Promise((resolve) => {
18 disposed.push(1);
19 resolve(1);
20 }).then((r) => {
21 thenCalls.push(r);
22 });
23 }
24 }
25 await using y = {
26 [Symbol.asyncDispose]() {
27 return new Promise((resolve) => {
28 disposed.push(2);
29 resolve();
30 });
31 }
32 }
33 }
34 testAwaitUsingWithPromisePrototypePollution();
35 drainJobQueue();
36 assertEq(thenCalled, 1);
37 assertArrayEq(disposed, [2, 1]);
38 assertArrayEq(thenCalls, [1]);
39 }