|
102 | 102 | var isFinite = platform.builtInGlobalObjectEntryIsFinite;
|
103 | 103 | var isNaN = platform.builtInGlobalObjectEntryIsNaN;
|
104 | 104 |
|
105 |
| - // Keep this "enum" in sync with IntlEngineInterfaceExtensionObject::EntryIntl_RegisterBuiltInFunction |
106 |
| - const IntlBuiltInFunctionID = setPrototype({ |
107 |
| - MIN: 0, |
108 |
| - DateToLocaleString: 0, |
109 |
| - DateToLocaleDateString: 1, |
110 |
| - DateToLocaleTimeString: 2, |
111 |
| - NumberToLocaleString: 3, |
112 |
| - StringLocaleCompare: 4, |
113 |
| - MAX: 5 |
114 |
| - }, null); |
115 |
| - |
116 | 105 | const _ = {
|
117 | 106 | toUpperCase(str) { return callInstanceFunc(StringInstanceToUpperCase, str); },
|
118 | 107 | toLowerCase(str) { return callInstanceFunc(StringInstanceToLowerCase, str); },
|
|
879 | 868 | const requestedLocales = CanonicalizeLocaleList(locales);
|
880 | 869 | options = options === undefined ? _.create() : Internal.ToObject(options);
|
881 | 870 |
|
| 871 | + // The spec says that usage dictates whether to use "[[SearchLocaleData]]" or "[[SortLocaleData]]" |
| 872 | + // ICU has no concept of a difference between the two, and instead sort/search corresponds to |
| 873 | + // collation = "standard" or collation = "search", respectively. Standard/sort is the default. |
| 874 | + // Thus, when the usage is sort, we can accept and honor -u-co in the locale, while if usage is search, |
| 875 | + // we are going to overwrite any -u-co value provided before giving the locale to ICU anyways. |
| 876 | + // To make the logic simpler, we can simply pretend like we don't accept a -u-co value if the usage is search. |
| 877 | + // See the lazy UCollator initialization in EntryIntl_LocaleCompare for where the collation value |
| 878 | + // gets overwritten by "search". |
882 | 879 | collator.usage = GetOption(options, "usage", "string", ["sort", "search"], "sort");
|
883 |
| - // TODO: determine the difference between sort and search locale data |
884 |
| - // const collatorLocaleData = collator.usage === "sort" ? localeData : localeData; |
| 880 | + const relevantExtensionKeys = collator.usage === "sort" ? ["co", "kn", "kf"] : ["kn", "kf"]; |
885 | 881 |
|
886 | 882 | const opt = _.create();
|
887 | 883 | opt.matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
|
888 | 884 | let kn = GetOption(options, "numeric", "boolean", undefined, undefined);
|
889 | 885 | opt.kn = kn === undefined ? kn : Internal.ToString(kn);
|
890 | 886 | opt.kf = GetOption(options, "caseFirst", "string", ["upper", "lower", "false"], undefined);
|
891 | 887 |
|
892 |
| - const r = ResolveLocale(platform.isCollatorLocaleAvailable, requestedLocales, opt, ["co", "kn", "kf"]); |
| 888 | + const r = ResolveLocale(platform.isCollatorLocaleAvailable, requestedLocales, opt, relevantExtensionKeys); |
893 | 889 | collator.locale = r.locale;
|
894 |
| - collator.collation = r.co === null ? "default" : r.co; |
| 890 | + // r.co is null when usage === "sort" and no -u-co is provided |
| 891 | + // r.co is undefined when usage === "search", since relevantExtensionKeys doesn't even look for -co |
| 892 | + collator.collation = r.co === null || r.co === undefined ? "default" : r.co; |
895 | 893 | collator.numeric = r.kn === "true";
|
896 | 894 | collator.caseFirst = r.kf;
|
897 | 895 | collator.caseFirstEnum = platform.CollatorCaseFirst[collator.caseFirst];
|
|
932 | 930 | }
|
933 | 931 |
|
934 | 932 | return platform.localeCompare(thisStr, thatStr, stateObject, /* forStringPrototypeLocaleCompare */ true);
|
935 |
| - }), IntlBuiltInFunctionID.StringLocaleCompare); |
| 933 | + }), platform.BuiltInFunctionID.StringLocaleCompare); |
936 | 934 |
|
937 | 935 | // If we were only initializing Intl for String.prototype, don't initialize Intl.Collator
|
938 | 936 | if (InitType === "String") {
|
|
1128 | 1126 |
|
1129 | 1127 | const n = Internal.ToNumber(this);
|
1130 | 1128 | return platform.formatNumber(n, stateObject, /* toParts */ false, /* forNumberPrototypeToLocaleString */ true);
|
1131 |
| - }), IntlBuiltInFunctionID.NumberToLocaleString); |
| 1129 | + }), platform.BuiltInFunctionID.NumberToLocaleString); |
1132 | 1130 |
|
1133 | 1131 | if (InitType === "Number") {
|
1134 | 1132 | return;
|
|
1665 | 1663 | platform.registerBuiltInFunction(createPublicMethod(name, function date_toLocaleString_entryPoint(locales = undefined, options = undefined) {
|
1666 | 1664 | return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
1667 | 1665 | }), platformFunctionID);
|
1668 |
| - })("Date.prototype.toLocaleString", "any", "all", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleString, IntlBuiltInFunctionID.DateToLocaleString); |
| 1666 | + })("Date.prototype.toLocaleString", "any", "all", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleString, platform.BuiltInFunctionID.DateToLocaleString); |
1669 | 1667 |
|
1670 | 1668 | (function (name, option1, option2, cacheSlot, platformFunctionID) {
|
1671 | 1669 | platform.registerBuiltInFunction(createPublicMethod(name, function date_toLocaleDateString_entryPoint(locales = undefined, options = undefined) {
|
1672 | 1670 | return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
1673 | 1671 | }), platformFunctionID);
|
1674 |
| - })("Date.prototype.toLocaleDateString", "date", "date", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleDateString, IntlBuiltInFunctionID.DateToLocaleDateString); |
| 1672 | + })("Date.prototype.toLocaleDateString", "date", "date", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleDateString, platform.BuiltInFunctionID.DateToLocaleDateString); |
1675 | 1673 |
|
1676 | 1674 | (function (name, option1, option2, cacheSlot, platformFunctionID) {
|
1677 | 1675 | platform.registerBuiltInFunction(createPublicMethod(name, function date_toLocaleTimeString_entryPoint(locales = undefined, options = undefined) {
|
1678 | 1676 | return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
1679 | 1677 | }), platformFunctionID);
|
1680 |
| - })("Date.prototype.toLocaleTimeString", "time", "time", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleTimeString, IntlBuiltInFunctionID.DateToLocaleTimeString); |
| 1678 | + })("Date.prototype.toLocaleTimeString", "time", "time", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleTimeString, platform.BuiltInFunctionID.DateToLocaleTimeString); |
1681 | 1679 |
|
1682 | 1680 | // if we were only initializing Date, dont bother initializing Intl.DateTimeFormat
|
1683 | 1681 | if (InitType !== "Intl") {
|
|
2837 | 2835 | thisArg,
|
2838 | 2836 | that,
|
2839 | 2837 | stateObject.__localeForCompare,
|
2840 |
| - toEnum(CollatorSensitivity, stateObject.__sensitivity), |
| 2838 | + platform.CollatorSensitivity[stateObject.__sensitivity], |
2841 | 2839 | stateObject.__ignorePunctuation,
|
2842 | 2840 | stateObject.__numeric,
|
2843 |
| - toEnum(CollatorCaseFirst, stateObject.__caseFirst) |
| 2841 | + platform.CollatorCaseFirst[stateObject.__caseFirst] |
2844 | 2842 | ));
|
2845 |
| - }), IntlBuiltInFunctionID.StringLocaleCompare); |
| 2843 | + }), platform.BuiltInFunctionID.StringLocaleCompare); |
2846 | 2844 |
|
2847 | 2845 | if (InitType === 'Intl') {
|
2848 | 2846 |
|
|
2890 | 2888 | a,
|
2891 | 2889 | b,
|
2892 | 2890 | hiddenObject.__localeForCompare,
|
2893 |
| - toEnum(CollatorSensitivity, hiddenObject.__sensitivity), |
| 2891 | + platform.CollatorSensitivity[hiddenObject.__sensitivity], |
2894 | 2892 | hiddenObject.__ignorePunctuation,
|
2895 | 2893 | hiddenObject.__numeric,
|
2896 |
| - toEnum(CollatorCaseFirst, hiddenObject.__caseFirst) |
| 2894 | + platform.CollatorCaseFirst[hiddenObject.__caseFirst] |
2897 | 2895 | ));
|
2898 | 2896 | }
|
2899 | 2897 | tagPublicFunction("Intl.Collator.prototype.compare", compare);
|
|
2973 | 2971 | var matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
|
2974 | 2972 | var style = GetOption(options, "style", "string", ["decimal", "percent", "currency"], "decimal");
|
2975 | 2973 |
|
2976 |
| - var formatterToUse = NumberFormatStyle.DECIMAL; // DEFAULT |
2977 |
| - if (style === 'percent') { |
2978 |
| - formatterToUse = NumberFormatStyle.PERCENT; |
2979 |
| - } else if (style === 'currency') { |
2980 |
| - formatterToUse = NumberFormatStyle.CURRENCY; |
2981 |
| - } |
| 2974 | + var formatterToUse = platform.NumberFormatStyle[style]; |
2982 | 2975 |
|
2983 | 2976 | var currency = GetOption(options, "currency", "string", undefined, undefined);
|
2984 | 2977 | var currencyDisplay = GetOption(options, 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol');
|
|
3045 | 3038 |
|
3046 | 3039 | if (currencyDisplay !== undefined) {
|
3047 | 3040 | numberFormat.__currencyDisplay = currencyDisplay;
|
3048 |
| - numberFormat.__currencyDisplayToUse = NumberFormatCurrencyDisplay.DEFAULT; |
3049 |
| - if (currencyDisplay === "symbol") { |
3050 |
| - numberFormat.__currencyDisplayToUse = NumberFormatCurrencyDisplay.SYMBOL; |
3051 |
| - } else if (currencyDisplay === "code") { |
3052 |
| - numberFormat.__currencyDisplayToUse = NumberFormatCurrencyDisplay.CODE; |
3053 |
| - } else if (currencyDisplay === "name") { |
3054 |
| - numberFormat.__currencyDisplayToUse = NumberFormatCurrencyDisplay.NAME; |
3055 |
| - } |
| 3041 | + numberFormat.__currencyDisplayToUse = platform.NumberFormatCurrencyDisplay[currencyDisplay]; |
3056 | 3042 | }
|
3057 | 3043 |
|
3058 | 3044 | numberFormat.__minimumIntegerDigits = minimumIntegerDigits;
|
|
3096 | 3082 |
|
3097 | 3083 | var n = Internal.ToNumber(this);
|
3098 | 3084 | return String(platform.formatNumber(n, stateObject));
|
3099 |
| - }), IntlBuiltInFunctionID.NumberToLocaleString); |
| 3085 | + }), platform.BuiltInFunctionID.NumberToLocaleString); |
3100 | 3086 |
|
3101 | 3087 | if (InitType === 'Intl') {
|
3102 | 3088 | function NumberFormat(locales = undefined, options = undefined) {
|
|
3618 | 3604 | platform.registerBuiltInFunction(tagPublicFunction(name, function date_toLocaleString_entryPoint(locales = undefined, options = undefined) {
|
3619 | 3605 | return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
3620 | 3606 | }), platformFunctionID);
|
3621 |
| - })("Date.prototype.toLocaleString", "any", "all", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleString, IntlBuiltInFunctionID.DateToLocaleString); |
| 3607 | + })("Date.prototype.toLocaleString", "any", "all", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleString, platform.BuiltInFunctionID.DateToLocaleString); |
3622 | 3608 |
|
3623 | 3609 | (function (name, option1, option2, cacheSlot, platformFunctionID) {
|
3624 | 3610 | platform.registerBuiltInFunction(tagPublicFunction(name, function date_toLocaleDateString_entryPoint(locales = undefined, options = undefined) {
|
3625 | 3611 | return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
3626 | 3612 | }), platformFunctionID);
|
3627 |
| - })("Date.prototype.toLocaleDateString", "date", "date", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleDateString, IntlBuiltInFunctionID.DateToLocaleDateString); |
| 3613 | + })("Date.prototype.toLocaleDateString", "date", "date", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleDateString, platform.BuiltInFunctionID.DateToLocaleDateString); |
3628 | 3614 |
|
3629 | 3615 | (function (name, option1, option2, cacheSlot, platformFunctionID) {
|
3630 | 3616 | platform.registerBuiltInFunction(tagPublicFunction(name, function date_toLocaleTimeString_entryPoint(locales = undefined, options = undefined) {
|
3631 | 3617 | return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
3632 | 3618 | }), platformFunctionID);
|
3633 |
| - })("Date.prototype.toLocaleTimeString", "time", "time", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleTimeString, IntlBuiltInFunctionID.DateToLocaleTimeString); |
| 3619 | + })("Date.prototype.toLocaleTimeString", "time", "time", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleTimeString, platform.BuiltInFunctionID.DateToLocaleTimeString); |
3634 | 3620 |
|
3635 | 3621 | if (InitType === 'Intl') {
|
3636 | 3622 | function DateTimeFormat(locales = undefined, options = undefined) {
|
|
0 commit comments