Debian Codegraph @

js/src/tests/non262/Intl/available-locales-resolved.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty('Intl'))
2
3 if (typeof getAvailableLocalesOf === "undefined") {
4 var getAvailableLocalesOf = SpecialPowers.Cu.getJSTestingFunctions().getAvailableLocalesOf;
5 }
6
7 function IsIntlService(c) {
8 return typeof c === "function" &&
9 c.hasOwnProperty("prototype") &&
10 c.prototype.hasOwnProperty("resolvedOptions");
11 }
12
13 const intlConstructors = Object.getOwnPropertyNames(Intl).map(name => Intl[name]).filter(IsIntlService);
14
15 // Test all Intl service constructors.
16 for (let intlConstructor of intlConstructors) {
17 // Retrieve all available locales of the given Intl service constructor.
18 let available = getAvailableLocalesOf(intlConstructor.name);
19
20 // "best fit" matchers could potentially return a different locale, so we only
21 // test with "lookup" locale matchers. (NB: We don't yet support "best fit"
22 // matchers.)
23 let options = {localeMatcher: "lookup"};
24
25 if (intlConstructor === Intl.DisplayNames) {
26 // Intl.DisplayNames can't be constructed without the "type" option.
27 options.type = "language";
28 }
29
30 for (let locale of available) {
31 let obj = new intlConstructor(locale, options);
32 let resolved = obj.resolvedOptions();
33
34 // If |locale| is an available locale, the "lookup" locale matcher should
35 // pick exactly that locale.
36 assertEq(resolved.locale, locale);
37 }
38 }
39
40 if (typeof reportCompare === "function")
41 reportCompare(true, true);