| 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.from |
| 7 |
description: Duration-like argument that is out of range |
| 8 |
features: [Temporal] |
| 9 |
---*/ |
| 10 |
|
| 11 |
const cases = [ |
| 12 |
// ceil(max safe integer / 86400) = 104249991375 |
| 13 |
["P104249991375D", "string with days > max"], |
| 14 |
[{ days: 104249991375 }, "property bag with days > max"], |
| 15 |
["P104249991374DT24H", "string where hours balance into days > max"], |
| 16 |
[{ days: 104249991374, hours: 24 }, "property bag where hours balance into days > max"], |
| 17 |
["-P104249991375D", "string with days < min"], |
| 18 |
[{ days: -104249991375 }, "property bag with days < min"], |
| 19 |
["-P104249991374DT24H", "string where hours balance into days < min"], |
| 20 |
[{ days: -104249991374, hours: -24 }, "property bag where hours balance into days < min"], |
| 21 |
|
| 22 |
// ceil(max safe integer / 3600) = 2501999792984 |
| 23 |
["PT2501999792984H", "string with hours > max"], |
| 24 |
[{ hours: 2501999792984 }, "property bag with hours > max"], |
| 25 |
["PT2501999792983H60M", "string where minutes balance into hours > max"], |
| 26 |
[{ hours: 2501999792983, minutes: 60 }, "property bag where minutes balance into hours > max"], |
| 27 |
["-PT2501999792984H", "string with hours < min"], |
| 28 |
[{ hours: -2501999792984 }, "property bag with hours < min"], |
| 29 |
["-PT2501999792983H60M", "string where minutes balance into hours < min"], |
| 30 |
[{ hours: -2501999792983, minutes: -60 }, "property bag where minutes balance into hours < min"], |
| 31 |
|
| 32 |
// ceil(max safe integer / 60) = 150119987579017 |
| 33 |
["PT150119987579017M", "string with minutes > max"], |
| 34 |
[{ minutes: 150119987579017 }, "property bag with minutes > max"], |
| 35 |
["PT150119987579016M60S", "string where seconds balance into minutes > max"], |
| 36 |
[{ minutes: 150119987579016, seconds: 60 }, "property bag where seconds balance into minutes > max"], |
| 37 |
["-PT150119987579017M", "string with minutes < min"], |
| 38 |
[{ minutes: -150119987579017 }, "property bag with minutes < min"], |
| 39 |
["-PT150119987579016M60S", "string where seconds balance into minutes < min"], |
| 40 |
[{ minutes: -150119987579016, seconds: -60 }, "property bag where seconds balance into minutes < min"], |
| 41 |
|
| 42 |
// 2^53 = 9007199254740992 |
| 43 |
["PT9007199254740992S", "string with seconds > max"], |
| 44 |
[{ seconds: 9007199254740992 }, "property bag with seconds > max"], |
| 45 |
[{ seconds: 9007199254740991, milliseconds: 1000 }, "property bag where milliseconds balance into seconds > max"], |
| 46 |
[{ seconds: 9007199254740991, microseconds: 1000000 }, "property bag where microseconds balance into seconds > max"], |
| 47 |
[{ seconds: 9007199254740991, nanoseconds: 1000000000 }, "property bag where nanoseconds balance into seconds > max"], |
| 48 |
["-PT9007199254740992S", "string with seconds < min"], |
| 49 |
[{ seconds: -9007199254740992 }, "property bag with seconds < min"], |
| 50 |
[{ seconds: -9007199254740991, milliseconds: -1000 }, "property bag where milliseconds balance into seconds < min"], |
| 51 |
[{ seconds: -9007199254740991, microseconds: -1000000 }, "property bag where microseconds balance into seconds < min"], |
| 52 |
[{ seconds: -9007199254740991, nanoseconds: -1000000000 }, "property bag where nanoseconds balance into seconds < min"], |
| 53 |
]; |
| 54 |
|
| 55 |
for (const [arg, descr] of cases) { |
| 56 |
assert.throws(RangeError, () => Temporal.Duration.from(arg), `${descr} is out of range`); |
| 57 |
} |
| 58 |
|
| 59 |
reportCompare(0, 0); |