|
|
@@ -102,17 +102,6 @@
|
|
|
var isFinite = platform.builtInGlobalObjectEntryIsFinite;
|
|
|
var isNaN = platform.builtInGlobalObjectEntryIsNaN;
|
|
|
|
|
|
- // Keep this "enum" in sync with IntlEngineInterfaceExtensionObject::EntryIntl_RegisterBuiltInFunction
|
|
|
- const IntlBuiltInFunctionID = setPrototype({
|
|
|
- MIN: 0,
|
|
|
- DateToLocaleString: 0,
|
|
|
- DateToLocaleDateString: 1,
|
|
|
- DateToLocaleTimeString: 2,
|
|
|
- NumberToLocaleString: 3,
|
|
|
- StringLocaleCompare: 4,
|
|
|
- MAX: 5
|
|
|
- }, null);
|
|
|
-
|
|
|
const _ = {
|
|
|
toUpperCase(str) { return callInstanceFunc(StringInstanceToUpperCase, str); },
|
|
|
toLowerCase(str) { return callInstanceFunc(StringInstanceToLowerCase, str); },
|
|
|
@@ -879,9 +868,16 @@
|
|
|
const requestedLocales = CanonicalizeLocaleList(locales);
|
|
|
options = options === undefined ? _.create() : Internal.ToObject(options);
|
|
|
|
|
|
+ // The spec says that usage dictates whether to use "[[SearchLocaleData]]" or "[[SortLocaleData]]"
|
|
|
+ // ICU has no concept of a difference between the two, and instead sort/search corresponds to
|
|
|
+ // collation = "standard" or collation = "search", respectively. Standard/sort is the default.
|
|
|
+ // Thus, when the usage is sort, we can accept and honor -u-co in the locale, while if usage is search,
|
|
|
+ // we are going to overwrite any -u-co value provided before giving the locale to ICU anyways.
|
|
|
+ // To make the logic simpler, we can simply pretend like we don't accept a -u-co value if the usage is search.
|
|
|
+ // See the lazy UCollator initialization in EntryIntl_LocaleCompare for where the collation value
|
|
|
+ // gets overwritten by "search".
|
|
|
collator.usage = GetOption(options, "usage", "string", ["sort", "search"], "sort");
|
|
|
- // TODO: determine the difference between sort and search locale data
|
|
|
- // const collatorLocaleData = collator.usage === "sort" ? localeData : localeData;
|
|
|
+ const relevantExtensionKeys = collator.usage === "sort" ? ["co", "kn", "kf"] : ["kn", "kf"];
|
|
|
|
|
|
const opt = _.create();
|
|
|
opt.matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
|
|
|
@@ -889,9 +885,11 @@
|
|
|
opt.kn = kn === undefined ? kn : Internal.ToString(kn);
|
|
|
opt.kf = GetOption(options, "caseFirst", "string", ["upper", "lower", "false"], undefined);
|
|
|
|
|
|
- const r = ResolveLocale(platform.isCollatorLocaleAvailable, requestedLocales, opt, ["co", "kn", "kf"]);
|
|
|
+ const r = ResolveLocale(platform.isCollatorLocaleAvailable, requestedLocales, opt, relevantExtensionKeys);
|
|
|
collator.locale = r.locale;
|
|
|
- collator.collation = r.co === null ? "default" : r.co;
|
|
|
+ // r.co is null when usage === "sort" and no -u-co is provided
|
|
|
+ // r.co is undefined when usage === "search", since relevantExtensionKeys doesn't even look for -co
|
|
|
+ collator.collation = r.co === null || r.co === undefined ? "default" : r.co;
|
|
|
collator.numeric = r.kn === "true";
|
|
|
collator.caseFirst = r.kf;
|
|
|
collator.caseFirstEnum = platform.CollatorCaseFirst[collator.caseFirst];
|
|
|
@@ -932,7 +930,7 @@
|
|
|
}
|
|
|
|
|
|
return platform.localeCompare(thisStr, thatStr, stateObject, /* forStringPrototypeLocaleCompare */ true);
|
|
|
- }), IntlBuiltInFunctionID.StringLocaleCompare);
|
|
|
+ }), platform.BuiltInFunctionID.StringLocaleCompare);
|
|
|
|
|
|
// If we were only initializing Intl for String.prototype, don't initialize Intl.Collator
|
|
|
if (InitType === "String") {
|
|
|
@@ -1128,7 +1126,7 @@
|
|
|
|
|
|
const n = Internal.ToNumber(this);
|
|
|
return platform.formatNumber(n, stateObject, /* toParts */ false, /* forNumberPrototypeToLocaleString */ true);
|
|
|
- }), IntlBuiltInFunctionID.NumberToLocaleString);
|
|
|
+ }), platform.BuiltInFunctionID.NumberToLocaleString);
|
|
|
|
|
|
if (InitType === "Number") {
|
|
|
return;
|
|
|
@@ -1665,19 +1663,19 @@
|
|
|
platform.registerBuiltInFunction(createPublicMethod(name, function date_toLocaleString_entryPoint(locales = undefined, options = undefined) {
|
|
|
return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
|
|
}), platformFunctionID);
|
|
|
- })("Date.prototype.toLocaleString", "any", "all", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleString, IntlBuiltInFunctionID.DateToLocaleString);
|
|
|
+ })("Date.prototype.toLocaleString", "any", "all", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleString, platform.BuiltInFunctionID.DateToLocaleString);
|
|
|
|
|
|
(function (name, option1, option2, cacheSlot, platformFunctionID) {
|
|
|
platform.registerBuiltInFunction(createPublicMethod(name, function date_toLocaleDateString_entryPoint(locales = undefined, options = undefined) {
|
|
|
return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
|
|
}), platformFunctionID);
|
|
|
- })("Date.prototype.toLocaleDateString", "date", "date", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleDateString, IntlBuiltInFunctionID.DateToLocaleDateString);
|
|
|
+ })("Date.prototype.toLocaleDateString", "date", "date", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleDateString, platform.BuiltInFunctionID.DateToLocaleDateString);
|
|
|
|
|
|
(function (name, option1, option2, cacheSlot, platformFunctionID) {
|
|
|
platform.registerBuiltInFunction(createPublicMethod(name, function date_toLocaleTimeString_entryPoint(locales = undefined, options = undefined) {
|
|
|
return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
|
|
}), platformFunctionID);
|
|
|
- })("Date.prototype.toLocaleTimeString", "time", "time", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleTimeString, IntlBuiltInFunctionID.DateToLocaleTimeString);
|
|
|
+ })("Date.prototype.toLocaleTimeString", "time", "time", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleTimeString, platform.BuiltInFunctionID.DateToLocaleTimeString);
|
|
|
|
|
|
// if we were only initializing Date, dont bother initializing Intl.DateTimeFormat
|
|
|
if (InitType !== "Intl") {
|
|
|
@@ -2837,12 +2835,12 @@
|
|
|
thisArg,
|
|
|
that,
|
|
|
stateObject.__localeForCompare,
|
|
|
- toEnum(CollatorSensitivity, stateObject.__sensitivity),
|
|
|
+ platform.CollatorSensitivity[stateObject.__sensitivity],
|
|
|
stateObject.__ignorePunctuation,
|
|
|
stateObject.__numeric,
|
|
|
- toEnum(CollatorCaseFirst, stateObject.__caseFirst)
|
|
|
+ platform.CollatorCaseFirst[stateObject.__caseFirst]
|
|
|
));
|
|
|
- }), IntlBuiltInFunctionID.StringLocaleCompare);
|
|
|
+ }), platform.BuiltInFunctionID.StringLocaleCompare);
|
|
|
|
|
|
if (InitType === 'Intl') {
|
|
|
|
|
|
@@ -2890,10 +2888,10 @@
|
|
|
a,
|
|
|
b,
|
|
|
hiddenObject.__localeForCompare,
|
|
|
- toEnum(CollatorSensitivity, hiddenObject.__sensitivity),
|
|
|
+ platform.CollatorSensitivity[hiddenObject.__sensitivity],
|
|
|
hiddenObject.__ignorePunctuation,
|
|
|
hiddenObject.__numeric,
|
|
|
- toEnum(CollatorCaseFirst, hiddenObject.__caseFirst)
|
|
|
+ platform.CollatorCaseFirst[hiddenObject.__caseFirst]
|
|
|
));
|
|
|
}
|
|
|
tagPublicFunction("Intl.Collator.prototype.compare", compare);
|
|
|
@@ -2973,12 +2971,7 @@
|
|
|
var matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
|
|
|
var style = GetOption(options, "style", "string", ["decimal", "percent", "currency"], "decimal");
|
|
|
|
|
|
- var formatterToUse = NumberFormatStyle.DECIMAL; // DEFAULT
|
|
|
- if (style === 'percent') {
|
|
|
- formatterToUse = NumberFormatStyle.PERCENT;
|
|
|
- } else if (style === 'currency') {
|
|
|
- formatterToUse = NumberFormatStyle.CURRENCY;
|
|
|
- }
|
|
|
+ var formatterToUse = platform.NumberFormatStyle[style];
|
|
|
|
|
|
var currency = GetOption(options, "currency", "string", undefined, undefined);
|
|
|
var currencyDisplay = GetOption(options, 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol');
|
|
|
@@ -3045,14 +3038,7 @@
|
|
|
|
|
|
if (currencyDisplay !== undefined) {
|
|
|
numberFormat.__currencyDisplay = currencyDisplay;
|
|
|
- numberFormat.__currencyDisplayToUse = NumberFormatCurrencyDisplay.DEFAULT;
|
|
|
- if (currencyDisplay === "symbol") {
|
|
|
- numberFormat.__currencyDisplayToUse = NumberFormatCurrencyDisplay.SYMBOL;
|
|
|
- } else if (currencyDisplay === "code") {
|
|
|
- numberFormat.__currencyDisplayToUse = NumberFormatCurrencyDisplay.CODE;
|
|
|
- } else if (currencyDisplay === "name") {
|
|
|
- numberFormat.__currencyDisplayToUse = NumberFormatCurrencyDisplay.NAME;
|
|
|
- }
|
|
|
+ numberFormat.__currencyDisplayToUse = platform.NumberFormatCurrencyDisplay[currencyDisplay];
|
|
|
}
|
|
|
|
|
|
numberFormat.__minimumIntegerDigits = minimumIntegerDigits;
|
|
|
@@ -3096,7 +3082,7 @@
|
|
|
|
|
|
var n = Internal.ToNumber(this);
|
|
|
return String(platform.formatNumber(n, stateObject));
|
|
|
- }), IntlBuiltInFunctionID.NumberToLocaleString);
|
|
|
+ }), platform.BuiltInFunctionID.NumberToLocaleString);
|
|
|
|
|
|
if (InitType === 'Intl') {
|
|
|
function NumberFormat(locales = undefined, options = undefined) {
|
|
|
@@ -3618,19 +3604,19 @@
|
|
|
platform.registerBuiltInFunction(tagPublicFunction(name, function date_toLocaleString_entryPoint(locales = undefined, options = undefined) {
|
|
|
return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
|
|
}), platformFunctionID);
|
|
|
- })("Date.prototype.toLocaleString", "any", "all", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleString, IntlBuiltInFunctionID.DateToLocaleString);
|
|
|
+ })("Date.prototype.toLocaleString", "any", "all", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleString, platform.BuiltInFunctionID.DateToLocaleString);
|
|
|
|
|
|
(function (name, option1, option2, cacheSlot, platformFunctionID) {
|
|
|
platform.registerBuiltInFunction(tagPublicFunction(name, function date_toLocaleDateString_entryPoint(locales = undefined, options = undefined) {
|
|
|
return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
|
|
}), platformFunctionID);
|
|
|
- })("Date.prototype.toLocaleDateString", "date", "date", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleDateString, IntlBuiltInFunctionID.DateToLocaleDateString);
|
|
|
+ })("Date.prototype.toLocaleDateString", "date", "date", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleDateString, platform.BuiltInFunctionID.DateToLocaleDateString);
|
|
|
|
|
|
(function (name, option1, option2, cacheSlot, platformFunctionID) {
|
|
|
platform.registerBuiltInFunction(tagPublicFunction(name, function date_toLocaleTimeString_entryPoint(locales = undefined, options = undefined) {
|
|
|
return DateInstanceToLocaleStringImplementation.call(this, name, option1, option2, cacheSlot, locales, options);
|
|
|
}), platformFunctionID);
|
|
|
- })("Date.prototype.toLocaleTimeString", "time", "time", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleTimeString, IntlBuiltInFunctionID.DateToLocaleTimeString);
|
|
|
+ })("Date.prototype.toLocaleTimeString", "time", "time", __DateInstanceToLocaleStringDefaultCacheSlot.toLocaleTimeString, platform.BuiltInFunctionID.DateToLocaleTimeString);
|
|
|
|
|
|
if (InitType === 'Intl') {
|
|
|
function DateTimeFormat(locales = undefined, options = undefined) {
|