overflow-invalid-string.js (2052B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 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.zoneddatetime.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-totemporalzoneddatetime steps 2–3: 17 2. If Type(_item_) is Object, then 18 ... 19 j. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). 20 3. Else, 21 a. Perform ? ToTemporalOverflow(_options_). 22 sec-temporal.zoneddatetime.from steps 2–3: 23 2. If Type(_item_) is Object and _item_ has an [[InitializedTemporalZonedDateTime]] internal slot, then 24 a. Perform ? ToTemporalOverflow(_options_). 25 ... 26 d. Return ... 27 3. Return ? ToTemporalZonedDateTime(_item_, _options_). 28 features: [Temporal] 29 ---*/ 30 31 const validValues = [ 32 new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC"), 33 { year: 2000, month: 5, day: 2, hour: 12, timeZone: "UTC" }, 34 "2001-09-09T01:46:40.987654321+00:00[UTC]", 35 ]; 36 37 const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"]; 38 for (const value of validValues) { 39 for (const overflow of badOverflows) { 40 assert.throws( 41 RangeError, 42 () => Temporal.ZonedDateTime.from(value, { overflow }), 43 `invalid overflow ("${overflow}")` 44 ); 45 } 46 } 47 48 reportCompare(0, 0);