summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/harness/asyncHelpers-throwsAsync-custom-typeerror.js
blob: 9cc1b95953f6da4fe1ce1af51a015fdc22c8e4a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// |reftest| async
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
    Thenables that reject with instances of the specified constructor function
    satisfy the assertion, without collision with error constructors of the same name.
flags: [async]
includes: [asyncHelpers.js]
---*/

var intrinsicTypeError = TypeError;

asyncTest(async function () {
  function TypeError() {}
  var caught = false;

  var p = assert.throwsAsync(
    TypeError,
    async function () {
      throw new TypeError();
    },
    "Throws an instance of the matching custom TypeError"
  );
  assert(p instanceof Promise);
  await p;

  p = assert.throwsAsync(intrinsicTypeError, async function () {
    throw new TypeError();
  });
  assert(p instanceof Promise);
  try {
    await p;
  } catch (err) {
    caught = true;
    assert.sameValue(
      err.constructor,
      Test262Error,
      "Expected a Test262Error, but a '" +
        err.constructor.name +
        "' was thrown."
    );
  } finally {
    assert(
      caught,
      "assert.throwsAsync did not reject a collision of constructor names"
    );
  }

  caught = false;

  p = assert.throwsAsync(TypeError, async function () {
    throw new intrinsicTypeError();
  });
  assert(p instanceof Promise);
  try {
    await p;
  } catch (err) {
    caught = true;
    assert.sameValue(
      err.constructor,
      Test262Error,
      "Expected a Test262Error, but a '" +
        err.constructor.name +
        "' was thrown."
    );
  } finally {
    assert(
      caught,
      "assert.throwsAsync did not reject a collision of constructor names"
    );
  }
})