| 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 |
esid: sec-temporal.plaindatetime.from |
| 7 |
description: RangeError thrown when overflow option not one of the allowed string values |
| 8 |
info: | |
| 9 |
sec-getoption step 10: |
| 10 |
10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception. |
| 11 |
sec-temporal-totemporaloverflow step 1: |
| 12 |
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*). |
| 13 |
sec-temporal-interprettemporaldatetimefields steps 2–3: |
| 14 |
2. Let _temporalDate_ be ? DateFromFields(_calendar_, _fields_, _options_). |
| 15 |
3. Let _overflow_ be ? ToTemporalOverflow(_options_). |
| 16 |
sec-temporal-totemporaldatetime steps 2–3: |
| 17 |
2. If Type(_item_) is Object, then |
| 18 |
... |
| 19 |
g. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). |
| 20 |
3. Else, |
| 21 |
a. Perform ? ToTemporalOverflow(_options_). |
| 22 |
sec-temporal.plaindatetime.from steps 2–3: |
| 23 |
2. If Type(_item_) is Object and _item_ has an [[InitializedTemporalDateTime]] internal slot, then |
| 24 |
a. Perform ? ToTemporalOverflow(_options_). |
| 25 |
b. Return ... |
| 26 |
3. Return ? ToTemporalDateTime(_item_, _options_). |
| 27 |
features: [Temporal] |
| 28 |
---*/ |
| 29 |
|
| 30 |
const validValues = [ |
| 31 |
new Temporal.PlainDateTime(2000, 5, 2, 12), |
| 32 |
new Temporal.PlainDate(2000, 5, 2), |
| 33 |
new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"), |
| 34 |
{ year: 2000, month: 5, day: 2, hour: 12 }, |
| 35 |
"2000-05-02T12:00", |
| 36 |
]; |
| 37 |
|
| 38 |
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"]; |
| 39 |
for (const value of validValues) { |
| 40 |
for (const overflow of badOverflows) { |
| 41 |
assert.throws( |
| 42 |
RangeError, |
| 43 |
() => Temporal.PlainDateTime.from(value, { overflow }), |
| 44 |
`invalid overflow ("${overflow}")` |
| 45 |
); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
reportCompare(0, 0); |