summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/PlainDate/negative-infinity-throws-rangeerror.js
blob: 07787c67b7e01ccc0f82bc8f9199aa2450b3eea4 (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
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Temporal.PlainDate throws a RangeError if any value is -Infinity
esid: sec-temporal.plaindate
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

assert.throws(RangeError, () => new Temporal.PlainDate(-Infinity, 1, 1));
assert.throws(RangeError, () => new Temporal.PlainDate(1970, -Infinity, 1));
assert.throws(RangeError, () => new Temporal.PlainDate(1970, 1, -Infinity));

const O = (primitiveValue, propertyName) => (calls) => TemporalHelpers.toPrimitiveObserver(calls, primitiveValue, propertyName);
const tests = [
  [
    "infinite year",
    [O(-Infinity, "year"), O(1, "month"), O(1, "day")],
    ["get year.valueOf", "call year.valueOf"]
  ],
  [
    "infinite month",
    [O(2, "year"), O(-Infinity, "month"), O(1, "day")],
    ["get year.valueOf", "call year.valueOf", "get month.valueOf", "call month.valueOf"]
  ],
  [
    "infinite day",
    [O(2, "year"), O(1, "month"), O(-Infinity, "day")],
    ["get year.valueOf", "call year.valueOf", "get month.valueOf", "call month.valueOf", "get day.valueOf", "call day.valueOf"]
  ],
];

for (const [description, args, expected] of tests) {
  const actual = [];
  const args_ = args.map((o) => o(actual));
  assert.throws(RangeError, () => new Temporal.PlainDate(...args_), description);
  assert.compareArray(actual, expected, `${description} order of operations`);
}

reportCompare(0, 0);