negative-infinity-throws-rangeerror.js (5644B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2020 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 description: Temporal.PlainDateTime throws a RangeError if any value is -Infinity 7 esid: sec-temporal.plaindatetime 8 includes: [compareArray.js, temporalHelpers.js] 9 features: [Temporal] 10 ---*/ 11 12 assert.throws(RangeError, () => new Temporal.PlainDateTime(-Infinity, 1, 1)); 13 assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, -Infinity, 1)); 14 assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, -Infinity)); 15 assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, -Infinity)); 16 assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, -Infinity)); 17 assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, 0, -Infinity)); 18 assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, -Infinity)); 19 assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, 0, -Infinity)); 20 assert.throws(RangeError, () => new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, 0, 0, -Infinity)); 21 22 const O = (primitiveValue, propertyName) => (calls) => TemporalHelpers.toPrimitiveObserver(calls, primitiveValue, propertyName); 23 const tests = [ 24 [ 25 "infinite year", 26 [O(-Infinity, "year"), O(1, "month"), O(1, "day")], 27 ["get year.valueOf", "call year.valueOf" 28 ] 29 ], 30 [ 31 "infinite month", 32 [O(2, "year"), O(-Infinity, "month"), O(1, "day")], 33 ["get year.valueOf", "call year.valueOf", "get month.valueOf", "call month.valueOf" 34 ] 35 ], 36 [ 37 "infinite day", 38 [O(2, "year"), O(1, "month"), O(-Infinity, "day")], 39 ["get year.valueOf", "call year.valueOf", "get month.valueOf", "call month.valueOf", "get day.valueOf", "call day.valueOf" 40 ] 41 ], 42 [ 43 "infinite hour", 44 [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")], 45 [ 46 "get year.valueOf", 47 "call year.valueOf", 48 "get month.valueOf", 49 "call month.valueOf", 50 "get day.valueOf", 51 "call day.valueOf", 52 "get hour.valueOf", 53 "call hour.valueOf" 54 ] 55 ], 56 [ 57 "infinite minute", 58 [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")], 59 [ 60 "get year.valueOf", 61 "call year.valueOf", 62 "get month.valueOf", 63 "call month.valueOf", 64 "get day.valueOf", 65 "call day.valueOf", 66 "get hour.valueOf", 67 "call hour.valueOf", 68 "get minute.valueOf", 69 "call minute.valueOf" 70 ] 71 ], 72 [ 73 "infinite second", 74 [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")], 75 [ 76 "get year.valueOf", 77 "call year.valueOf", 78 "get month.valueOf", 79 "call month.valueOf", 80 "get day.valueOf", 81 "call day.valueOf", 82 "get hour.valueOf", 83 "call hour.valueOf", 84 "get minute.valueOf", 85 "call minute.valueOf", 86 "get second.valueOf", 87 "call second.valueOf" 88 ] 89 ], 90 [ 91 "infinite millisecond", 92 [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")], 93 [ 94 "get year.valueOf", 95 "call year.valueOf", 96 "get month.valueOf", 97 "call month.valueOf", 98 "get day.valueOf", 99 "call day.valueOf", 100 "get hour.valueOf", 101 "call hour.valueOf", 102 "get minute.valueOf", 103 "call minute.valueOf", 104 "get second.valueOf", 105 "call second.valueOf", 106 "get millisecond.valueOf", 107 "call millisecond.valueOf" 108 ] 109 ], 110 [ 111 "infinite microsecond", 112 [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")], 113 [ 114 "get year.valueOf", 115 "call year.valueOf", 116 "get month.valueOf", 117 "call month.valueOf", 118 "get day.valueOf", 119 "call day.valueOf", 120 "get hour.valueOf", 121 "call hour.valueOf", 122 "get minute.valueOf", 123 "call minute.valueOf", 124 "get second.valueOf", 125 "call second.valueOf", 126 "get millisecond.valueOf", 127 "call millisecond.valueOf", 128 "get microsecond.valueOf", 129 "call microsecond.valueOf" 130 ] 131 ], 132 [ 133 "infinite nanosecond", 134 [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")], 135 [ 136 "get year.valueOf", 137 "call year.valueOf", 138 "get month.valueOf", 139 "call month.valueOf", 140 "get day.valueOf", 141 "call day.valueOf", 142 "get hour.valueOf", 143 "call hour.valueOf", 144 "get minute.valueOf", 145 "call minute.valueOf", 146 "get second.valueOf", 147 "call second.valueOf", 148 "get millisecond.valueOf", 149 "call millisecond.valueOf", 150 "get microsecond.valueOf", 151 "call microsecond.valueOf", 152 "get nanosecond.valueOf", 153 "call nanosecond.valueOf" 154 ] 155 ], 156 ]; 157 158 for (const [description, args, expected] of tests) { 159 const actual = []; 160 const args_ = args.map((o) => o(actual)); 161 assert.throws(RangeError, () => new Temporal.PlainDateTime(...args_), description); 162 assert.compareArray(actual, expected, `${description} order of operations`); 163 } 164 165 reportCompare(0, 0);