tor-browser

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

constructor-options-variants-invalid.js (1446B)


      1 // Copyright 2025 Richard Gibson. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-intl.locale
      6 description: >
      7    Checks error cases for the options argument to the Locale
      8    constructor.
      9 info: |
     10    Intl.Locale( tag [, options] )
     11    12. Set _tag_ to ? UpdateLanguageId(_tag_, _options_).
     12 
     13    UpdateLanguageId ( tag, options )
     14    8. Let _variants_ be ? GetOption(_options_, *"variants"*, ~string~, ~empty~, GetLocaleVariants(_baseName_)).
     15    9. If _variants_ is not *undefined*, then
     16      a. If _variants_ cannot be matched by the <code>unicode_variant_subtag</code> Unicode locale nonterminal, throw a *RangeError* exception.
     17 
     18 features: [Intl.Locale]
     19 ---*/
     20 
     21 /*
     22 unicode_variant_subtag = (alphanum{5,8} | digit alphanum{3})
     23 */
     24 const invalidVariantsOptions = [
     25  "",
     26  "a",
     27  "1",
     28  "ab",
     29  "2x",
     30  "abc",
     31  "3xy",
     32  "abcd",
     33  "abcdefghi",
     34 
     35  // Value contains more than just the 'variants' production.
     36  "GB-scouse",
     37 
     38  // Value contains duplicates.
     39  "fonipa-fonipa",
     40  "fonipa-valencia-Fonipa",
     41 
     42  // Value contains out-of-place dashes.
     43  "-",
     44  "-spanglis",
     45  "spanglis-",
     46  "-spanglis-oxendict",
     47  "spanglis-oxendict-",
     48  "spanglis--oxendict",
     49 ];
     50 for (const variants of invalidVariantsOptions) {
     51  assert.throws(RangeError, function() {
     52    new Intl.Locale("en", {variants});
     53  }, `new Intl.Locale("en", {variants: "${variants}"}) throws RangeError`);
     54 }
     55 
     56 reportCompare(0, 0);