mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 18:20:04 +00:00
ix file formatting and locale "resize" function
Update the class code https://gitee.com/zhujie81/arkcompiler_ets_runtime/issues/I6N6Y1 Signed-off-by: zhujie81 <zhujie81@huawei.com>
This commit is contained in:
parent
6041daede2
commit
1457b8d407
@ -270,7 +270,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv)
|
||||
#ifdef ARK_SUPPORT_INTL
|
||||
if (cacheable) {
|
||||
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
|
||||
IcuFormatterType::SimpleDateFormatDefault);
|
||||
IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT);
|
||||
if (simpleDateFormat != nullptr) {
|
||||
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
@ -290,7 +290,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv)
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (cacheable) {
|
||||
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
|
||||
IcuFormatterType::SimpleDateFormatDefault);
|
||||
IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT);
|
||||
ASSERT(simpleDateFormat != nullptr);
|
||||
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
@ -350,7 +350,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv)
|
||||
#ifdef ARK_SUPPORT_INTL
|
||||
if (cacheable) {
|
||||
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
|
||||
IcuFormatterType::SimpleDateFormatDate);
|
||||
IcuFormatterType::SIMPLE_DATE_FORMAT_DATE);
|
||||
if (simpleDateFormat != nullptr) {
|
||||
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
@ -370,7 +370,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv)
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (cacheable) {
|
||||
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
|
||||
IcuFormatterType::SimpleDateFormatDate);
|
||||
IcuFormatterType::SIMPLE_DATE_FORMAT_DATE);
|
||||
ASSERT(simpleDateFormat != nullptr);
|
||||
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
@ -430,7 +430,7 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv)
|
||||
#ifdef ARK_SUPPORT_INTL
|
||||
if (cacheable) {
|
||||
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
|
||||
IcuFormatterType::SimpleDateFormatTime);
|
||||
IcuFormatterType::SIMPLE_DATE_FORMAT_TIME);
|
||||
if (simpleDateFormat != nullptr) {
|
||||
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
@ -450,7 +450,7 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv)
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (cacheable) {
|
||||
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
|
||||
IcuFormatterType::SimpleDateFormatTime);
|
||||
IcuFormatterType::SIMPLE_DATE_FORMAT_TIME);
|
||||
ASSERT(simpleDateFormat != nullptr);
|
||||
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
|
@ -87,11 +87,11 @@ class ConstantPool;
|
||||
class OptCodeProfiler;
|
||||
|
||||
enum class IcuFormatterType {
|
||||
SimpleDateFormatDefault,
|
||||
SimpleDateFormatDate,
|
||||
SimpleDateFormatTime,
|
||||
NumberFormatter,
|
||||
Collator
|
||||
SIMPLE_DATE_FORMAT_DEFAULT,
|
||||
SIMPLE_DATE_FORMAT_DATE,
|
||||
SIMPLE_DATE_FORMAT_TIME,
|
||||
NUMBER_FORMATTER,
|
||||
COLLATOR
|
||||
};
|
||||
using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm,
|
||||
const JSHandle<JSPromise> promise,
|
||||
|
@ -90,19 +90,19 @@ public:
|
||||
IcuFormatterType icuType;
|
||||
switch (types) {
|
||||
case GlobalFormatterType::Collator:
|
||||
icuType = IcuFormatterType::Collator;
|
||||
icuType = IcuFormatterType::COLLATOR;
|
||||
break;
|
||||
case GlobalFormatterType::SimpleDateFormatDate:
|
||||
icuType = IcuFormatterType::SimpleDateFormatDate;
|
||||
icuType = IcuFormatterType::SIMPLE_DATE_FORMAT_DATE;
|
||||
break;
|
||||
case GlobalFormatterType::SimpleDateFormatTime:
|
||||
icuType = IcuFormatterType::SimpleDateFormatTime;
|
||||
icuType = IcuFormatterType::SIMPLE_DATE_FORMAT_TIME;
|
||||
break;
|
||||
case GlobalFormatterType::DateFormatter:
|
||||
icuType = IcuFormatterType::SimpleDateFormatDefault;
|
||||
icuType = IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT;
|
||||
break;
|
||||
case GlobalFormatterType::NumberFormatter:
|
||||
icuType = IcuFormatterType::NumberFormatter;
|
||||
icuType = IcuFormatterType::NUMBER_FORMATTER;
|
||||
break;
|
||||
}
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
@ -118,15 +118,15 @@ public:
|
||||
if (cache) {
|
||||
T *cacheObject = tObject.release();
|
||||
switch (icuType) {
|
||||
case IcuFormatterType::Collator:
|
||||
case IcuFormatterType::COLLATOR:
|
||||
ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeCollatorFormat);
|
||||
break;
|
||||
case IcuFormatterType::SimpleDateFormatDate:
|
||||
case IcuFormatterType::SimpleDateFormatTime:
|
||||
case IcuFormatterType::SimpleDateFormatDefault:
|
||||
case IcuFormatterType::SIMPLE_DATE_FORMAT_DATE:
|
||||
case IcuFormatterType::SIMPLE_DATE_FORMAT_TIME:
|
||||
case IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT:
|
||||
ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeDateTimeFormat);
|
||||
break;
|
||||
case IcuFormatterType::NumberFormatter:
|
||||
case IcuFormatterType::NUMBER_FORMATTER:
|
||||
ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeNumberFormat);
|
||||
break;
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ std::string LocaleHelper::BestAvailableLocale(const std::vector<std::string> &av
|
||||
pos -= INTL_INDEX_TWO;
|
||||
}
|
||||
// d. Let candidate be the substring of candidate from position 0, inclusive, to position pos, exclusive.
|
||||
localeCandidate = localeCandidate.substr(0, pos);
|
||||
localeCandidate.resize(pos);
|
||||
}
|
||||
}
|
||||
} // namespace panda::ecmascript::base
|
@ -287,7 +287,7 @@ JSHandle<JSCollator> JSCollator::InitializeCollator(JSThread *thread,
|
||||
if (forIcuCache) {
|
||||
std::string cacheEntry =
|
||||
locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::Collator, cacheEntry, icuCollator.release(),
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::COLLATOR, cacheEntry, icuCollator.release(),
|
||||
JSCollator::FreeIcuCollator);
|
||||
} else {
|
||||
SetIcuCollator(thread, collator, icuCollator.release(), JSCollator::FreeIcuCollator);
|
||||
@ -301,7 +301,7 @@ icu::Collator *JSCollator::GetCachedIcuCollator(JSThread *thread, const JSHandle
|
||||
{
|
||||
std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
void *cachedCollator = ecmaVm->GetIcuFormatterFromCache(IcuFormatterType::Collator, cacheEntry);
|
||||
void *cachedCollator = ecmaVm->GetIcuFormatterFromCache(IcuFormatterType::COLLATOR, cacheEntry);
|
||||
if (cachedCollator != nullptr) {
|
||||
return reinterpret_cast<icu::Collator*>(cachedCollator);
|
||||
}
|
||||
|
@ -456,15 +456,15 @@ JSHandle<JSDateTimeFormat> JSDateTimeFormat::InitializeDateTimeFormat(JSThread *
|
||||
locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
|
||||
switch (type) {
|
||||
case IcuCacheType::DEFAULT:
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SimpleDateFormatDefault, cacheEntry,
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT, cacheEntry,
|
||||
simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat);
|
||||
break;
|
||||
case IcuCacheType::DATE:
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SimpleDateFormatDate, cacheEntry,
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SIMPLE_DATE_FORMAT_DATE, cacheEntry,
|
||||
simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat);
|
||||
break;
|
||||
case IcuCacheType::TIME:
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SimpleDateFormatTime, cacheEntry,
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SIMPLE_DATE_FORMAT_TIME, cacheEntry,
|
||||
simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat);
|
||||
break;
|
||||
default:
|
||||
|
@ -668,7 +668,7 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle<JSN
|
||||
std::string cacheEntry =
|
||||
locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
|
||||
auto formatterPointer = new icu::number::LocalizedNumberFormatter(icuNumberFormatter);
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::NumberFormatter, cacheEntry, formatterPointer,
|
||||
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::NUMBER_FORMATTER, cacheEntry, formatterPointer,
|
||||
JSNumberFormat::FreeIcuNumberformat);
|
||||
} else {
|
||||
// Set numberFormat.[[IcuNumberForma]] to handleNumberFormatter
|
||||
@ -697,7 +697,7 @@ icu::number::LocalizedNumberFormatter *JSNumberFormat::GetCachedIcuNumberFormatt
|
||||
{
|
||||
std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
void *cachedNumberFormatter = ecmaVm->GetIcuFormatterFromCache(IcuFormatterType::NumberFormatter, cacheEntry);
|
||||
void *cachedNumberFormatter = ecmaVm->GetIcuFormatterFromCache(IcuFormatterType::NUMBER_FORMATTER, cacheEntry);
|
||||
if (cachedNumberFormatter) {
|
||||
return reinterpret_cast<icu::number::LocalizedNumberFormatter*>(cachedNumberFormatter);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user