Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/PlainYearMonth/from/overflow-invalid-string.js

raw
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.plainyearmonth.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-totemporalyearmonth steps 2–3:
14 2. If Type(_item_) is Object, then
15 ...
16 e. Return ? YearMonthFromFields(_calendar_, _fields_, _options_).
17 3. Perform ? ToTemporalOverflow(_options_).
18 sec-temporal.plainyearmonth.from steps 2–3:
19 2. If Type(_item_) is Object and _item_ has an [[InitializedTemporalYearMonth]] internal slot, then
20 a. Perform ? ToTemporalOverflow(_options_).
21 b. Return ...
22 3. Return ? ToTemporalYearMonth(_item_, _options_).
23 features: [Temporal]
24 ---*/
25
26 const validValues = [
27 new Temporal.PlainYearMonth(2000, 5),
28 { year: 2000, month: 5 },
29 "2000-05",
30 ];
31
32 const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
33 for (const value of validValues) {
34 for (const overflow of badOverflows) {
35 assert.throws(
36 RangeError,
37 () => Temporal.PlainYearMonth.from(value, { overflow }),
38 `invalid overflow ("${overflow}")`
39 );
40 }
41 }
42
43 reportCompare(0, 0);