summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/DateTimeFormat/constructor-options-toobject.js
blob: 6f449b023b8a7cc2dc29e479140c379259566a7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-createdatetimeformat
description: >
  Tests that Intl.DateTimeFormat contructor converts the options argument
  to an object using `ToObject` (7.1.13).

---*/

const toObjectResults = [
  [true, new Boolean(true)],
  [42, new Number(42)],
  ['foo', new String('foo')],
  [{}, {}],
  [Symbol(), Object(Symbol())]
];

// Test if ToObject is used to convert primitives to Objects.
toObjectResults.forEach(pair => {
  const [value, result] = pair;

  const actual = new Intl.DateTimeFormat(['en-US'], value).resolvedOptions();
  const expected = new Intl.DateTimeFormat(['en-US'], result).resolvedOptions();

  assert.sameValue(actual.locale, expected.locale);
  assert.sameValue(actual.calendar, expected.calendar);
  assert.sameValue(actual.day, expected.day);
  assert.sameValue(actual.month, expected.month);
  assert.sameValue(actual.year, expected.year);
  assert.sameValue(actual.numberingSystem, expected.numberingSystem);
  assert.sameValue(actual.timeZone, expected.timeZone);
});

// ToObject throws a TypeError for undefined and null, but it's not called
// when options is undefined.
assert.throws(TypeError, () => new Intl.DateTimeFormat(['en-US'], null));

reportCompare(0, 0);