tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

overflow-invalid-string.js (1777B)


      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.plaindate.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-totemporaldate steps 2–3:
     14      2. If Type(_item_) is Object, then
     15        ...
     16        g. Return ? DateFromFields(_calendar_, _fields_, _options_).
     17      3. Perform ? ToTemporalOverflow(_options_).
     18    sec-temporal.plaindate.from steps 2–3:
     19      2. If Type(_item_) is Object and _item_ has an [[InitializedTemporalDate]] internal slot, then
     20        a. Perform ? ToTemporalOverflow(_options_).
     21        b. Return ...
     22      3. Return ? ToTemporalDate(_item_, _options_).
     23 features: [Temporal]
     24 ---*/
     25 
     26 const validItems = [
     27  new Temporal.PlainDate(2000, 5, 2),
     28  new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"),
     29  new Temporal.PlainDateTime(2000, 5, 2, 12),
     30  { year: 2000, month: 5, day: 2 },
     31  "2000-05-02",
     32 ];
     33 
     34 const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
     35 for (const item of validItems) {
     36  for (const overflow of badOverflows) {
     37    assert.throws(
     38      RangeError,
     39      () => Temporal.PlainDate.from(item, { overflow }),
     40      `invalid overflow ("${overflow}")`
     41    );
     42  }
     43 }
     44 
     45 reportCompare(0, 0);