Debian Codegraph @

js/src/tests/test262/harness/asyncHelpers-throwsAsync-invalid-func.js

raw
1 // |reftest| async
2 // Copyright (C) 2022 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 description: |
6 assert.throwsAsync calls $DONE with a rejecting value if func is not a function returning a thenable.
7 flags: [async]
8 includes: [asyncHelpers.js]
9 ---*/
10
11 async function checkRejects(func) {
12 var caught = false;
13 const p = assert.throwsAsync(Test262Error, func);
14 assert(p instanceof Promise, "assert.throwsAsync should return a promise");
15 try {
16 await p;
17 } catch (e) {
18 caught = true;
19 assert.sameValue(
20 e.constructor,
21 Test262Error,
22 "throwsAsync should reject improper function with a Test262Error"
23 );
24 } finally {
25 assert(
26 caught,
27 "assert.throwsAsync did not reject improper function " + func
28 );
29 }
30 }
31
32 asyncTest(async function () {
33 await checkRejects(null);
34 await checkRejects({});
35 await checkRejects("string");
36 await checkRejects(10);
37 await checkRejects();
38 await checkRejects({
39 then: function (res, rej) {
40 res(true);
41 },
42 });
43 await checkRejects(function () {
44 return null;
45 });
46 await checkRejects(function () {
47 return {};
48 });
49 await checkRejects(function () {
50 return "string";
51 });
52 await checkRejects(function () {
53 return 10;
54 });
55 await checkRejects(function () {});
56 await checkRejects(function () {
57 return { then: null };
58 });
59 await checkRejects(function () {
60 return { then: {} };
61 });
62 await checkRejects(function () {
63 return { then: "string" };
64 });
65 await checkRejects(function () {
66 return { then: 10 };
67 });
68 await checkRejects(function () {
69 return { then: undefined };
70 });
71 });