Intl.DisplayNames make type required

Update the tests to the latest version after we make
the type option now required

Spec:
https://tc39.es/proposal-intl-displaynames/

Changes of spec:
https://github.com/tc39/proposal-intl-displaynames/pull/76
https://github.com/tc39/proposal-intl-displaynames/pull/83
This commit is contained in:
Frank Tang 2020-07-10 19:19:34 -07:00
parent 59f5b49359
commit 3c89cde3e0
18 changed files with 194 additions and 241 deletions

View File

@ -40,7 +40,8 @@ function testWithIntlConstructors(f) {
// Optionally supported Intl constructors. // Optionally supported Intl constructors.
// NB: Intl.Locale isn't an Intl service constructor! // 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") { if (typeof Intl[constructor] === "function") {
constructors[constructors.length] = constructor; constructors[constructors.length] = constructor;
} }

View File

@ -6,12 +6,15 @@ esid: sec-Intl.DisplayNames
description: > description: >
Custom Prototype of the returned object based on the NewTarget Custom Prototype of the returned object based on the NewTarget
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[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 ] ) OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
@ -32,6 +35,6 @@ features: [Intl.DisplayNames, Reflect]
var custom = new Function(); var custom = new Function();
custom.prototype = {}; 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); assert.sameValue(Object.getPrototypeOf(obj), custom.prototype);

View File

@ -6,16 +6,19 @@ esid: sec-Intl.DisplayNames
description: > description: >
Prototype of the returned object is DisplayNames.prototype Prototype of the returned object is DisplayNames.prototype
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[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. 27. Return displayNames.
features: [Intl.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); assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype);

View File

@ -6,12 +6,15 @@ esid: sec-Intl.DisplayNames
description: > description: >
Instance is extensible Instance is extensible
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[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 ] ) OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
@ -30,6 +33,6 @@ info: |
features: [Intl.DisplayNames] features: [Intl.DisplayNames]
---*/ ---*/
var obj = new Intl.DisplayNames(); var obj = new Intl.DisplayNames(undefined, {type: 'language'});
assert(Object.isExtensible(obj)); assert(Object.isExtensible(obj));

View File

@ -6,13 +6,16 @@ esid: sec-Intl.DisplayNames
description: > description: >
CanonicalizeLocaleList tries to fetch length from Object. CanonicalizeLocaleList tries to fetch length from Object.
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
3. Let requestedLocales be ? CanonicalizeLocaleList(locales). 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 ) CanonicalizeLocaleList ( locales )
@ -29,8 +32,8 @@ locale: [en]
includes: [compareArray.js] includes: [compareArray.js]
---*/ ---*/
var calls = []; let calls = [];
var symbol = Symbol(); let symbol = Symbol();
Symbol.prototype.length = 1; 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']); assert.compareArray(calls, ['length', '0']);

View File

@ -6,22 +6,16 @@ esid: sec-Intl.DisplayNames
description: > description: >
Return abrupt completion from GetOption fallback Return abrupt completion from GetOption fallback
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
... ...
4. If options is undefined, then 4. Let options be ? ToObject(options).
a. Let options be ObjectCreate(null).
5. Else
a. Let options be ? ToObject(options).
... ...
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
... 13. If type is undefined, throw a TypeError exception.
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"). 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
... ...
@ -34,7 +28,7 @@ features: [Intl.DisplayNames, Symbol]
locale: [en] locale: [en]
---*/ ---*/
var options = {}; var options = { type: 'language' };
Object.defineProperty(options, 'fallback', { Object.defineProperty(options, 'fallback', {
get() { throw new Test262Error(); }, get() { throw new Test262Error(); },
}); });

View File

