tor-browser

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

options-fallback-toString-abrupt-throws.js (1867B)


      1 // Copyright (C) 2019 Leo Balter. 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 GetOption fallback
      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  10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long").
     20  ...
     21  12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
     22  13. If type is undefined, throw a TypeError exception.
     23 
     24  GetOption ( options, property, type, values, fallback )
     25 
     26  1. Let value be ? Get(options, property).
     27  ...
     28 features: [Intl.DisplayNames, Symbol]
     29 locale: [en]
     30 ---*/
     31 
     32 assert.throws(Test262Error, () => {
     33  new Intl.DisplayNames('en', {
     34    type: 'language', fallback: { toString() { throw new Test262Error(); }}
     35  });
     36 }, 'from toString');
     37 
     38 assert.throws(Test262Error, () => {
     39  new Intl.DisplayNames('en', {
     40    type: 'language',
     41    fallback: {toString: undefined, valueOf() {throw new Test262Error(); }}
     42  });
     43 }, 'from valueOf');
     44 
     45 assert.throws(Test262Error, () => {
     46  new Intl.DisplayNames('en', {
     47    type: 'language',
     48    fallback: { [Symbol.toPrimitive]() { throw new Test262Error(); } }
     49  });
     50 }, 'from ToPrimitive');
     51 
     52 assert.throws(TypeError, () => {
     53  new Intl.DisplayNames('en', {
     54    type: 'language',
     55    fallback: Symbol()
     56  });
     57 }, 'symbol value');
     58 
     59 reportCompare(0, 0);