tor-browser

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

constructor-options-style-conflict.js (1753B)


      1 // Copyright 2023 Igalia, S.L. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-isvaliddurationrecord
      6 description: Checks that the "long", "short", and "narrow" styles can't be used for units following a unit using the "numeric" or "2-digit" style.
      7 info: |
      8    GetDurationUnitOptions (unit, options, baseStyle, stylesList, digitalBase, prevStyle)
      9    (...)
     10    6. If prevStyle is "numeric" or "2-digit", then
     11    a. If style is not "numeric" or "2-digit", then
     12        i. Throw a RangeError exception.
     13 features: [Intl.DurationFormat]
     14 ---*/
     15 
     16 let invalidOptions = {};
     17 for (const timeUnit of ["hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"]){
     18  invalidOptions[timeUnit] = "numeric";
     19 }
     20 
     21 for (const timeUnit of ["minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"]){
     22  for (const invalidStyle of ["long", "short", "narrow"]){
     23    invalidOptions[timeUnit] = invalidStyle;
     24    assert.throws(RangeError, function() {
     25      new Intl.DurationFormat([], invalidOptions);
     26    }, `${invalidStyle} is an invalid style option value when following a unit with \"numeric\" style`);
     27  }
     28  invalidOptions[timeUnit] = "numeric";
     29 }
     30 
     31 for (const timeUnit of ["hours", "minutes", "seconds"]){
     32  invalidOptions[timeUnit] = "2-digit";
     33 }
     34 
     35 for (const timeUnit of ["minutes", "seconds", "milliseconds"]){
     36  for (const invalidStyle of ["long", "short", "narrow"]){
     37    invalidOptions[timeUnit] = invalidStyle;
     38    assert.throws(RangeError, function() {
     39      new Intl.DurationFormat([], invalidOptions);
     40    }, `${invalidStyle} is an invalid style option value when following a unit with \"2-digit\" style`);
     41  }
     42  invalidOptions[timeUnit] = "2-digit";
     43 }
     44 
     45 reportCompare(0, 0);