[Intl] Refactor logic of CurrencyDigits to Intl:: for C++.
Bug: v8:7979 Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng Change-Id: Idbda0c93f55fe8a9b560ee006a3ed7dcceb1a540 Reviewed-on: https://chromium-review.googlesource.com/1149442 Commit-Queue: Frank Tang <ftang@chromium.org> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#54708}
This commit is contained in:
parent
208430c34a
commit
6c27d79d7a
@ -1719,5 +1719,20 @@ MaybeHandle<String> Intl::CanonicalizeLanguageTag(Isolate* isolate,
|
||||
.ToHandleChecked();
|
||||
}
|
||||
|
||||
// ecma-402/#sec-currencydigits
|
||||
Handle<Smi> Intl::CurrencyDigits(Isolate* isolate, Handle<String> currency) {
|
||||
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
|
||||
v8::String::Value currency_string(v8_isolate, v8::Utils::ToLocal(currency));
|
||||
CHECK_NOT_NULL(*currency_string);
|
||||
|
||||
DisallowHeapAllocation no_gc;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
uint32_t fraction_digits = ucurr_getDefaultFractionDigits(
|
||||
reinterpret_cast<const UChar*>(*currency_string), &status);
|
||||
// For missing currency codes, default to the most common, 2
|
||||
if (U_FAILURE(status)) fraction_digits = 2;
|
||||
return Handle<Smi>(Smi::FromInt(fraction_digits), isolate);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -302,6 +302,10 @@ class Intl {
|
||||
// Canonicalize the localeID.
|
||||
static MaybeHandle<String> CanonicalizeLanguageTag(Isolate* isolate,
|
||||
Handle<Object> localeID);
|
||||
|
||||
// ecma-402/#sec-currencydigits
|
||||
// The currency is expected to an all upper case string value.
|
||||
static Handle<Smi> CurrencyDigits(Isolate* isolate, Handle<String> currency);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
@ -258,20 +258,10 @@ RUNTIME_FUNCTION(Runtime_InternalNumberFormat) {
|
||||
}
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_CurrencyDigits) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK_EQ(1, args.length());
|
||||
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
|
||||
|
||||
CONVERT_ARG_HANDLE_CHECKED(String, currency, 0);
|
||||
|
||||
v8::String::Value currency_string(v8_isolate, v8::Utils::ToLocal(currency));
|
||||
|
||||
DisallowHeapAllocation no_gc;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
uint32_t fraction_digits = ucurr_getDefaultFractionDigits(
|
||||
reinterpret_cast<const UChar*>(*currency_string), &status);
|
||||
// For missing currency codes, default to the most common, 2
|
||||
if (!U_SUCCESS(status)) fraction_digits = 2;
|
||||
return Smi::FromInt(fraction_digits);
|
||||
return *Intl::CurrencyDigits(isolate, currency);
|
||||
}
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_CreateCollator) {
|
||||
|
Loading…
Reference in New Issue
Block a user