constructor-options-toobject.js (1335B)
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-createdatetimeformat 6 description: > 7 Tests that Intl.DateTimeFormat contructor converts the options argument 8 to an object using `ToObject` (7.1.13). 9 10 ---*/ 11 12 const toObjectResults = [ 13 [true, new Boolean(true)], 14 [42, new Number(42)], 15 ['foo', new String('foo')], 16 [{}, {}], 17 [Symbol(), Object(Symbol())] 18 ]; 19 20 // Test if ToObject is used to convert primitives to Objects. 21 toObjectResults.forEach(pair => { 22 const [value, result] = pair; 23 24 const actual = new Intl.DateTimeFormat(['en-US'], value).resolvedOptions(); 25 const expected = new Intl.DateTimeFormat(['en-US'], result).resolvedOptions(); 26 27 assert.sameValue(actual.locale, expected.locale); 28 assert.sameValue(actual.calendar, expected.calendar); 29 assert.sameValue(actual.day, expected.day); 30 assert.sameValue(actual.month, expected.month); 31 assert.sameValue(actual.year, expected.year); 32 assert.sameValue(actual.numberingSystem, expected.numberingSystem); 33 assert.sameValue(actual.timeZone, expected.timeZone); 34 }); 35 36 // ToObject throws a TypeError for undefined and null, but it's not called 37 // when options is undefined. 38 assert.throws(TypeError, () => new Intl.DateTimeFormat(['en-US'], null)); 39 40 reportCompare(0, 0);