summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/PlainDateTime/negative-infinity-throws-rangeerror.js
blob: 938d56bd5c4c4e1b0542fc84cdc99f2dfa7f6b31 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

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

assert.throws(RangeError, () => new Temporal.PlainDateTime(-Infinity, 1, 1));
assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, -Infinity, 1));
assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, -Infinity));
assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, -Infinity));
assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, -Infinity));
assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, 0, -Infinity));
assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, -Infinity));
assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, 0, -Infinity));
assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, 0, 0, -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"
    ]
  ],
  [
    "infinite hour",
    [O(2, "year"), O(1, "month"), O(1, "day"), O(-Infinity, "hour"), O(1, "minute"), O(1, "second"), O(1, "millisecond"), O(1, "microsecond"), O(1, "nanosecond")],
    [
      "get year.valueOf",
      "call year.valueOf",
      "get month.valueOf",
      "call month.valueOf",
      "get day.valueOf",
      "call day.valueOf",
      "get hour.valueOf",
      "call hour.valueOf"
    ]
  ],
  [
    "infinite minute",
    [O(2, "year"), O(1, "month"), O(1, "day"), O(1, "hour"), O(-Infinity, "minute"), O(1, "second"), O(1, "millisecond"), O(1, "microsecond"), O(1, "nanosecond")],
    [
      "get year.valueOf",
      "call year.valueOf",
      "get month.valueOf",
      "call month.valueOf",
      "get day.valueOf",
      "call day.valueOf",
      "get hour.valueOf",
      "call hour.valueOf",
      "get minute.valueOf",
      "call minute.valueOf"
    ]
  ],
  [
    "infinite second",
    [O(2, "year"), O(1, "month"), O(1, "day"), O(1, "hour"), O(1, "minute"), O(-Infinity, "second"), O(1, "millisecond"), O(1, "microsecond"), O(1, "nanosecond")],
    [
      "get year.valueOf",
      "call year.valueOf",
      "get month.valueOf",
      "call month.valueOf",
      "get day.valueOf",
      "call day.valueOf",
      "get hour.valueOf",
      "call hour.valueOf",
      "get minute.valueOf",
      "call minute.valueOf",
      "get second.valueOf",
      "call second.valueOf"
    ]
  ],
  [
    "infinite millisecond",
    [O(2, "year"), O(1, "month"), O(1, "day"), O(1, "hour"), O(1, "minute"), O(1, "second"), O(-Infinity, "millisecond"), O(1, "microsecond"), O(1, "nanosecond")],
    [
      "get year.valueOf",
      "call year.valueOf",
      "get month.valueOf",
      "call month.valueOf",
      "get day.valueOf",
      "call day.valueOf",
      "get hour.valueOf",
      "call hour.valueOf",
      "get minute.valueOf",
      "call minute.valueOf",
      "get second.valueOf",
      "call second.valueOf",
      "get millisecond.valueOf",
      "call millisecond.valueOf"
    ]
  ],
  [
    "infinite microsecond",
    [O(2, "year"), O(1, "month"), O(1, "day"), O(1, "hour"), O(1, "minute"), O(1, "second"), O(1, "millisecond"), O(-Infinity, "microsecond"), O(1, "nanosecond")],
    [
      "get year.valueOf",
      "call year.valueOf",
      "get month.valueOf",
      "call month.valueOf",
      "get day.valueOf",
      "call day.valueOf",
      "get hour.valueOf",
      "call hour.valueOf",
      "get minute.valueOf",
      "call minute.valueOf",
      "get second.valueOf",
      "call second.valueOf",
      "get millisecond.valueOf",
      "call millisecond.valueOf",
      "get microsecond.valueOf",
      "call microsecond.valueOf"
    ]
  ],
  [
    "infinite nanosecond",
    [O(2, "year"), O(1, "month"), O(1, "day"), O(1, "hour"), O(1, "minute"), O(1, "second"), O(1, "millisecond"), O(1, "microsecond"), O(-Infinity, "nanosecond")],
    [
      "get year.valueOf",
      "call year.valueOf",
      "get month.valueOf",
      "call month.valueOf",
      "get day.valueOf",
      "call day.valueOf",
      "get hour.valueOf",
      "call hour.valueOf",
      "get minute.valueOf",
      "call minute.valueOf",
      "get second.valueOf",
      "call second.valueOf",
      "get millisecond.valueOf",
      "call millisecond.valueOf",
      "get microsecond.valueOf",
      "call microsecond.valueOf",
      "get nanosecond.valueOf",
      "call nanosecond.valueOf"
    ]
  ],
];

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

reportCompare(0, 0);