@ -6,22 +6,18 @@ esid: sec-Intl.DisplayNames
description: > description: >
Return abrupt completion from an invalid fallback option Return abrupt completion from an invalid fallback option
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
... ...
4. If options is undefined, then 4. Let options be ? ToObject(options).
a. Let options be ObjectCreate(null).
5. Else
a. Let options be ? ToObject(options).
... ...
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). 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"). 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », "language").
... 13. If type is undefined, throw a TypeError exception.
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"). 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
... ...
@ -40,34 +36,22 @@ features: [Intl.DisplayNames]
locale: [en] locale: [en]
---*/ ---*/
var options = {
fallback: 'err'
};
assert.throws(RangeError, () => { assert.throws(RangeError, () => {
new Intl.DisplayNames('en', options); new Intl.DisplayNames('en', {fallback: 'err', type: 'language'});
}, 'err'); }, 'err');
options.fallback = 'non';
assert.throws(RangeError, () => { assert.throws(RangeError, () => {
new Intl.DisplayNames('en', options); new Intl.DisplayNames('en', {fallback: 'non', type: 'language'});
}, 'non, not none'); }, 'non, not none');
options.fallback = null;
assert.throws(RangeError, () => { assert.throws(RangeError, () => {
new Intl.DisplayNames('en', options); new Intl.DisplayNames('en', {fallback: null, type: 'language'});
}, 'null'); }, 'null');
options.fallback = '';
assert.throws(RangeError, () => { assert.throws(RangeError, () => {
new Intl.DisplayNames('en', options); new Intl.DisplayNames('en', {fallback: '', type: 'language'});
}, 'the empty string'); }, 'the empty string');
options.fallback = ['code', 'none'];
assert.throws(RangeError, () => { 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'); }, 'an array with the valid options is not necessarily valid');

View File

@ -6,21 +6,20 @@ esid: sec-Intl.DisplayNames
description: > description: >
Return abrupt completion from GetOption fallback Return abrupt completion from GetOption fallback
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
... ...
4. If options is undefined, then 4. Let options be ? ToObject(options).
a. Let options be ObjectCreate(null).
5. Else
a. Let options be ? ToObject(options).
... ...
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). 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 ) GetOption ( options, property, type, values, fallback )
@ -30,41 +29,29 @@ features: [Intl.DisplayNames, Symbol]
locale: [en] locale: [en]
---*/ ---*/
var options = {
fallback: {
toString() {
throw new Test262Error();
}
}
};
assert.throws(Test262Error, () => { assert.throws(Test262Error, () => {
new Intl.DisplayNames('en', options); new Intl.DisplayNames('en', {
type: 'language', fallback: { toString() { throw new Test262Error(); }}
});
}, 'from toString'); }, 'from toString');
options.fallback = {
toString: undefined,
valueOf() {
throw new Test262Error();
}
};
assert.throws(Test262Error, () => { assert.throws(Test262Error, () => {
new Intl.DisplayNames('en', options); new Intl.DisplayNames('en', {
type: 'language',
fallback: {toString: undefined, valueOf() {throw new Test262Error(); }}
});
}, 'from valueOf'); }, 'from valueOf');
options.fallback = {
[Symbol.toPrimitive]() {
throw new Test262Error();
}
};
assert.throws(Test262Error, () => { assert.throws(Test262Error, () => {
new Intl.DisplayNames('en', options); new Intl.DisplayNames('en', {
type: 'language',
fallback: { [Symbol.toPrimitive]() { throw new Test262Error(); } }
});
}, 'from ToPrimitive'); }, 'from ToPrimitive');
options.fallback = Symbol();
assert.throws(TypeError, () => { assert.throws(TypeError, () => {
new Intl.DisplayNames('en', options); new Intl.DisplayNames('en', {
type: 'language',
fallback: Symbol()
});
}, 'symbol value'); }, 'symbol value');

View File

@ -6,22 +6,20 @@ esid: sec-Intl.DisplayNames
description: > description: >
Valid options for fallback Valid options for fallback
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
... ...
4. If options is undefined, then 4. Let options be ? ToObject(options).
a. Let options be ObjectCreate(null).
5. Else
a. Let options be ? ToObject(options).
... ...
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). 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"). 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 // results for option values verified in the tests for resolvedOptions
var values = [ const fallbacks = [
undefined, undefined,
'code', 'code',
'none' 'none'
]; ];
for (let valid of values) { fallbacks.forEach(fallback => {
let options = { const obj = new Intl.DisplayNames('en', { fallback, type: 'language'});
fallback: valid
};
var obj = new Intl.DisplayNames('en', options); assert(obj instanceof Intl.DisplayNames, `instanceof check - ${fallback}`);
assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${fallback}`);
assert(obj instanceof Intl.DisplayNames, `instanceof check - ${valid}`); });
assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${valid}`);
}

View File

@ -6,22 +6,20 @@ esid: sec-Intl.DisplayNames
description: > description: >
Valid options for localeMatcher Valid options for localeMatcher
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
... ...
4. If options is undefined, then 4. Let options be ? ToObject(options).
a. Let options be ObjectCreate(null).
5. Else
a. Let options be ? ToObject(options).
... ...
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). 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"). 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 // results for option values verified in the tests for resolvedOptions
var values = [ const localeMatchers = [
undefined, undefined,
'lookup', 'lookup',
'best fit' 'best fit'
]; ];
for (let valid of values) { localeMatchers.forEach(localeMatcher => {
let options = { const obj = new Intl.DisplayNames('en', { localeMatcher, type: 'language' });
localeMatcher: valid
};
var obj = new Intl.DisplayNames('en', options); assert(obj instanceof Intl.DisplayNames, `instanceof check - ${localeMatcher}`);
assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${localeMatcher}`);
assert(obj instanceof Intl.DisplayNames, `instanceof check - ${valid}`); });
assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${valid}`);
}

View File

@ -6,22 +6,20 @@ esid: sec-Intl.DisplayNames
description: > description: >
Random options are not checked or used, including case sensitive Random options are not checked or used, including case sensitive
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
... ...
4. If options is undefined, then 4. Let options be ? ToObject(options).
a. Let options be ObjectCreate(null).
5. Else
a. 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"). 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
... ...
@ -34,7 +32,7 @@ features: [Intl.DisplayNames]
locale: [en] locale: [en]
---*/ ---*/
var options = {}; var options = { type: 'language' };
Object.defineProperty(options, 'fallBack', { Object.defineProperty(options, 'fallBack', {
get() { throw new Test262Error(); } get() { throw new Test262Error(); }
}); });

View File

@ -6,24 +6,18 @@ esid: sec-Intl.DisplayNames
description: > description: >
Valid options for localeMatcher Valid options for localeMatcher
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
... ...
4. If options is undefined, then 4. Let options be ? ToObject(options).
a. Let options be ObjectCreate(null).
5. Else
a. 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"). 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
... 13. If type is undefined, throw a TypeError exception.
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").
... ...
GetOption ( options, property, type, values, fallback ) GetOption ( options, property, type, values, fallback )
@ -36,20 +30,20 @@ locale: [en]
// results for option values verified in the tests for resolvedOptions // results for option values verified in the tests for resolvedOptions
var values = [ const styles = [
undefined, undefined,
'narrow', 'narrow',
'short', 'short',
'long' 'long'
]; ];
for (let valid of values) { const types = ['language', 'region', 'script', 'currency'];
let options = {
style: valid
};
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(obj instanceof Intl.DisplayNames, `instanceof check - ${style}`);
assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${valid}`); assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${style}`);
} });
});

View File

@ -6,24 +6,16 @@ esid: sec-Intl.DisplayNames
description: > description: >
Valid options for localeMatcher Valid options for localeMatcher
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
... ...
4. If options is undefined, then 4. Let options be ? ToObject(options).
a. Let options be ObjectCreate(null).
5. Else
a. Let options be ? ToObject(options).
... ...
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
... 13. If type is undefined, throw a TypeError exception.
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").
... ...
GetOption ( options, property, type, values, fallback ) GetOption ( options, property, type, values, fallback )
@ -36,21 +28,16 @@ locale: [en]
// results for option values verified in the tests for resolvedOptions // results for option values verified in the tests for resolvedOptions
var values = [ const types = [
undefined,
'language', 'language',
'region', 'region',
'script', 'script',
'currency' 'currency'
]; ];
for (let valid of values) { types.forEach(type => {
let options = { const obj = new Intl.DisplayNames('en', { type });
type: valid
};
var obj = new Intl.DisplayNames('en', options); assert(obj instanceof Intl.DisplayNames, `instanceof check - ${type}`);
assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${type}`);
assert(obj instanceof Intl.DisplayNames, `instanceof check - ${valid}`); });
assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${valid}`);
}

View File

@ -4,12 +4,14 @@
esid: sec-Intl.DisplayNames esid: sec-Intl.DisplayNames
description: Default [[Prototype]] value derived from realm of the newTarget description: Default [[Prototype]] value derived from realm of the newTarget
info: | info: |
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
1. If NewTarget is undefined, throw a TypeError exception. 1. If NewTarget is undefined, throw a TypeError exception.
2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%",
« [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). « [[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 ] ) OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
@ -32,6 +34,6 @@ var other = $262.createRealm().global;
var C = new other.Function(); var C = new other.Function();
C.prototype = null; 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); assert.sameValue(Object.getPrototypeOf(o), other.Intl.DisplayNames.prototype);

View File

@ -26,17 +26,17 @@ info: |
[[Type]]: "type" [[Type]]: "type"
[[Fallback]]: "fallback" [[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]]). %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", 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
"weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). 13. If type is undefined, throw a TypeError exception.
... ...
15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
... ...
@ -54,7 +54,7 @@ features: [Intl.DisplayNames]
includes: [propertyHelper.js] includes: [propertyHelper.js]
---*/ ---*/
var dn = new Intl.DisplayNames('en-US'); var dn = new Intl.DisplayNames('en-US', {type: 'language'});
var options = dn.resolvedOptions(); var options = dn.resolvedOptions();

