src/third_party/mozjs/extract/js/src/builtin/intl/CommonFunctions.js
/**
 * Compares a BCP 47 language priority list against availableLocales and
 * determines the best available language to meet the request. Options specified
 * through Unicode extension subsequences are negotiated separately, taking the
 * caller's relevant extensions and locale data as well as client-provided
 * options into consideration.
 *
 * Spec: ECMAScript Internationalization API Specification, 9.2.6.
 */
Compares a BCP 47 language priority list against availableLocales and
determines the best available language to meet the request. Options specified
through Unicode extension subsequences are negotiated separately, taking the
caller's relevant extensions and locale data as well as client-provided
options into consideration.

ECMAScript Internationalization API Specification, 9.2.6.
Compares a BCP 47 language priority list against availableLocales and determines the best available language to meet the request . Options specified through Unicode extension subsequences are negotiated separately taking the caller ' s relevant extensions and locale data as well as client - provided options into consideration . ECMAScript Internationalization API Specification 9 . 2 . 6 .
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData) {
    var matcher = options.localeMatcher;
    var r = (matcher === "lookup")
            ? LookupMatcher(availableLocales, requestedLocales)
            : BestFitMatcher(availableLocales, requestedLocales);
    var foundLocale = r.locale;
    var extension = r.extension;
    var result = new_Record();
    result.dataLocale = foundLocale;
    var supportedExtension = "-u";
    var localeDataProvider = localeData();
    for (var i = 0; i < relevantExtensionKeys.length; i++) {
        var key = relevantExtensionKeys[i];
        var keyLocaleData = undefined;
        var value = undefined;
        g.
        var supportedExtensionAddition = "";
        h.
        if (extension !== undefined) {
            h.i.
            var requestedValue = UnicodeExtensionValue(extension, key);
            h.ii.
            if (requestedValue !== undefined) {
                keyLocaleData = callFunction(localeDataProvider[key], null, foundLocale);
                h.ii.1.
                if (requestedValue !== "") {
                    h.ii.1.a.
                    if (callFunction(ArrayIndexOf, keyLocaleData, requestedValue) !== -1) {
                        value = requestedValue;
                        supportedExtensionAddition = "-" + key + "-" + value;
                    }
                } else {
                    h.ii.2.
                    if (callFunction(ArrayIndexOf, keyLocaleData, "true") !== -1) {
                        value = "true";
                        supportedExtensionAddition = "-" + key;
                    }
                }
            }
        }
        i.i.
        var optionsValue = options[key];
        i.ii.
        assert(typeof optionsValue === "string" ||
               optionsValue === undefined ||
               optionsValue === null,
               "unexpected type for options value");
        if (optionsValue !== undefined && optionsValue !== value) {
            if (keyLocaleData === undefined)
                keyLocaleData = callFunction(localeDataProvider[key], null, foundLocale);
            i.iii.
            if (callFunction(ArrayIndexOf, keyLocaleData, optionsValue) !== -1) {
                value = optionsValue;
                supportedExtensionAddition = "";
            }
        }
        if (value === undefined) {
            value = keyLocaleData === undefined
                    ? callFunction(localeDataProvider.default[key], null, foundLocale)
                    : keyLocaleData[0];
        }
        j.
        assert(typeof value === "string" || value === null, "unexpected locale data value");
        result[key] = value;
        k.
        supportedExtension += supportedExtensionAddition;
    }
    if (supportedExtension.length > 2)
        foundLocale = addUnicodeExtension(foundLocale, supportedExtension);
    result.locale = foundLocale;
    return result;
}
function ResolveLocale ( availableLocales , requestedLocales , options , relevantExtensionKeys , localeData ) { var matcher = options . localeMatcher ; var r = ( matcher === "lookup" ) ? LookupMatcher ( availableLocales , requestedLocales ) : BestFitMatcher ( availableLocales , requestedLocales ) ; var foundLocale = r . locale ; var extension = r . extension ; var result = new_Record ( ) ; result . dataLocale = foundLocale ; var supportedExtension = "-u" ; var localeDataProvider = localeData ( ) ; for ( var i = 0 ; i < relevantExtensionKeys . length ; i ++ ) { var key = relevantExtensionKeys [ i ] ; var keyLocaleData = undefined ; var value = undefined ; var supportedExtensionAddition = "" ; if ( extension !== undefined ) { var requestedValue = UnicodeExtensionValue ( extension , key ) ; if ( requestedValue !== undefined ) { keyLocaleData = callFunction ( localeDataProvider [ key ] , null , foundLocale ) ; if ( requestedValue !== "" ) { if ( callFunction ( ArrayIndexOf , keyLocaleData , requestedValue ) !== - 1 ) { value = requestedValue ; supportedExtensionAddition = "-" + key + "-" + value ; } } else { if ( callFunction ( ArrayIndexOf , keyLocaleData , "true" ) !== - 1 ) { value = "true" ; supportedExtensionAddition = "-" + key ; } } } } var optionsValue = options [ key ] ; assert ( typeof optionsValue === "string" || optionsValue === undefined || optionsValue === null , "unexpected type for options value" ) ; if ( optionsValue !== undefined && optionsValue !== value ) { if ( keyLocaleData === undefined ) keyLocaleData = callFunction ( localeDataProvider [ key ] , null , foundLocale ) ; if ( callFunction ( ArrayIndexOf , keyLocaleData , optionsValue ) !== - 1 ) { value = optionsValue ; supportedExtensionAddition = "" ; } } if ( value === undefined ) { value = keyLocaleData === undefined ? callFunction ( localeDataProvider . default [ key ] , null , foundLocale ) : keyLocaleData [ 0 ] ; } assert ( typeof value === "string" || value === null , "unexpected locale data value" ) ; result [ key ] = value ; supportedExtension += supportedExtensionAddition ; } if ( supportedExtension . length > 2 ) foundLocale = addUnicodeExtension ( foundLocale , supportedExtension ) ; result . locale = foundLocale ; return result ; }
Compares a BCP 47 language priority list against availableLocales and
 determines the best available language to meet the request.
Compares a BCP 47 language priority list against availableLocales and determines the best available language to meet the request .
// Steps 1-3. // Step 4. // Step 5. // Step 6. // Step 7. // In this implementation, localeData is a function, not an object. // Step 8. // Steps 8.a-h (The locale data is only computed when needed). // Locale tag may override. // Step 8.g. // Step 8.h. // Step 8.h.i. // Step 8.h.ii. // Steps 8.a-d. // Step 8.h.ii.1. // Step 8.h.ii.1.a. // Step 8.h.ii.2. // According to the LDML spec, if there's no type value, // and true is an allowed value, it's used. // Options override all. // Step 8.i.i. // Step 8.i.ii. // Steps 8.i, 8.i.iii.1. // Steps 8.a-d. // Step 8.i.iii. // Locale data provides default value. // Steps 8.a-f. // Step 8.j. // Step 8.k. // Step 9. // Step 10. // Step 11.