tor-browser

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

constructor-options-toobject.js (1511B)


      1 // Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-initializenumberformat
      6 description: >
      7  Tests that Intl.NumberFormat contructor converts the options argument
      8  to an object using `ToObject` (7.1.13).
      9 info: |
     10  11.1.2 InitializeNumberFormat
     11 
     12  3.a. Let options be ? ToObject(options).
     13 ---*/
     14 
     15 const toObjectResults = [
     16  [true, new Boolean(true)],
     17  [42, new Number(42)],
     18  ['foo', new String('foo')],
     19  [{}, {}],
     20  [Symbol(), Object(Symbol())]
     21 ];
     22 
     23 // Test if ToObject is used to convert primitives to Objects.
     24 toObjectResults.forEach(pair => {
     25  const [value, result] = pair;
     26  const actual = new Intl.NumberFormat(['en-US'], value).resolvedOptions();
     27  const expected = new Intl.NumberFormat(['en-US'], result).resolvedOptions();
     28  assert.sameValue(actual.locale, expected.locale);
     29  assert.sameValue(actual.minimumIntegerDigits, expected.minimumIntegerDigits);
     30  assert.sameValue(actual.minimumFractionDigits, expected.minimumFractionDigits);
     31  assert.sameValue(actual.maximumFractionDigits, expected.maximumFractionDigits);
     32  assert.sameValue(actual.numberingSystem, expected.numberingSystem);
     33  assert.sameValue(actual.style, expected.style);
     34  assert.sameValue(actual.useGrouping, expected.useGrouping);
     35 
     36 });
     37 
     38 // ToObject throws a TypeError for undefined and null, but it's not called
     39 // when options is undefined.
     40 assert.throws(TypeError, () => new Intl.NumberFormat(['en-US'], null));
     41 
     42 reportCompare(0, 0);