mirror of https://github.com/tc39/test262.git
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:
parent
59f5b49359
commit
3c89cde3e0
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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(); },
|
||||
});
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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}`);
|
||||
});
|
||||
|
|
|
@ -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}`);
|
||||
});
|
||||
|
|
|
@ -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(); }
|
||||
});
|
||||
|
|
|
@ -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}`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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}`);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue