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:
zhujie81 2023-03-15 09:58:26 +08:00
parent 6041daede2
commit 1457b8d407
7 changed files with 29 additions and 29 deletions

View File

@ -270,7 +270,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv)
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
if (cacheable) { if (cacheable) {
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales, auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
IcuFormatterType::SimpleDateFormatDefault); IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT);
if (simpleDateFormat != nullptr) { if (simpleDateFormat != nullptr) {
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x); JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -290,7 +290,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (cacheable) { if (cacheable) {
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales, auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
IcuFormatterType::SimpleDateFormatDefault); IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT);
ASSERT(simpleDateFormat != nullptr); ASSERT(simpleDateFormat != nullptr);
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x); JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -350,7 +350,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv)
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
if (cacheable) { if (cacheable) {
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales, auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
IcuFormatterType::SimpleDateFormatDate); IcuFormatterType::SIMPLE_DATE_FORMAT_DATE);
if (simpleDateFormat != nullptr) { if (simpleDateFormat != nullptr) {
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x); JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -370,7 +370,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (cacheable) { if (cacheable) {
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales, auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
IcuFormatterType::SimpleDateFormatDate); IcuFormatterType::SIMPLE_DATE_FORMAT_DATE);
ASSERT(simpleDateFormat != nullptr); ASSERT(simpleDateFormat != nullptr);
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x); JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -430,7 +430,7 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv)
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
if (cacheable) { if (cacheable) {
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales, auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
IcuFormatterType::SimpleDateFormatTime); IcuFormatterType::SIMPLE_DATE_FORMAT_TIME);
if (simpleDateFormat != nullptr) { if (simpleDateFormat != nullptr) {
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x); JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -450,7 +450,7 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (cacheable) { if (cacheable) {
auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales, auto simpleDateFormat = JSDateTimeFormat::GetCachedIcuSimpleDateFormat(thread, locales,
IcuFormatterType::SimpleDateFormatTime); IcuFormatterType::SIMPLE_DATE_FORMAT_TIME);
ASSERT(simpleDateFormat != nullptr); ASSERT(simpleDateFormat != nullptr);
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x); JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, simpleDateFormat, x);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);

View File

@ -87,11 +87,11 @@ class ConstantPool;
class OptCodeProfiler; class OptCodeProfiler;
enum class IcuFormatterType { enum class IcuFormatterType {
SimpleDateFormatDefault, SIMPLE_DATE_FORMAT_DEFAULT,
SimpleDateFormatDate, SIMPLE_DATE_FORMAT_DATE,
SimpleDateFormatTime, SIMPLE_DATE_FORMAT_TIME,
NumberFormatter, NUMBER_FORMATTER,
Collator COLLATOR
}; };
using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm, using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm,
const JSHandle<JSPromise> promise, const JSHandle<JSPromise> promise,

View File

@ -90,19 +90,19 @@ public:
IcuFormatterType icuType; IcuFormatterType icuType;
switch (types) { switch (types) {
case GlobalFormatterType::Collator: case GlobalFormatterType::Collator:
icuType = IcuFormatterType::Collator; icuType = IcuFormatterType::COLLATOR;
break; break;
case GlobalFormatterType::SimpleDateFormatDate: case GlobalFormatterType::SimpleDateFormatDate:
icuType = IcuFormatterType::SimpleDateFormatDate; icuType = IcuFormatterType::SIMPLE_DATE_FORMAT_DATE;
break; break;
case GlobalFormatterType::SimpleDateFormatTime: case GlobalFormatterType::SimpleDateFormatTime:
icuType = IcuFormatterType::SimpleDateFormatTime; icuType = IcuFormatterType::SIMPLE_DATE_FORMAT_TIME;
break; break;
case GlobalFormatterType::DateFormatter: case GlobalFormatterType::DateFormatter:
icuType = IcuFormatterType::SimpleDateFormatDefault; icuType = IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT;
break; break;
case GlobalFormatterType::NumberFormatter: case GlobalFormatterType::NumberFormatter:
icuType = IcuFormatterType::NumberFormatter; icuType = IcuFormatterType::NUMBER_FORMATTER;
break; break;
} }
EcmaVM *ecmaVm = thread->GetEcmaVM(); EcmaVM *ecmaVm = thread->GetEcmaVM();
@ -118,15 +118,15 @@ public:
if (cache) { if (cache) {
T *cacheObject = tObject.release(); T *cacheObject = tObject.release();
switch (icuType) { switch (icuType) {
case IcuFormatterType::Collator: case IcuFormatterType::COLLATOR:
ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeCollatorFormat); ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeCollatorFormat);
break; break;
case IcuFormatterType::SimpleDateFormatDate: case IcuFormatterType::SIMPLE_DATE_FORMAT_DATE:
case IcuFormatterType::SimpleDateFormatTime: case IcuFormatterType::SIMPLE_DATE_FORMAT_TIME:
case IcuFormatterType::SimpleDateFormatDefault: case IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT:
ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeDateTimeFormat); ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeDateTimeFormat);
break; break;
case IcuFormatterType::NumberFormatter: case IcuFormatterType::NUMBER_FORMATTER:
ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeNumberFormat); ecmaVm->SetIcuFormatterToCache(icuType, cacheEntry, cacheObject, FreeNumberFormat);
break; break;
} }