View File

@ -26,17 +26,15 @@ info: |
[[Type]]: "type" [[Type]]: "type"
[[Fallback]]: "fallback" [[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, 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt,
%DisplayNames%.[[RelevantExtensionKeys]]). %DisplayNames%.[[RelevantExtensionKeys]]).
11. 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", 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
"weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). 13. If type is undefined, throw a TypeError exception.
... ...
15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
... ...
@ -54,30 +52,33 @@ features: [Intl.DisplayNames]
includes: [propertyHelper.js] includes: [propertyHelper.js]
---*/ ---*/
var fallbacks = ['code', 'none']; const fallbacks = ['code', 'none'];
const types = ['language', 'region', 'script', 'currency'];
fallbacks.forEach(fallback => { types.forEach(type => {
var dn = new Intl.DisplayNames('en-US', { fallback }); fallbacks.forEach(fallback => {
var options = dn.resolvedOptions(); const dn = new Intl.DisplayNames('en-US', { fallback, type });
const options = dn.resolvedOptions();
verifyProperty(options, 'fallback', { verifyProperty(options, 'fallback', {
value: fallback, value: fallback,
writable: true, writable: true,
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
verifyProperty(options, 'type', { verifyProperty(options, 'type', {
value: 'language', value: type,
writable: true, writable: true,
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
verifyProperty(options, 'style', { verifyProperty(options, 'style', {
value: 'long', value: 'long',
writable: true, writable: true,
enumerable: true, enumerable: true,
configurable: true configurable: true
});
}); });
}); });

View File

@ -26,17 +26,17 @@ info: |
[[Type]]: "type" [[Type]]: "type"
[[Fallback]]: "fallback" [[Fallback]]: "fallback"
Intl.DisplayNames ([ locales [ , options ]]) Intl.DisplayNames ( locales , options )
... ...
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
... ...
10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt,
%DisplayNames%.[[RelevantExtensionKeys]]). %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", 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
"weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). 13. If type is undefined, throw a TypeError exception.
... ...
15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
... ...
@ -54,30 +54,33 @@ features: [Intl.DisplayNames]
includes: [propertyHelper.js] includes: [propertyHelper.js]
---*/ ---*/
var styles = ['narrow', 'short', 'long']; const styles = ['narrow', 'short', 'long'];
const types = ['language', 'region', 'script', 'currency'];
styles.forEach(style => { types.forEach(type => {
var dn = new Intl.DisplayNames('en-US', { style }); styles.forEach(style => {
var options = dn.resolvedOptions(); const dn = new Intl.DisplayNames('en-US', { style, type });
const options = dn.resolvedOptions();
verifyProperty(options, 'style', { verifyProperty(options, 'style', {
value: style, value: style,
writable: true, writable: true,
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
verifyProperty(options, 'type', { verifyProperty(options, 'type', {
value: 'language', value: type,
writable: true, writable: true,
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
verifyProperty(options, 'fallback', { verifyProperty(options, 'fallback', {
value: 'code', value: 'code',
writable: true, writable: true,
enumerable: true, enumerable: true,
configurable: true configurable: true
});
}); });
}); });

View File

@ -26,17 +26,17 @@ info: |
[[Type]]: "type" [[Type]]: "type"
[[Fallback]]: "fallback" [[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]]). %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", 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
"weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). 13. If type is undefined, throw a TypeError exception.
... ...
15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
... ...
@ -54,10 +54,10 @@ features: [Intl.DisplayNames, Reflect]
includes: [propertyHelper.js, compareArray.js] 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(); const options = dn.resolvedOptions();
var other = dn.resolvedOptions(); const other = dn.resolvedOptions();
assert.notSameValue(options, other, 'each call returns a new object'); assert.notSameValue(options, other, 'each call returns a new object');
@ -77,7 +77,8 @@ verifyProperty(options, 'locale', {
configurable: true configurable: true
}); });
var explicit = new Intl.DisplayNames('en', { localeMatcher: 'lookup' }).resolvedOptions(); const explicit = new Intl.DisplayNames(
'en', { localeMatcher: 'lookup', type: 'language' }).resolvedOptions();
assert.sameValue( assert.sameValue(
explicit.hasOwnProperty('localeMatcher'), explicit.hasOwnProperty('localeMatcher'),
@ -85,7 +86,8 @@ assert.sameValue(
'the localeMatcher option is not set, option was explicitly set' '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( assert.compareArray(
Reflect.ownKeys(extra), Reflect.ownKeys(extra),