Debian Codegraph @

js/src/tests/test262/harness/asyncHelpers-throwsAsync-func-never-settles.js

raw
1 // |reftest| async
2 // Copyright (C) 2024 Julián Espina. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 description: |
6 assert.throwsAsync returns a promise that never settles if func returns a thenable that never settles.
7 flags: [async]
8 includes: [asyncHelpers.js]
9 ---*/
10
11 var realDone = $DONE;
12 var doneCalls = 0
13 globalThis.$DONE = function () {
14 doneCalls++;
15 }
16
17 function delay() {
18 var later = Promise.resolve();
19 for (var i = 0; i < 100; i++) {
20 later = later.then();
21 }
22 return later;
23 }
24
25 (async function () {
26 // Spy on the promise returned by an invocation of assert.throwsAsync
27 // with a function that returns a thenable which never settles.
28 var neverSettlingThenable = { then: function () { } };
29 const p = assert.throwsAsync(TypeError, function () { return neverSettlingThenable });
30 assert(p instanceof Promise, "assert.throwsAsync should return a promise");
31 p.then($DONE, $DONE);
32 })()
33 // Give it a long time to try.
34 .then(delay, delay)
35 .then(function () {
36 assert.sameValue(doneCalls, 0, "$DONE should not have been called")
37 })
38 .then(realDone, realDone);