diff --git a/harness/testIntl.js b/harness/testIntl.js index fe3be6c27a..e59c2185a9 100644 --- a/harness/testIntl.js +++ b/harness/testIntl.js @@ -40,7 +40,8 @@ function testWithIntlConstructors(f) { // Optionally supported Intl constructors. // NB: Intl.Locale isn't an Intl service constructor! - ["PluralRules", "RelativeTimeFormat", "ListFormat", "DisplayNames"].forEach(function(constructor) { + // Intl.DisplayNames cannot be called without type in options. + ["PluralRules", "RelativeTimeFormat", "ListFormat"].forEach(function(constructor) { if (typeof Intl[constructor] === "function") { constructors[constructors.length] = constructor; } diff --git a/test/intl402/DisplayNames/ctor-custom-prototype.js b/test/intl402/DisplayNames/ctor-custom-prototype.js index de78c046c4..6cabaeeea1 100644 --- a/test/intl402/DisplayNames/ctor-custom-prototype.js +++ b/test/intl402/DisplayNames/ctor-custom-prototype.js @@ -6,12 +6,15 @@ esid: sec-Intl.DisplayNames description: > Custom Prototype of the returned object based on the NewTarget info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) @@ -32,6 +35,6 @@ features: [Intl.DisplayNames, Reflect] var custom = new Function(); custom.prototype = {}; -var obj = Reflect.construct(Intl.DisplayNames, [], custom); +const obj = Reflect.construct(Intl.DisplayNames, [undefined, {type: 'language'}], custom); assert.sameValue(Object.getPrototypeOf(obj), custom.prototype); diff --git a/test/intl402/DisplayNames/ctor-default-prototype.js b/test/intl402/DisplayNames/ctor-default-prototype.js index 1229eda060..2ccb1ecb9c 100644 --- a/test/intl402/DisplayNames/ctor-default-prototype.js +++ b/test/intl402/DisplayNames/ctor-default-prototype.js @@ -6,16 +6,19 @@ esid: sec-Intl.DisplayNames description: > Prototype of the returned object is DisplayNames.prototype info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... 27. Return displayNames. features: [Intl.DisplayNames] ---*/ -var obj = new Intl.DisplayNames(); +var obj = new Intl.DisplayNames(undefined, {type: 'language'}); assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype); diff --git a/test/intl402/DisplayNames/instance-extensible.js b/test/intl402/DisplayNames/instance-extensible.js index 89676f56d0..ef61dd69d3 100644 --- a/test/intl402/DisplayNames/instance-extensible.js +++ b/test/intl402/DisplayNames/instance-extensible.js @@ -6,12 +6,15 @@ esid: sec-Intl.DisplayNames description: > Instance is extensible info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) @@ -30,6 +33,6 @@ info: | features: [Intl.DisplayNames] ---*/ -var obj = new Intl.DisplayNames(); +var obj = new Intl.DisplayNames(undefined, {type: 'language'}); assert(Object.isExtensible(obj)); diff --git a/test/intl402/DisplayNames/locales-symbol-length.js b/test/intl402/DisplayNames/locales-symbol-length.js index 648db1806e..e13303c368 100644 --- a/test/intl402/DisplayNames/locales-symbol-length.js +++ b/test/intl402/DisplayNames/locales-symbol-length.js @@ -6,13 +6,16 @@ esid: sec-Intl.DisplayNames description: > CanonicalizeLocaleList tries to fetch length from Object. info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... CanonicalizeLocaleList ( locales ) @@ -29,8 +32,8 @@ locale: [en] includes: [compareArray.js] ---*/ -var calls = []; -var symbol = Symbol(); +let calls = []; +let symbol = Symbol(); Symbol.prototype.length = 1; @@ -54,6 +57,6 @@ Object.defineProperty(Symbol.prototype, '0', { } }); -new Intl.DisplayNames(symbol); +new Intl.DisplayNames(symbol, {type: 'language'}); assert.compareArray(calls, ['length', '0']); diff --git a/test/intl402/DisplayNames/options-fallback-abrupt-throws.js b/test/intl402/DisplayNames/options-fallback-abrupt-throws.js index 918bf9be6a..c049809f91 100644 --- a/test/intl402/DisplayNames/options-fallback-abrupt-throws.js +++ b/test/intl402/DisplayNames/options-fallback-abrupt-throws.js @@ -6,22 +6,16 @@ esid: sec-Intl.DisplayNames description: > Return abrupt completion from GetOption fallback info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... - 4. If options is undefined, then - a. Let options be ObjectCreate(null). - 5. Else - a. Let options be ? ToObject(options). + 4. Let options be ? ToObject(options). ... - 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - ... - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). - ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -34,7 +28,7 @@ features: [Intl.DisplayNames, Symbol] locale: [en] ---*/ -var options = {}; +var options = { type: 'language' }; Object.defineProperty(options, 'fallback', { get() { throw new Test262Error(); }, }); diff --git a/test/intl402/DisplayNames/options-fallback-invalid-throws.js b/test/intl402/DisplayNames/options-fallback-invalid-throws.js index 7e0029db0a..63cb6c62c0 100644 --- a/test/intl402/DisplayNames/options-fallback-invalid-throws.js +++ b/test/intl402/DisplayNames/options-fallback-invalid-throws.js @@ -6,22 +6,18 @@ esid: sec-Intl.DisplayNames description: > Return abrupt completion from an invalid fallback option info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... - 4. If options is undefined, then - a. Let options be ObjectCreate(null). - 5. Else - a. Let options be ? ToObject(options). + 4. Let options be ? ToObject(options). ... 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). - ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », "language"). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -40,34 +36,22 @@ features: [Intl.DisplayNames] locale: [en] ---*/ -var options = { - fallback: 'err' -}; - assert.throws(RangeError, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', {fallback: 'err', type: 'language'}); }, 'err'); -options.fallback = 'non'; - assert.throws(RangeError, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', {fallback: 'non', type: 'language'}); }, 'non, not none'); -options.fallback = null; - assert.throws(RangeError, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', {fallback: null, type: 'language'}); }, 'null'); -options.fallback = ''; - assert.throws(RangeError, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', {fallback: '', type: 'language'}); }, 'the empty string'); -options.fallback = ['code', 'none']; - assert.throws(RangeError, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', {fallback: ['code', 'none'], type: 'language'}); }, 'an array with the valid options is not necessarily valid'); diff --git a/test/intl402/DisplayNames/options-fallback-toString-abrupt-throws.js b/test/intl402/DisplayNames/options-fallback-toString-abrupt-throws.js index ad528bf86c..469239d075 100644 --- a/test/intl402/DisplayNames/options-fallback-toString-abrupt-throws.js +++ b/test/intl402/DisplayNames/options-fallback-toString-abrupt-throws.js @@ -6,21 +6,20 @@ esid: sec-Intl.DisplayNames description: > Return abrupt completion from GetOption fallback info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... - 4. If options is undefined, then - a. Let options be ObjectCreate(null). - 5. Else - a. Let options be ? ToObject(options). + 4. Let options be ? ToObject(options). ... 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. GetOption ( options, property, type, values, fallback ) @@ -30,41 +29,29 @@ features: [Intl.DisplayNames, Symbol] locale: [en] ---*/ -var options = { - fallback: { - toString() { - throw new Test262Error(); - } - } -}; - assert.throws(Test262Error, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', { + type: 'language', fallback: { toString() { throw new Test262Error(); }} + }); }, 'from toString'); -options.fallback = { - toString: undefined, - valueOf() { - throw new Test262Error(); - } -}; - assert.throws(Test262Error, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', { + type: 'language', + fallback: {toString: undefined, valueOf() {throw new Test262Error(); }} + }); }, 'from valueOf'); -options.fallback = { - [Symbol.toPrimitive]() { - throw new Test262Error(); - } -}; - assert.throws(Test262Error, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', { + type: 'language', + fallback: { [Symbol.toPrimitive]() { throw new Test262Error(); } } + }); }, 'from ToPrimitive'); -options.fallback = Symbol(); - assert.throws(TypeError, () => { - new Intl.DisplayNames('en', options); + new Intl.DisplayNames('en', { + type: 'language', + fallback: Symbol() + }); }, 'symbol value'); diff --git a/test/intl402/DisplayNames/options-fallback-valid.js b/test/intl402/DisplayNames/options-fallback-valid.js index dae06f2fdc..21efc85bdf 100644 --- a/test/intl402/DisplayNames/options-fallback-valid.js +++ b/test/intl402/DisplayNames/options-fallback-valid.js @@ -6,22 +6,20 @@ esid: sec-Intl.DisplayNames description: > Valid options for fallback info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... - 4. If options is undefined, then - a. Let options be ObjectCreate(null). - 5. Else - a. Let options be ? ToObject(options). + 4. Let options be ? ToObject(options). ... 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -36,19 +34,15 @@ locale: [en] // results for option values verified in the tests for resolvedOptions -var values = [ +const fallbacks = [ undefined, 'code', 'none' ]; -for (let valid of values) { - let options = { - fallback: valid - }; +fallbacks.forEach(fallback => { + const obj = new Intl.DisplayNames('en', { fallback, type: 'language'}); - var obj = new Intl.DisplayNames('en', options); - - assert(obj instanceof Intl.DisplayNames, `instanceof check - ${valid}`); - assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${valid}`); -} + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${fallback}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${fallback}`); +}); diff --git a/test/intl402/DisplayNames/options-localeMatcher-valid.js b/test/intl402/DisplayNames/options-localeMatcher-valid.js index e1cc5e6649..0a5f87ffae 100644 --- a/test/intl402/DisplayNames/options-localeMatcher-valid.js +++ b/test/intl402/DisplayNames/options-localeMatcher-valid.js @@ -6,22 +6,20 @@ esid: sec-Intl.DisplayNames description: > Valid options for localeMatcher info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... - 4. If options is undefined, then - a. Let options be ObjectCreate(null). - 5. Else - a. Let options be ? ToObject(options). + 4. Let options be ? ToObject(options). ... 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -36,19 +34,15 @@ locale: [en] // results for option values verified in the tests for resolvedOptions -var values = [ +const localeMatchers = [ undefined, 'lookup', 'best fit' ]; -for (let valid of values) { - let options = { - localeMatcher: valid - }; +localeMatchers.forEach(localeMatcher => { + const obj = new Intl.DisplayNames('en', { localeMatcher, type: 'language' }); - var obj = new Intl.DisplayNames('en', options); - - assert(obj instanceof Intl.DisplayNames, `instanceof check - ${valid}`); - assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${valid}`); -} + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${localeMatcher}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${localeMatcher}`); +}); diff --git a/test/intl402/DisplayNames/options-random-properties-unchecked.js b/test/intl402/DisplayNames/options-random-properties-unchecked.js index 1244c77994..7fe2618ee2 100644 --- a/test/intl402/DisplayNames/options-random-properties-unchecked.js +++ b/test/intl402/DisplayNames/options-random-properties-unchecked.js @@ -6,22 +6,20 @@ esid: sec-Intl.DisplayNames description: > Random options are not checked or used, including case sensitive info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... - 4. If options is undefined, then - a. Let options be ObjectCreate(null). - 5. Else - a. Let options be ? ToObject(options). + 4. Let options be ? ToObject(options). ... - 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -34,7 +32,7 @@ features: [Intl.DisplayNames] locale: [en] ---*/ -var options = {}; +var options = { type: 'language' }; Object.defineProperty(options, 'fallBack', { get() { throw new Test262Error(); } }); diff --git a/test/intl402/DisplayNames/options-style-valid.js b/test/intl402/DisplayNames/options-style-valid.js index 9fcd7382ec..6ff9d8d642 100644 --- a/test/intl402/DisplayNames/options-style-valid.js +++ b/test/intl402/DisplayNames/options-style-valid.js @@ -6,24 +6,18 @@ esid: sec-Intl.DisplayNames description: > Valid options for localeMatcher info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... - 4. If options is undefined, then - a. Let options be ObjectCreate(null). - 5. Else - a. Let options be ? ToObject(options). + 4. Let options be ? ToObject(options). ... - 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). - ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). - ... - 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... GetOption ( options, property, type, values, fallback ) @@ -36,20 +30,20 @@ locale: [en] // results for option values verified in the tests for resolvedOptions -var values = [ +const styles = [ undefined, 'narrow', 'short', 'long' ]; -for (let valid of values) { - let options = { - style: valid - }; +const types = ['language', 'region', 'script', 'currency']; - var obj = new Intl.DisplayNames('en', options); +types.forEach( type => { + styles.forEach(style => { + var obj = new Intl.DisplayNames('en', { style, type }); - assert(obj instanceof Intl.DisplayNames, `instanceof check - ${valid}`); - assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${valid}`); -} + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${style}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${style}`); + }); +}); diff --git a/test/intl402/DisplayNames/options-type-valid.js b/test/intl402/DisplayNames/options-type-valid.js index 22566f335d..4176a83460 100644 --- a/test/intl402/DisplayNames/options-type-valid.js +++ b/test/intl402/DisplayNames/options-type-valid.js @@ -6,24 +6,16 @@ esid: sec-Intl.DisplayNames description: > Valid options for localeMatcher info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... - 4. If options is undefined, then - a. Let options be ObjectCreate(null). - 5. Else - a. Let options be ? ToObject(options). + 4. Let options be ? ToObject(options). ... - 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - ... - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). - ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », "language"). - ... - 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... GetOption ( options, property, type, values, fallback ) @@ -36,21 +28,16 @@ locale: [en] // results for option values verified in the tests for resolvedOptions -var values = [ - undefined, +const types = [ 'language', 'region', 'script', 'currency' ]; -for (let valid of values) { - let options = { - type: valid - }; +types.forEach(type => { + const obj = new Intl.DisplayNames('en', { type }); - var obj = new Intl.DisplayNames('en', options); - - assert(obj instanceof Intl.DisplayNames, `instanceof check - ${valid}`); - assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${valid}`); -} + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${type}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${type}`); +}); diff --git a/test/intl402/DisplayNames/proto-from-ctor-realm.js b/test/intl402/DisplayNames/proto-from-ctor-realm.js index 97b4723251..3bb808071e 100644 --- a/test/intl402/DisplayNames/proto-from-ctor-realm.js +++ b/test/intl402/DisplayNames/proto-from-ctor-realm.js @@ -4,12 +4,14 @@ esid: sec-Intl.DisplayNames description: Default [[Prototype]] value derived from realm of the newTarget info: | - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) 1. If NewTarget is undefined, throw a TypeError exception. 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) @@ -32,6 +34,6 @@ var other = $262.createRealm().global; var C = new other.Function(); C.prototype = null; -var o = Reflect.construct(Intl.DisplayNames, [], C); +var o = Reflect.construct(Intl.DisplayNames, [undefined, {type: 'language'}], C); assert.sameValue(Object.getPrototypeOf(o), other.Intl.DisplayNames.prototype); diff --git a/test/intl402/DisplayNames/prototype/resolvedOptions/default-option-values.js b/test/intl402/DisplayNames/prototype/resolvedOptions/default-option-values.js index da1288d094..6ac209a53c 100644 --- a/test/intl402/DisplayNames/prototype/resolvedOptions/default-option-values.js +++ b/test/intl402/DisplayNames/prototype/resolvedOptions/default-option-values.js @@ -26,17 +26,17 @@ info: | [[Type]]: "type" [[Fallback]]: "fallback" - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) ... - 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... - 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, + 9. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, %DisplayNames%.[[RelevantExtensionKeys]]). - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", - "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -54,7 +54,7 @@ features: [Intl.DisplayNames] includes: [propertyHelper.js] ---*/ -var dn = new Intl.DisplayNames('en-US'); +var dn = new Intl.DisplayNames('en-US', {type: 'language'}); var options = dn.resolvedOptions(); diff --git a/test/intl402/DisplayNames/prototype/resolvedOptions/option-fallback.js b/test/intl402/DisplayNames/prototype/resolvedOptions/option-fallback.js index a7f1e5f3bd..ddb3e2acc8 100644 --- a/test/intl402/DisplayNames/prototype/resolvedOptions/option-fallback.js +++ b/test/intl402/DisplayNames/prototype/resolvedOptions/option-fallback.js @@ -26,17 +26,15 @@ info: | [[Type]]: "type" [[Fallback]]: "fallback" - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) - ... - 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, %DisplayNames%.[[RelevantExtensionKeys]]). 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", - "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -54,30 +52,33 @@ features: [Intl.DisplayNames] includes: [propertyHelper.js] ---*/ -var fallbacks = ['code', 'none']; +const fallbacks = ['code', 'none']; +const types = ['language', 'region', 'script', 'currency']; -fallbacks.forEach(fallback => { - var dn = new Intl.DisplayNames('en-US', { fallback }); - var options = dn.resolvedOptions(); +types.forEach(type => { + fallbacks.forEach(fallback => { + const dn = new Intl.DisplayNames('en-US', { fallback, type }); + const options = dn.resolvedOptions(); - verifyProperty(options, 'fallback', { - value: fallback, - writable: true, - enumerable: true, - configurable: true - }); - - verifyProperty(options, 'type', { - value: 'language', - writable: true, - enumerable: true, - configurable: true - }); - - verifyProperty(options, 'style', { - value: 'long', - writable: true, - enumerable: true, - configurable: true + verifyProperty(options, 'fallback', { + value: fallback, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'type', { + value: type, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'style', { + value: 'long', + writable: true, + enumerable: true, + configurable: true + }); }); }); diff --git a/test/intl402/DisplayNames/prototype/resolvedOptions/option-style.js b/test/intl402/DisplayNames/prototype/resolvedOptions/option-style.js index d80b566b2c..88ca86575d 100644 --- a/test/intl402/DisplayNames/prototype/resolvedOptions/option-style.js +++ b/test/intl402/DisplayNames/prototype/resolvedOptions/option-style.js @@ -26,17 +26,17 @@ info: | [[Type]]: "type" [[Fallback]]: "fallback" - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) ... 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, %DisplayNames%.[[RelevantExtensionKeys]]). - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", - "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -54,30 +54,33 @@ features: [Intl.DisplayNames] includes: [propertyHelper.js] ---*/ -var styles = ['narrow', 'short', 'long']; +const styles = ['narrow', 'short', 'long']; +const types = ['language', 'region', 'script', 'currency']; -styles.forEach(style => { - var dn = new Intl.DisplayNames('en-US', { style }); - var options = dn.resolvedOptions(); +types.forEach(type => { + styles.forEach(style => { + const dn = new Intl.DisplayNames('en-US', { style, type }); + const options = dn.resolvedOptions(); - verifyProperty(options, 'style', { - value: style, - writable: true, - enumerable: true, - configurable: true - }); - - verifyProperty(options, 'type', { - value: 'language', - writable: true, - enumerable: true, - configurable: true - }); - - verifyProperty(options, 'fallback', { - value: 'code', - writable: true, - enumerable: true, - configurable: true + verifyProperty(options, 'style', { + value: style, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'type', { + value: type, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'fallback', { + value: 'code', + writable: true, + enumerable: true, + configurable: true + }); }); }); diff --git a/test/intl402/DisplayNames/prototype/resolvedOptions/return-object.js b/test/intl402/DisplayNames/prototype/resolvedOptions/return-object.js index 54d7ff2874..89cf012d80 100644 --- a/test/intl402/DisplayNames/prototype/resolvedOptions/return-object.js +++ b/test/intl402/DisplayNames/prototype/resolvedOptions/return-object.js @@ -26,17 +26,17 @@ info: | [[Type]]: "type" [[Fallback]]: "fallback" - Intl.DisplayNames ([ locales [ , options ]]) + Intl.DisplayNames ( locales , options ) ... - 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). ... - 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, + 9. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, %DisplayNames%.[[RelevantExtensionKeys]]). - 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). ... - 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", - "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. ... 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). ... @@ -54,10 +54,10 @@ features: [Intl.DisplayNames, Reflect] includes: [propertyHelper.js, compareArray.js] ---*/ -var dn = new Intl.DisplayNames('en-US'); +const dn = new Intl.DisplayNames('en-US', {type: 'language'}); -var options = dn.resolvedOptions(); -var other = dn.resolvedOptions(); +const options = dn.resolvedOptions(); +const other = dn.resolvedOptions(); assert.notSameValue(options, other, 'each call returns a new object'); @@ -77,7 +77,8 @@ verifyProperty(options, 'locale', { configurable: true }); -var explicit = new Intl.DisplayNames('en', { localeMatcher: 'lookup' }).resolvedOptions(); +const explicit = new Intl.DisplayNames( + 'en', { localeMatcher: 'lookup', type: 'language' }).resolvedOptions(); assert.sameValue( explicit.hasOwnProperty('localeMatcher'), @@ -85,7 +86,8 @@ assert.sameValue( 'the localeMatcher option is not set, option was explicitly set' ); -var extra = new Intl.DisplayNames('en', { chaos: 'yes', random: 'sure', '0': 42 }).resolvedOptions(); +const extra = new Intl.DisplayNames( + 'en', { chaos: 'yes', random: 'sure', '0': 42, type: 'language' }).resolvedOptions(); assert.compareArray( Reflect.ownKeys(extra),