summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Temporal/PlainDate/prototype/eraYear/validate-calendar-value.js
blob: 48bb01304eb4959c6e21b457f00090fa696993b9 (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
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2023 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindate.prototype.erayear
description: Validate result returned from calendar eraYear() method
features: [Temporal]
---*/

const badResults = [
  [null, TypeError],
  [false, TypeError],
  [Infinity, RangeError],
  [-Infinity, RangeError],
  [NaN, RangeError],
  [-0.1, RangeError],
  ["string", TypeError],
  [Symbol("foo"), TypeError],
  [7n, TypeError],
  [{}, TypeError],
  [true, TypeError],
  [7.1, RangeError],
  ["7", TypeError],
  ["7.5", TypeError],
  [{valueOf() { return 7; }}, TypeError],
];

badResults.forEach(([result, error]) => {
  const calendar = new class extends Temporal.Calendar {
    eraYear() {
      return result;
    }
  }("iso8601");
  const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
  assert.throws(error, () => instance.eraYear, `${typeof result} ${String(result)} not converted to integer`);
});

const preservedResults = [
  undefined,
  -7,
];

preservedResults.forEach(result => {
  const calendar = new class extends Temporal.Calendar {
    eraYear() {
      return result;
    }
  }("iso8601");
  const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
  assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`);
});

reportCompare(0, 0);