| 1 |
// |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2023 Igalia, S.L. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-temporal.duration.compare |
| 7 |
description: Duration-like argument that is out of range |
| 8 |
features: [Temporal] |
| 9 |
---*/ |
| 10 |
|
| 11 |
const cases = [ |
| 12 |
// 2^32 = 4294967296 |
| 13 |
["P4294967296Y", "string with years > max"], |
| 14 |
[{ years: 4294967296 }, "property bag with years > max"], |
| 15 |
["-P4294967296Y", "string with years < min"], |
| 16 |
[{ years: -4294967296 }, "property bag with years < min"], |
| 17 |
["P4294967296M", "string with months > max"], |
| 18 |
[{ months: 4294967296 }, "property bag with months > max"], |
| 19 |
["-P4294967296M", "string with months < min"], |
| 20 |
[{ months: -4294967296 }, "property bag with months < min"], |
| 21 |
["P4294967296W", "string with weeks > max"], |
| 22 |
[{ weeks: 4294967296 }, "property bag with weeks > max"], |
| 23 |
["-P4294967296W", "string with weeks < min"], |
| 24 |
[{ weeks: -4294967296 }, "property bag with weeks < min"], |
| 25 |
|
| 26 |
// ceil(max safe integer / 86400) = 104249991375 |
| 27 |
["P104249991375D", "string with days > max"], |
| 28 |
[{ days: 104249991375 }, "property bag with days > max"], |
| 29 |
["P104249991374DT24H", "string where hours balance into days > max"], |
| 30 |
[{ days: 104249991374, hours: 24 }, "property bag where hours balance into days > max"], |
| 31 |
["-P104249991375D", "string with days < min"], |
| 32 |
[{ days: -104249991375 }, "property bag with days < min"], |
| 33 |
["-P104249991374DT24H", "string where hours balance into days < min"], |
| 34 |
[{ days: -104249991374, hours: -24 }, "property bag where hours balance into days < min"], |
| 35 |
|
| 36 |
// ceil(max safe integer / 3600) = 2501999792984 |
| 37 |
["PT2501999792984H", "string with hours > max"], |
| 38 |
[{ hours: 2501999792984 }, "property bag with hours > max"], |
| 39 |
["PT2501999792983H60M", "string where minutes balance into hours > max"], |
| 40 |
[{ hours: 2501999792983, minutes: 60 }, "property bag where minutes balance into hours > max"], |
| 41 |
["-PT2501999792984H", "string with hours < min"], |
| 42 |
[{ hours: -2501999792984 }, "property bag with hours < min"], |
| 43 |
["-PT2501999792983H60M", "string where minutes balance into hours < min"], |
| 44 |
[{ hours: -2501999792983, minutes: -60 }, "property bag where minutes balance into hours < min"], |
| 45 |
|
| 46 |
// ceil(max safe integer / 60) = 150119987579017 |
| 47 |
["PT150119987579017M", "string with minutes > max"], |
| 48 |
[{ minutes: 150119987579017 }, "property bag with minutes > max"], |
| 49 |
["PT150119987579016M60S", "string where seconds balance into minutes > max"], |
| 50 |
[{ minutes: 150119987579016, seconds: 60 }, "property bag where seconds balance into minutes > max"], |
| 51 |
["-PT150119987579017M", "string with minutes < min"], |
| 52 |
[{ minutes: -150119987579017 }, "property bag with minutes < min"], |
| 53 |
["-PT150119987579016M60S", "string where seconds balance into minutes < min"], |
| 54 |
[{ minutes: -150119987579016, seconds: -60 }, "property bag where seconds balance into minutes < min"], |
| 55 |
|
| 56 |
// 2^53 = 9007199254740992 |
| 57 |
["PT9007199254740992S", "string with seconds > max"], |
| 58 |
[{ seconds: 9007199254740992 }, "property bag with seconds > max"], |
| 59 |
[{ seconds: 9007199254740991, milliseconds: 1000 }, "property bag where milliseconds balance into seconds > max"], |
| 60 |
[{ seconds: 9007199254740991, microseconds: 1000000 }, "property bag where microseconds balance into seconds > max"], |
| 61 |
[{ seconds: 9007199254740991, nanoseconds: 1000000000 }, "property bag where nanoseconds balance into seconds > max"], |
| 62 |
["-PT9007199254740992S", "string with seconds < min"], |
| 63 |
[{ seconds: -9007199254740992 }, "property bag with seconds < min"], |
| 64 |
[{ seconds: -9007199254740991, milliseconds: -1000 }, "property bag where milliseconds balance into seconds < min"], |
| 65 |
[{ seconds: -9007199254740991, microseconds: -1000000 }, "property bag where microseconds balance into seconds < min"], |
| 66 |
[{ seconds: -9007199254740991, nanoseconds: -1000000000 }, "property bag where nanoseconds balance into seconds < min"], |
| 67 |
]; |
| 68 |
|
| 69 |
for (const [arg, descr] of cases) { |
| 70 |
assert.throws(RangeError, () => Temporal.Duration.compare(arg, new Temporal.Duration()), `${descr} is out of range (first argument)`); |
| 71 |
assert.throws(RangeError, () => Temporal.Duration.compare(new Temporal.Duration(), arg), `${descr} is out of range (second argument)`); |
| 72 |
} |
| 73 |
|
| 74 |
reportCompare(0, 0); |