tor-browser

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

getters-grandfathered.js (4111B)


      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    Verifies getters with grandfathered tags.
      8 info: |
      9    get Intl.Locale.prototype.baseName
     10    3. Return GetLocaleBaseName(_loc_.[[Locale]]).
     11 
     12    GetLocaleBaseName
     13    2. Return the longest prefix of _locale_ matched by the
     14       <code>unicode_language_id</code> Unicode locale nonterminal.
     15 
     16    get Intl.Locale.prototype.language
     17    3. Return GetLocaleLanguage(_loc_.[[Locale]]).
     18 
     19    GetLocaleLanguage
     20    1. Let _baseName_ be GetLocaleBaseName(_locale_).
     21    2. Assert: The first subtag of _baseName_ can be matched by the
     22       <code>unicode_language_subtag</code> Unicode locale nonterminal.
     23    3. Return the first subtag of _baseName_.
     24 
     25    get Intl.Locale.prototype.script
     26    3. Return GetLocaleScript(_loc_.[[Locale]]).
     27 
     28    GetLocaleScript
     29    1. Let _baseName_ be GetLocaleBaseName(_locale_).
     30    2. Assert: _baseName_ contains at most one subtag that can be matched by the
     31       <code>unicode_script_subtag</code> Unicode locale nonterminal.
     32    3. If _baseName_ contains a subtag matched by the
     33       <code>unicode_script_subtag</code> Unicode locale nonterminal, return
     34       that subtag.
     35    4. Return *undefined*.
     36 
     37    get Intl.Locale.prototype.region
     38    3. Return GetLocaleRegion(_loc_.[[Locale]]).
     39 
     40    GetLocaleRegion
     41    1. Let _baseName_ be GetLocaleBaseName(_locale_).
     42    2. NOTE: A <code>unicode_region_subtag</code> subtag is only valid
     43       immediately after an initial <code>unicode_language_subtag</code> subtag,
     44       optionally with a single <code>unicode_script_subtag</code> subtag
     45       between them. In that position, <code>unicode_region_subtag</code> cannot
     46       be confused with any other valid subtag because all their productions are
     47       disjoint.
     48    3. Assert: The first subtag of _baseName_ can be matched by the
     49       <code>unicode_language_subtag</code> Unicode locale nonterminal.
     50    4. Let _baseNameTail_ be the suffix of _baseName_ following the first
     51       subtag.
     52    5. Assert: _baseNameTail_ contains at most one subtag that can be matched by
     53       the <code>unicode_region_subtag</code> Unicode locale nonterminal.
     54    6. If _baseNameTail_ contains a subtag matched by the
     55       <code>unicode_region_subtag</code> Unicode locale nonterminal, return
     56       that subtag.
     57    7. Return *undefined*.
     58 
     59    get Intl.Locale.prototype.variants
     60    3. Return GetLocaleVariants(_loc_.[[Locale]]).
     61 
     62    GetLocaleVariants
     63    1. Let _baseName_ be GetLocaleBaseName(_locale_).
     64    2. NOTE: Each subtag in _baseName_ that is preceded by *"-"* is either a
     65       <code>unicode_script_subtag</code>, <code>unicode_region_subtag</code>,
     66       or <code>unicode_variant_subtag</code>, but any substring matched by
     67       <code>unicode_variant_subtag</code> is strictly longer than any prefix
     68       thereof which could also be matched by one of the other productions.
     69    3. Let _variants_ be the longest suffix of _baseName_ that starts with a
     70       *"-"* followed by a <emu-not-ref>substring</emu-not-ref> that is matched
     71       by the <code>unicode_variant_subtag</code> Unicode locale nonterminal. If
     72       there is no such suffix, return *undefined*.
     73    4. Return the substring of _variants_ from 1.
     74 features: [Intl.Locale]
     75 ---*/
     76 
     77 // Regular grandfathered language tag.
     78 var loc = new Intl.Locale("cel-gaulish");
     79 assert.sameValue(loc.baseName, "xtg");
     80 assert.sameValue(loc.language, "xtg");
     81 assert.sameValue(loc.script, undefined);
     82 assert.sameValue(loc.region, undefined);
     83 assert.sameValue(loc.variants, undefined);
     84 
     85 loc = new Intl.Locale("cel", { variants: "gaulish" });
     86 assert.sameValue(loc.baseName, "xtg");
     87 assert.sameValue(loc.language, "xtg");
     88 assert.sameValue(loc.script, undefined);
     89 assert.sameValue(loc.region, undefined);
     90 assert.sameValue(loc.variants, undefined);
     91 
     92 // Regular grandfathered language tag.
     93 assert.throws(RangeError, () => new Intl.Locale("zh-min"));
     94 
     95 assert.throws(RangeError, () => new Intl.Locale("i-default"));
     96 
     97 
     98 reportCompare(0, 0);