tor-browser

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

options-localeMatcher-toString-abrupt-throws.js (1698B)


      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 localeMatcher
      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. If options is undefined, then
     16    a. Let options be ObjectCreate(null).
     17  5. Else
     18    a. Let options be ? ToObject(options).
     19  ...
     20  8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
     21 
     22  GetOption ( options, property, type, values, fallback )
     23 
     24  1. Let value be ? Get(options, property).
     25  ...
     26 features: [Intl.DisplayNames, Symbol]
     27 locale: [en]
     28 ---*/
     29 
     30 var options = {
     31  localeMatcher: {
     32    toString() {
     33      throw new Test262Error();
     34    }
     35  }
     36 };
     37 
     38 assert.throws(Test262Error, () => {
     39  new Intl.DisplayNames('en', options);
     40 }, 'from toString');
     41 
     42 options.localeMatcher = {
     43  toString: undefined,
     44  valueOf() {
     45    throw new Test262Error();
     46  }
     47 };
     48 
     49 assert.throws(Test262Error, () => {
     50  new Intl.DisplayNames('en', options);
     51 }, 'from valueOf');
     52 
     53 options.localeMatcher = {
     54  [Symbol.toPrimitive]() {
     55    throw new Test262Error();
     56  }
     57 };
     58 
     59 assert.throws(Test262Error, () => {
     60  new Intl.DisplayNames('en', options);
     61 }, 'from ToPrimitive');
     62 
     63 options.localeMatcher = Symbol();
     64 
     65 assert.throws(TypeError, () => {
     66  new Intl.DisplayNames('en', options);
     67 }, 'symbol value');
     68 
     69 reportCompare(0, 0);