src/third_party/mozjs/extract/js/src/builtin/intl/Collator.js
/**
 * Initializes an object as a Collator.
 *
 * This method is complicated a moderate bit by its implementing initialization
 * as a *lazy* concept.  Everything that must happen now, does -- but we defer
 * all the work we can until the object is actually used as a Collator.  This
 * later work occurs in |resolveCollatorInternals|; steps not noted here occur
 * there.
 *
 * Spec: ECMAScript Internationalization API Specification, 10.1.1.
 */
Initializes an object as a Collator.
This method is complicated a moderate bit by its implementing initialization
as a *lazy* concept.  Everything that must happen now, does -- but we defer
all the work we can until the object is actually used as a Collator.  This
later work occurs in |resolveCollatorInternals|; steps not noted here occur
there.

ECMAScript Internationalization API Specification, 10.1.1.
Initializes an object as a Collator . This method is complicated a moderate bit by its implementing initialization as a * lazy * concept . Everything that must happen now does -- but we defer all the work we can until the object is actually used as a Collator . This later work occurs in |resolveCollatorInternals| ; steps not noted here occur there . ECMAScript Internationalization API Specification 10 . 1 . 1 .
function InitializeCollator(collator, locales, options) {
    assert(IsObject(collator), "InitializeCollator called with non-object");
    assert(intl_GuardToCollator(collator) != null, "InitializeCollator called with non-Collator");
       {
         requestedLocales: List of locales,
         usage: "sort" / "search",
         opt:  opt object computed in InitializeCollator
           {
             localeMatcher: "lookup" / "best fit",
             co: string matching a Unicode extension type / undefined
             kn: true / false / undefined,
             kf: "upper" / "lower" / "false" / undefined
           }
         rawSensitivity: "base" / "accent" / "case" / "variant" / undefined,
         ignorePunctuation: true / false
       }
     Note that lazy data is only installed as a final step of initialization,
     so every Collator lazy data object has *all* these properties, never a
     subset of them.
    var lazyCollatorData = std_Object_create(null);
     Step 1.
    var requestedLocales = CanonicalizeLocaleList(locales);
    lazyCollatorData.requestedLocales = requestedLocales;
     Steps 2-3.
     If we ever need more speed here at startup, we should try to detect the
     case where |options === undefined| and then directly use the default
     value for each option.  For now, just keep it simple.
    if (options === undefined)
        options = std_Object_create(null);
    else
        options = ToObject(options);
     Compute options that impact interpretation of locale.
     Step 4.
    var u = GetOption(options, "usage", "string", ["sort", "search"], "sort");
    lazyCollatorData.usage = u;
     Step 8.
    var opt = new_Record();
    lazyCollatorData.opt = opt;
     Steps 9-10.
    var matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
    opt.localeMatcher = matcher;
     https:github.com/tc39/ecma402/pull/459
    var collation = GetOption(options, "collation", "string", undefined, undefined);
    if (collation !== undefined)
        collation = intl_ValidateAndCanonicalizeUnicodeExtensionType(collation, "collation", "co");
    opt.co = collation;
     Steps 11-13.
    var numericValue = GetOption(options, "numeric", "boolean", undefined, undefined);
    if (numericValue !== undefined)
        numericValue = numericValue ? "true" : "false";
    opt.kn = numericValue;
     Steps 14-15.
    var caseFirstValue = GetOption(options, "caseFirst", "string", ["upper", "lower", "false"], undefined);
    opt.kf = caseFirstValue;
     Compute remaining collation options.
     Step 24.
    var s = GetOption(options, "sensitivity", "string",
                      ["base", "accent", "case", "variant"], undefined);
    lazyCollatorData.rawSensitivity = s;
     Step 27.
    var ip = GetOption(options, "ignorePunctuation", "boolean", undefined, false);
    lazyCollatorData.ignorePunctuation = ip;
     Step 29.
     We've done everything that must be done now: mark the lazy data as fully
     computed and install it.
    initializeIntlObject(collator, "Collator", lazyCollatorData);
}
function InitializeCollator ( collator , locales , options ) { assert ( IsObject ( collator ) , "InitializeCollator called with non-object" ) ; assert ( intl_GuardToCollator ( collator ) != null , "InitializeCollator called with non-Collator" ) ; var lazyCollatorData = std_Object_create ( null ) ; var requestedLocales = CanonicalizeLocaleList ( locales ) ; lazyCollatorData . requestedLocales = requestedLocales ; if ( options === undefined ) options = std_Object_create ( null ) ; else options = ToObject ( options ) ; var u = GetOption ( options , "usage" , "string" , [ "sort" , "search" ] , "sort" ) ; lazyCollatorData . usage = u ; var opt = new_Record ( ) ; lazyCollatorData . opt = opt ; var matcher = GetOption ( options , "localeMatcher" , "string" , [ "lookup" , "best fit" ] , "best fit" ) ; opt . localeMatcher = matcher ; var collation = GetOption ( options , "collation" , "string" , undefined , undefined ) ; if ( collation !== undefined ) collation = intl_ValidateAndCanonicalizeUnicodeExtensionType ( collation , "collation" , "co" ) ; opt . co = collation ; var numericValue = GetOption ( options , "numeric" , "boolean" , undefined , undefined ) ; if ( numericValue !== undefined ) numericValue = numericValue ? "true" : "false" ; opt . kn = numericValue ; var caseFirstValue = GetOption ( options , "caseFirst" , "string" , [ "upper" , "lower" , "false" ] , undefined ) ; opt . kf = caseFirstValue ; var s = GetOption ( options , "sensitivity" , "string" , [ "base" , "accent" , "case" , "variant" ] , undefined ) ; lazyCollatorData . rawSensitivity = s ; var ip = GetOption ( options , "ignorePunctuation" , "boolean" , undefined , false ) ; lazyCollatorData . ignorePunctuation = ip ; initializeIntlObject ( collator , "Collator" , lazyCollatorData ) ; }
Initializes an object as a Collator.
Initializes an object as a Collator .
// Lazy Collator data has the following structure: // //   { //     requestedLocales: List of locales, //     usage: "sort" / "search", //     opt: // opt object computed in InitializeCollator //       { //         localeMatcher: "lookup" / "best fit", //         co: string matching a Unicode extension type / undefined //         kn: true / false / undefined, //         kf: "upper" / "lower" / "false" / undefined //       } //     rawSensitivity: "base" / "accent" / "case" / "variant" / undefined, //     ignorePunctuation: true / false //   } // // Note that lazy data is only installed as a final step of initialization, // so every Collator lazy data object has *all* these properties, never a // subset of them. // Step 1. // Steps 2-3. // // If we ever need more speed here at startup, we should try to detect the // case where |options === undefined| and then directly use the default // value for each option.  For now, just keep it simple. // Compute options that impact interpretation of locale. // Step 4. // Step 8. // Steps 9-10. // https://github.com/tc39/ecma402/pull/459 // Steps 11-13. // Steps 14-15. // Compute remaining collation options. // Step 24. // Step 27. // Step 29. // // We've done everything that must be done now: mark the lazy data as fully // computed and install it.