| 1 |
// |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2021 Igalia, S.L. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
description: Throws if any value in a property bag for either argument is Infinity or -Infinity |
| 7 |
esid: sec-temporal.plaindatetime.compare |
| 8 |
includes: [compareArray.js, temporalHelpers.js] |
| 9 |
features: [Temporal] |
| 10 |
---*/ |
| 11 |
|
| 12 |
const other = new Temporal.PlainDateTime(2000, 5, 2, 15); |
| 13 |
const base = { year: 2000, month: 5, day: 2, hour: 15, minute: 30, second: 45, millisecond: 987, microsecond: 654, nanosecond: 321 }; |
| 14 |
|
| 15 |
[Infinity, -Infinity].forEach((inf) => { |
| 16 |
["year", "month", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond"].forEach((prop) => { |
| 17 |
assert.throws(RangeError, () => Temporal.PlainDateTime.compare({ ...base, [prop]: inf }, other), `${prop} property cannot be ${inf}`); |
| 18 |
|
| 19 |
assert.throws(RangeError, () => Temporal.PlainDateTime.compare(other, { ...base, [prop]: inf }), `${prop} property cannot be ${inf}`); |
| 20 |
|
| 21 |
const calls1 = []; |
| 22 |
const obj1 = TemporalHelpers.toPrimitiveObserver(calls1, inf, prop); |
| 23 |
assert.throws(RangeError, () => Temporal.PlainDateTime.compare({ ...base, [prop]: obj1 }, other)); |
| 24 |
assert.compareArray(calls1, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value"); |
| 25 |
|
| 26 |
const calls2 = []; |
| 27 |
const obj2 = TemporalHelpers.toPrimitiveObserver(calls2, inf, prop); |
| 28 |
assert.throws(RangeError, () => Temporal.PlainDateTime.compare(other, { ...base, [prop]: obj2 })); |
| 29 |
assert.compareArray(calls2, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value"); |
| 30 |
}); |
| 31 |
}); |
| 32 |
|
| 33 |
reportCompare(0, 0); |