tor-browser

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

constructor-options-language-invalid.js (2063B)


      1 // Copyright 2018 André Bargull; 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-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    10. If options is undefined, then
     12    11. Else
     13        a. Let options be ? ToObject(options).
     14    12. Set tag to ? ApplyOptionsToTag(tag, options).
     15 
     16    ApplyOptionsToTag( tag, options )
     17    ...
     18    4. If language is not undefined, then
     19        a. If language does not match the language production, throw a RangeError exception.
     20    ...
     21 
     22 features: [Intl.Locale]
     23 ---*/
     24 
     25 /*
     26 language      = 2*3ALPHA            ; shortest ISO 639 code
     27                 ["-" extlang]       ; sometimes followed by
     28                                     ; extended language subtags
     29               / 4ALPHA              ; or reserved for future use
     30               / 5*8ALPHA            ; or registered language subtag
     31 
     32 extlang       = 3ALPHA              ; selected ISO 639 codes
     33                 *2("-" 3ALPHA)      ; permanently reserved
     34 */
     35 const invalidLanguageOptions = [
     36  "",
     37  "a",
     38  "ab7",
     39  "notalanguage",
     40  "undefined",
     41 
     42  // "root" is treated as a special `unicode_language_subtag`, but is not
     43  // actually one and is not valid in a Unicode BCP 47 locale identifier.
     44  // https://unicode.org/reports/tr35/#unicode_bcp47_locale_id
     45  "root",
     46 
     47  // Value contains more than just the 'language' production.
     48  "fr-Latn",
     49  "fr-FR",
     50  "sa-vaidika",
     51  "fr-a-asdf",
     52  "fr-x-private",
     53 
     54  // Irregular grandfathered language tag.
     55  "i-klingon",
     56 
     57  // Regular grandfathered language tag.
     58  "zh-min",
     59  "zh-min-nan",
     60 
     61  // Reserved with extended language subtag
     62  "abcd-US",
     63  "abcde-US",
     64  "abcdef-US",
     65  "abcdefg-US",
     66  "abcdefgh-US",
     67 
     68  7,
     69 ];
     70 for (const language of invalidLanguageOptions) {
     71  assert.throws(RangeError, function() {
     72    new Intl.Locale("en", {language});
     73  }, `new Intl.Locale("en", {language: "${language}"}) throws RangeError`);
     74 }
     75 
     76 reportCompare(0, 0);