tor-browser

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

options-languagedisplay-invalid-throws.js (2174B)


      1 // Copyright (C) 2021 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-Intl.DisplayNames
      6 description: >
      7  Return abrupt completion from an invalid fallback option
      8 info: |
      9  Intl.DisplayNames ( locales , options )
     10 
     11  1. If NewTarget is undefined, throw a TypeError exception.
     12  2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
     13    « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
     14  ...
     15  4. Let options be ? ToObject(options).
     16  ...
     17  8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
     18  ...
     19  12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », "language").
     20  13. If type is undefined, throw a TypeError exception.
     21  ...
     22  24. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", « "dialect", "standard" », "dialect").
     23  ...
     24 
     25  GetOption ( options, property, type, values, fallback )
     26 
     27  1. Let value be ? Get(options, property).
     28  2. If value is not undefined, then
     29    ...
     30    c. If type is "string", then
     31      i. Let value be ? ToString(value).
     32    d. If values is not undefined, then
     33      i. If values does not contain an element equal to value, throw a RangeError exception.
     34  ...
     35 features: [Intl.DisplayNames-v2]
     36 locale: [en]
     37 ---*/
     38 
     39 assert.throws(RangeError, () => {
     40  new Intl.DisplayNames('en', {languageDisplay: 'err', type: 'language'});
     41 }, 'err');
     42 
     43 assert.throws(RangeError, () => {
     44  new Intl.DisplayNames('en', {languageDisplay: 'standar', type: 'language'});
     45 }, 'standar, not standard');
     46 
     47 assert.throws(RangeError, () => {
     48  new Intl.DisplayNames('en', {languageDisplay: null, type: 'language'});
     49 }, 'null');
     50 
     51 assert.throws(RangeError, () => {
     52  new Intl.DisplayNames('en', {languageDisplay: '', type: 'language'});
     53 }, 'the empty string');
     54 
     55 assert.throws(RangeError, () => {
     56  new Intl.DisplayNames('en', {languageDisplay: ['dialect', 'standard'], type: 'language'});
     57 }, 'an array with the valid options is not necessarily valid');
     58 
     59 reportCompare(0, 0);