available-locales-implied-script.js (1233B)
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 let availableSet = new Set(available); 20 21 available.filter(x => { 22 return new Intl.Locale(x); 23 }).filter(loc => { 24 // Find all locales which have both a script and a region subtag. 25 return loc.script && loc.region; 26 }).forEach(loc => { 27 let noScript = `${loc.language}-${loc.region}`; 28 29 // The locale without a script subtag must also be available. 30 assertEq(availableSet.has(noScript), true, `Missing locale ${noScript} for ${loc}`); 31 }); 32 } 33 34 if (typeof reportCompare === "function") 35 reportCompare(true, true);