summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/harness/assert-throws-custom-typeerror.js
blob: b49ae1b5a62e4d3241a078af4e3699d83388dfb4 (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
// Copyright (C) 2021 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
    Functions that throw instances of the specified constructor function
    satisfy the assertion, without collision with error constructors of the
    same name.
---*/

var intrinsicTypeError = TypeError; 
var threw = false;

(function() {
  function TypeError() {}

  assert.throws(TypeError, function() {
    throw new TypeError();
  }, 'Throws an instance of the matching custom TypeError');

  try {
    assert.throws(intrinsicTypeError, function() {
      throw new TypeError();
    });
  } catch (err) {
    threw = true;
    if (err.constructor !== Test262Error) {
      throw new Error(
        'Expected a Test262Error but a "' + err.constructor.name + 
        '" was thrown.'
      );
    }
  }

  if (threw === false) {
    throw new Error('Expected a Test262Error, but no error was thrown.');
  }

  threw = false;

  try {
    assert.throws(TypeError, function() {
      throw new intrinsicTypeError();
    });
  } catch (err) {
    threw = true;
    if (err.constructor !== Test262Error) {
      throw new Error(
        'Expected a Test262Error but a "' + err.constructor.name + 
        '" was thrown.'
      );
    }
  }

  if (threw === false) {
    throw new Error('Expected a Test262Error, but no error was thrown.');
  }
})();

reportCompare(0, 0);