View File

@ -467,7 +467,7 @@ std::string LocaleHelper::BestAvailableLocale(const std::vector<std::string> &av
pos -= INTL_INDEX_TWO; pos -= INTL_INDEX_TWO;
} }
// d. Let candidate be the substring of candidate from position 0, inclusive, to position pos, exclusive. // 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 } // namespace panda::ecmascript::base

View File

@ -287,7 +287,7 @@ JSHandle<JSCollator> JSCollator::InitializeCollator(JSThread *thread,
if (forIcuCache) { if (forIcuCache) {
std::string cacheEntry = std::string cacheEntry =
locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::Collator, cacheEntry, icuCollator.release(), ecmaVm->SetIcuFormatterToCache(IcuFormatterType::COLLATOR, cacheEntry, icuCollator.release(),
JSCollator::FreeIcuCollator); JSCollator::FreeIcuCollator);
} else { } else {
SetIcuCollator(thread, collator, icuCollator.release(), JSCollator::FreeIcuCollator); 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(); std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
EcmaVM *ecmaVm = thread->GetEcmaVM(); EcmaVM *ecmaVm = thread->GetEcmaVM();
void *cachedCollator = ecmaVm->GetIcuFormatterFromCache(IcuFormatterType::Collator, cacheEntry); void *cachedCollator = ecmaVm->GetIcuFormatterFromCache(IcuFormatterType::COLLATOR, cacheEntry);
if (cachedCollator != nullptr) { if (cachedCollator != nullptr) {
return reinterpret_cast<icu::Collator*>(cachedCollator); return reinterpret_cast<icu::Collator*>(cachedCollator);
} }

View File

@ -456,15 +456,15 @@ JSHandle<JSDateTimeFormat> JSDateTimeFormat::InitializeDateTimeFormat(JSThread *
locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
switch (type) { switch (type) {
case IcuCacheType::DEFAULT: case IcuCacheType::DEFAULT:
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SimpleDateFormatDefault, cacheEntry, ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SIMPLE_DATE_FORMAT_DEFAULT, cacheEntry,
simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat); simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat);
break; break;
case IcuCacheType::DATE: case IcuCacheType::DATE:
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SimpleDateFormatDate, cacheEntry, ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SIMPLE_DATE_FORMAT_DATE, cacheEntry,
simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat); simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat);
break; break;
case IcuCacheType::TIME: case IcuCacheType::TIME:
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SimpleDateFormatTime, cacheEntry, ecmaVm->SetIcuFormatterToCache(IcuFormatterType::SIMPLE_DATE_FORMAT_TIME, cacheEntry,
simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat); simpleDateFormatIcu.release(), JSDateTimeFormat::FreeSimpleDateFormat);
break; break;
default: default:

View File

@ -668,7 +668,7 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle<JSN
std::string cacheEntry = std::string cacheEntry =
locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
auto formatterPointer = new icu::number::LocalizedNumberFormatter(icuNumberFormatter); auto formatterPointer = new icu::number::LocalizedNumberFormatter(icuNumberFormatter);
ecmaVm->SetIcuFormatterToCache(IcuFormatterType::NumberFormatter, cacheEntry, formatterPointer, ecmaVm->SetIcuFormatterToCache(IcuFormatterType::NUMBER_FORMATTER, cacheEntry, formatterPointer,
JSNumberFormat::FreeIcuNumberformat); JSNumberFormat::FreeIcuNumberformat);
} else { } else {
// Set numberFormat.[[IcuNumberForma]] to handleNumberFormatter // Set numberFormat.[[IcuNumberForma]] to handleNumberFormatter
@ -697,7 +697,7 @@ icu::number::LocalizedNumberFormatter *JSNumberFormat::GetCachedIcuNumberFormatt
{ {
std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
EcmaVM *ecmaVm = thread->GetEcmaVM(); EcmaVM *ecmaVm = thread->GetEcmaVM();
void *cachedNumberFormatter = ecmaVm->GetIcuFormatterFromCache(IcuFormatterType::NumberFormatter, cacheEntry); void *cachedNumberFormatter = ecmaVm->GetIcuFormatterFromCache(IcuFormatterType::NUMBER_FORMATTER, cacheEntry);
if (cachedNumberFormatter) { if (cachedNumberFormatter) {
return reinterpret_cast<icu::number::LocalizedNumberFormatter*>(cachedNumberFormatter); return reinterpret_cast<icu::number::LocalizedNumberFormatter*>(cachedNumberFormatter);
} }