summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/NativeErrors/AggregateError/message-tostring-abrupt.js
blob: 1c356d719a3ea86324fc79c79171d845b07b6d9b (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
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-aggregate-error
description: >
  Abrupt completions of ToString(message)
info: |
  AggregateError ( errors, message )

  ...
  5. If message is not undefined, then
    a. Let msg be ? ToString(message).
    b. Perform ! CreateMethodProperty(O, "message", msg).
  6. Return O.
features: [AggregateError, Symbol.toPrimitive]
---*/

var case1 = {
  [Symbol.toPrimitive]() {
    throw new Test262Error();
  },
  toString() {
    throw 'toString called';
  },
  valueOf() {
    throw 'valueOf called';
  }
};

assert.throws(Test262Error, () => {
  new AggregateError([], case1);
}, 'toPrimitive');

var case2 = {
  [Symbol.toPrimitive]: undefined,
  toString() {
    throw new Test262Error();
  },
  valueOf() {
    throw 'valueOf called';
  }
};

assert.throws(Test262Error, () => {
  new AggregateError([], case2);
}, 'toString');

var case3 = {
  [Symbol.toPrimitive]: undefined,
  toString: undefined,
  valueOf() {
    throw new Test262Error();
  }
};

assert.throws(Test262Error, () => {
  new AggregateError([], case3);
}, 'valueOf');

reportCompare(0, 0);