From a9f7fcae97de8b21f5eddd072b01d3eab81b2b6a Mon Sep 17 00:00:00 2001 From: liuzhongyu101 Date: Thu, 22 Feb 2024 14:53:37 +0800 Subject: [PATCH] intl collator & number_format --- ecmascript/dump.cpp | 5 +- ecmascript/global_env_constants.h | 16 +++ ecmascript/js_collator.cpp | 13 +- ecmascript/js_locale.h | 48 +++++++ ecmascript/js_number_format.cpp | 206 ++++++++++++++++++++++++++++-- ecmascript/js_number_format.h | 24 +++- ecmascript/object_factory.cpp | 2 +- 7 files changed, 292 insertions(+), 22 deletions(-) diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index c551ccf150..24a18c32bc 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -3144,8 +3144,7 @@ void JSNumberFormat::Dump(std::ostream &os) const GetMinimumSignificantDigits().Dump(os); os << "\n" << " - MaximumSignificantDigits: "; GetMaximumSignificantDigits().Dump(os); - os << "\n" << " - UseGrouping: "; - GetUseGrouping().Dump(os); + os << "\n" << " - UseGrouping: " << static_cast(GetUseGrouping()); os << "\n" << " - RoundingType: " << static_cast(GetRoundingType()); os << "\n" << " - Notation: " << static_cast(GetNotation()); os << "\n" << " - CompactDisplay: " << static_cast(GetCompactDisplay()); @@ -5586,7 +5585,7 @@ void JSNumberFormat::DumpForSnapshot(std::vector &vec) const vec.emplace_back(CString("MaximumFractionDigits"), GetMaximumFractionDigits()); vec.emplace_back(CString("MinimumSignificantDigits"), GetMinimumSignificantDigits()); vec.emplace_back(CString("MaximumSignificantDigits"), GetMaximumSignificantDigits()); - vec.emplace_back(CString("UseGrouping"), GetUseGrouping()); + vec.emplace_back(CString("UseGrouping"), JSTaggedValue(static_cast(GetUseGrouping()))); vec.emplace_back(CString("RoundingType"), JSTaggedValue(static_cast(GetRoundingType()))); vec.emplace_back(CString("Notation"), JSTaggedValue(static_cast(GetNotation()))); vec.emplace_back(CString("CompactDisplay"), JSTaggedValue(static_cast(GetCompactDisplay()))); diff --git a/ecmascript/global_env_constants.h b/ecmascript/global_env_constants.h index 828dc6bf9b..7792f9096a 100644 --- a/ecmascript/global_env_constants.h +++ b/ecmascript/global_env_constants.h @@ -357,10 +357,25 @@ class ObjectFactory; V(AutoString, AUTO_STRING_INDEX, "auto") \ V(ThrowString, THROW_STRING_INDEX, "throw") \ V(UnitDisplayString, UNIT_DISPLAY_INDEX, "unitDisplay") \ + V(UseGroupingString, USE_GROUPING_INDEX, "useGrouping") \ + V(OffString, OFF_STRING_INDEX, "false") \ + V(Min2String, MIN2_STRING_INDEX, "min2") \ V(NotationString, NOTATION_INDEX, "notation") \ V(CompactDisplayString, COMPACT_DISPALY_INDEX, "compactDisplay") \ V(UserGroupingString, USER_GROUPING_INDEX, "useGrouping") \ V(SignDisplayString, SIGN_DISPLAY_INDEX, "signDisplay") \ + V(CeilString, CEIL_STRING_INDEX, "ceil") \ + V(FloorString, FLOOR_STRING_INDEX, "floor") \ + V(ExpandString, EXPAND_STRING_INDEX, "expand") \ + V(TruncString, TRUNC_STRING_INDEX, "trunc") \ + V(HalfCeilString, HALF_CEIL_STRING_INDEX, "halfCeil") \ + V(HalfFloorString, HALF_FLOOR_STRING_INDEX, "halfFloor") \ + V(HalfExpandString, HALF_EXPAND_STRING_INDEX, "halfExpand") \ + V(HalfTruncString, HALF_TRUNC_STRING_INDEX, "halfTrunc") \ + V(HalfEvenString, HALF_EVEN_STRING_INDEX, "halfEven") \ + V(StripIfIntegerString, STRIP_IF_INTEGER_INDEX, "stripIfInteger") \ + V(RoundingModeString, ROUNDING_MODE_INDEX, "roundingMode") \ + V(TrailingZeroDisplayString, TRAILING_ZERO_DISPLAY_INDEX, "trailingZeroDisplay") \ V(CodeString, CODE_INDEX, "code") \ V(NarrowSymbolString, NARROW_SYMBOL_INDEX, "narrowSymbol") \ V(StandardString, STANDARD_INDEX, "standard") \ @@ -371,6 +386,7 @@ class ObjectFactory; V(CompactString, COMPACT_STRING_INDEX, "compact") \ V(NeverString, NEVER_INDEX, "never") \ V(ExceptZeroString, EXPECT_ZERO_INDEX, "exceptZero") \ + V(NegativeString, NEGATIVE_STRING_INDEX, "negative") \ V(MinimumIntegerDigitsString, MINIMUM_INTEGER_DIGITS_INDEX, "minimumIntegerDigits") \ V(MinimumFractionDigitsString, MINIMUM_FRACTIONDIGITS_INDEX, "minimumFractionDigits") \ V(MaximumFractionDigitsString, MAXIMUM_FRACTIONDIGITS_INDEX, "maximumFractionDigits") \ diff --git a/ecmascript/js_collator.cpp b/ecmascript/js_collator.cpp index ad7a4cd97c..e4d81a9fd6 100644 --- a/ecmascript/js_collator.cpp +++ b/ecmascript/js_collator.cpp @@ -451,8 +451,19 @@ JSHandle JSCollator::ResolvedOptions(JSThread *thread, const JSHandle< // [[Collation]] JSMutableHandle collationValue(thread, collator->GetCollation()); + UErrorCode status = U_ZERO_ERROR; + icu::Collator *icuCollator = collator->GetIcuCollator(); + icu::Locale icu_locale(icuCollator->getLocale(ULOC_VALID_LOCALE, status)); + std::string collation_value = + icu_locale.getUnicodeKeywordValue("co", status); if (collationValue->IsUndefined()) { - collationValue.Update(globalConst->GetDefaultString()); + if (collation_value != "search") { + JSHandle localestr = intl::LocaleHelper::ToLanguageTag(thread, icu_locale); + collator->SetLocale(thread, localestr.GetTaggedValue()); + collationValue.Update(factory->NewFromStdString(collation_value).GetTaggedValue()); + } else { + collationValue.Update(globalConst->GetDefaultString()); + } } JSObject::CreateDataProperty(thread, options, globalConst->GetHandledCollationString(), collationValue); diff --git a/ecmascript/js_locale.h b/ecmascript/js_locale.h index 7c58dd578d..78f3cbd2fb 100644 --- a/ecmascript/js_locale.h +++ b/ecmascript/js_locale.h @@ -257,6 +257,54 @@ public: return enumValues[existIdx]; } + template + static T GetStringOrBooleanOption(JSThread *thread, const JSHandle &options, + const JSHandle &property, const std::vector &enumValues, + const std::vector &strValues, T true_value, T false_value, + T fallback) { + // 1. Let value be ? Get(options, property). + OperationResult operationResult = JSObject::GetProperty(thread, options, property); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, T::EXCEPTION); + JSHandle value = operationResult.GetValue(); + + if (value->IsUndefined()) { + return fallback; + } + if (value->IsTrue()) { + return true_value; + } + + bool valueBoolean = value->ToBoolean(); + if (!valueBoolean) { + return false_value; + } + + JSHandle valueEStr = JSTaggedValue::ToString(thread, value); + if ( EcmaStringAccessor(value.GetTaggedValue()).ToStdString() == "true" || EcmaStringAccessor(value.GetTaggedValue()).ToStdString() == "false" ) { + return fallback; + } + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, T::EXCEPTION); + std::string valueStr = std::string(ConvertToString(*valueEStr, StringConvertedUsage::LOGICOPERATION)); + int existIdx = -1; + if (!enumValues.empty()) { + size_t strValuesSize = strValues.size(); + for (size_t i = 0; i < strValuesSize; i++) { + if (strValues[i] == valueStr) { + existIdx = static_cast(i); + } + } + if (existIdx == -1) { + THROW_RANGE_ERROR_AND_RETURN(thread, "getStringOption failed", T::EXCEPTION); + } + } + if (existIdx == -1) { + LOG_ECMA(FATAL) << "this branch is unreachable"; + UNREACHABLE(); + } + // e.Return value. + return enumValues[existIdx]; + } + static bool GetOptionOfBool(JSThread *thread, const JSHandle &options, const JSHandle &property, bool fallback, bool *res); diff --git a/ecmascript/js_number_format.cpp b/ecmascript/js_number_format.cpp index b05d24e0e1..c8ade3491c 100644 --- a/ecmascript/js_number_format.cpp +++ b/ecmascript/js_number_format.cpp @@ -107,6 +107,30 @@ JSHandle OptionToEcmaString(JSThread *thread, UnitDisplayOption u return result; } +JSHandle OptionToEcmaString(JSThread *thread, UseGroupingOption useGrouping) +{ + JSMutableHandle result(thread, JSTaggedValue::Undefined()); + auto globalConst = thread->GlobalConstants(); + switch (useGrouping) { + case UseGroupingOption::OFF: + result.Update(globalConst->GetHandledOffString().GetTaggedValue()); + break; + case UseGroupingOption::MIN2: + result.Update(globalConst->GetHandledMin2String().GetTaggedValue()); + break; + case UseGroupingOption::AUTO: + result.Update(globalConst->GetHandledAutoString().GetTaggedValue()); + break; + case UseGroupingOption::ALWAYS: + result.Update(globalConst->GetHandledAlwaysString().GetTaggedValue()); + break; + default: + LOG_ECMA(FATAL) << "this branch is unreachable"; + UNREACHABLE(); + } + return result; +} + JSHandle OptionToEcmaString(JSThread *thread, NotationOption notation) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); @@ -166,6 +190,67 @@ JSHandle OptionToEcmaString(JSThread *thread, SignDisplayOption s case SignDisplayOption::EXCEPTZERO: result.Update(globalConst->GetHandledExceptZeroString().GetTaggedValue()); break; + case SignDisplayOption::NEGATIVE: + result.Update(globalConst->GetHandledNegativeString().GetTaggedValue()); + break; + default: + LOG_ECMA(FATAL) << "this branch is unreachable"; + UNREACHABLE(); + } + return result; +} + +JSHandle OptionToEcmaString(JSThread *thread, RoundingModeOption roundingMode) +{ + JSMutableHandle result(thread, JSTaggedValue::Undefined()); + auto globalConst = thread->GlobalConstants(); + + switch (roundingMode) { + case RoundingModeOption::CEIL: + result.Update(globalConst->GetHandledCeilString().GetTaggedValue()); + break; + case RoundingModeOption::FLOOR: + result.Update(globalConst->GetHandledFloorString().GetTaggedValue()); + break; + case RoundingModeOption::EXPAND: + result.Update(globalConst->GetHandledExpandString().GetTaggedValue()); + break; + case RoundingModeOption::TRUNC: + result.Update(globalConst->GetHandledTruncString().GetTaggedValue()); + break; + case RoundingModeOption::HALFCEIL: + result.Update(globalConst->GetHandledHalfCeilString().GetTaggedValue()); + break; + case RoundingModeOption::HALFFLOOR: + result.Update(globalConst->GetHandledHalfFloorString().GetTaggedValue()); + break; + case RoundingModeOption::HALFEXPAND: + result.Update(globalConst->GetHandledHalfExpandString().GetTaggedValue()); + break; + case RoundingModeOption::HALFTRUNC: + result.Update(globalConst->GetHandledHalfTruncString().GetTaggedValue()); + break; + case RoundingModeOption::HALFEVEN: + result.Update(globalConst->GetHandledHalfEvenString().GetTaggedValue()); + break; + default: + LOG_ECMA(FATAL) << "this branch is unreachable"; + UNREACHABLE(); + } + return result; +} + +JSHandle OptionToEcmaString(JSThread *thread, TrailingZeroDisplayOption trailingZeroDisplay) +{ + JSMutableHandle result(thread, JSTaggedValue::Undefined()); + auto globalConst = thread->GlobalConstants(); + switch (trailingZeroDisplay) { + case TrailingZeroDisplayOption::AUTO: + result.Update(globalConst->GetHandledAutoString().GetTaggedValue()); + break; + case TrailingZeroDisplayOption::STRTPIFINTEGER: + result.Update(globalConst->GetHandledStripIfIntegerString().GetTaggedValue()); + break; default: LOG_ECMA(FATAL) << "this branch is unreachable"; UNREACHABLE(); @@ -616,15 +701,76 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleGetHandledUserGroupingString(); - bool useGrouping = false; - [[maybe_unused]] bool find = JSLocale::GetOptionOfBool(thread, optionsObject, property, true, &useGrouping); + UseGroupingOption defaultUseGrouping = UseGroupingOption::AUTO; + auto useGrouping = JSLocale::GetStringOrBooleanOption( + thread, optionsObject, property, + {UseGroupingOption::MIN2, UseGroupingOption::AUTO, UseGroupingOption::ALWAYS}, + {"min2", "auto", "always"}, + UseGroupingOption::ALWAYS, //trueValue + UseGroupingOption::OFF, //falseValue + defaultUseGrouping); // fallback RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle useGroupingValue(thread, JSTaggedValue(useGrouping)); - numberFormat->SetUseGrouping(thread, useGroupingValue); + numberFormat->SetUseGrouping(useGrouping); // 25. Set numberFormat.[[UseGrouping]] to useGrouping. - if (!useGrouping) { - icuNumberFormatter = icuNumberFormatter.grouping(UNumberGroupingStrategy::UNUM_GROUPING_OFF); + + switch (useGrouping) { + case UseGroupingOption::OFF: + icuNumberFormatter = icuNumberFormatter.grouping(UNumberGroupingStrategy::UNUM_GROUPING_OFF); + break; + case UseGroupingOption::MIN2: + icuNumberFormatter = icuNumberFormatter.grouping(UNumberGroupingStrategy::UNUM_GROUPING_MIN2); + break; + case UseGroupingOption::AUTO: + icuNumberFormatter = icuNumberFormatter.grouping(UNumberGroupingStrategy::UNUM_GROUPING_AUTO); + break; + case UseGroupingOption::ALWAYS: + icuNumberFormatter = icuNumberFormatter.grouping(UNumberGroupingStrategy::UNUM_GROUPING_ON_ALIGNED); + break; + default: + break; + } + + property = globalConst->GetHandledRoundingModeString(); + auto roundingMode = JSLocale::GetOptionOfString( + thread, optionsObject, property, + {RoundingModeOption::CEIL, RoundingModeOption::FLOOR, RoundingModeOption::EXPAND, RoundingModeOption::TRUNC, RoundingModeOption::HALFCEIL, + RoundingModeOption::HALFFLOOR, RoundingModeOption::HALFEXPAND, RoundingModeOption::HALFTRUNC, RoundingModeOption::HALFEVEN}, + {"ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven"}, RoundingModeOption::HALFEXPAND); + RETURN_IF_ABRUPT_COMPLETION(thread); + numberFormat->SetRoundingMode(roundingMode); + + switch (roundingMode) { + case RoundingModeOption::CEIL: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_CEILING); + break; + case RoundingModeOption::FLOOR: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_FLOOR); + break; + case RoundingModeOption::EXPAND: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_UP); + break; + case RoundingModeOption::TRUNC: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_DOWN); + break; + case RoundingModeOption::HALFCEIL: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALF_CEILING); + break; + case RoundingModeOption::HALFFLOOR: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALF_FLOOR); + break; + case RoundingModeOption::HALFEXPAND: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALFUP); + break; + case RoundingModeOption::HALFTRUNC: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALFDOWN); + break; + case RoundingModeOption::HALFEVEN: + icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALFEVEN); + break; + default: + std::cerr << "------roundingMode break----------" << std::endl; + break; } // 26. Let signDisplay be ? @@ -632,8 +778,8 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleGetHandledSignDisplayString(); auto signDisplay = JSLocale::GetOptionOfString( thread, optionsObject, property, - {SignDisplayOption::AUTO, SignDisplayOption::NEVER, SignDisplayOption::ALWAYS, SignDisplayOption::EXCEPTZERO}, - {"auto", "never", "always", "exceptZero"}, SignDisplayOption::AUTO); + {SignDisplayOption::AUTO, SignDisplayOption::NEVER, SignDisplayOption::ALWAYS, SignDisplayOption::EXCEPTZERO, SignDisplayOption::NEGATIVE}, + {"auto", "never", "always", "exceptZero", "negative"}, SignDisplayOption::AUTO); RETURN_IF_ABRUPT_COMPLETION(thread); numberFormat->SetSignDisplay(signDisplay); @@ -672,10 +818,27 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleGetHandledTrailingZeroDisplayString(); + auto trailingZeroDisplay = JSLocale::GetOptionOfString( + thread, optionsObject, property, + {TrailingZeroDisplayOption::AUTO, TrailingZeroDisplayOption::STRTPIFINTEGER}, + {"auto", "stripIfInteger"}, TrailingZeroDisplayOption::AUTO); + RETURN_IF_ABRUPT_COMPLETION(thread); + numberFormat->SetTrailingZeroDisplay(trailingZeroDisplay); + if (forIcuCache) { std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); @@ -1055,8 +1218,16 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledUserGroupingString(); - JSObject::CreateDataPropertyOrThrow(thread, options, property, - JSHandle(thread, numberFormat->GetUseGrouping())); + UseGroupingOption useGrouping = numberFormat->GetUseGrouping(); + if ( useGrouping == UseGroupingOption::OFF ) { + JSHandle useGroup(thread, JSTaggedValue(false)); + // std::cerr << "------useGrouping == UseGroupingOption::OFF-----------" << std::endl; + JSObject::CreateDataPropertyOrThrow(thread, options, property, useGroup); + } else { + JSHandle useGroupingString = OptionToEcmaString(thread, useGrouping); + // std::cerr << "------UseGrouping-----------" << EcmaStringAccessor(useGroupingString.GetTaggedValue()).ToStdString() << std::endl; + JSObject::CreateDataPropertyOrThrow(thread, options, property, useGroupingString); + } RETURN_IF_ABRUPT_COMPLETION(thread); // [[Notation]] @@ -1081,6 +1252,19 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetSignDisplay(); JSHandle signDisplayString = OptionToEcmaString(thread, signDisplay); JSObject::CreateDataPropertyOrThrow(thread, options, property, signDisplayString); - RETURN_IF_ABRUPT_COMPLETION(thread); + + // [[RoundingMode]] + property = globalConst->GetHandledRoundingModeString(); + RoundingModeOption roundingMode= numberFormat->GetRoundingMode(); + JSHandle roundingModeString = OptionToEcmaString(thread, roundingMode); + // std::cerr << "------RoundingMode-----------" << EcmaStringAccessor(roundingModeString.GetTaggedValue()).ToStdString() << std::endl; + JSObject::CreateDataPropertyOrThrow(thread, options, property, roundingModeString); + + // TrailingZeroDisplay + property = globalConst->GetHandledTrailingZeroDisplayString(); + TrailingZeroDisplayOption trailingZeroDisplay = numberFormat->GetTrailingZeroDisplay(); + JSHandle trailingZeroDisplayString = OptionToEcmaString(thread, trailingZeroDisplay); + // std::cerr << "------TrailingZeroDisplay-----------" << EcmaStringAccessor(trailingZeroDisplayString.GetTaggedValue()).ToStdString() << std::endl; + JSObject::CreateDataPropertyOrThrow(thread, options, property, trailingZeroDisplayString); } } // namespace panda::ecmascript \ No newline at end of file diff --git a/ecmascript/js_number_format.h b/ecmascript/js_number_format.h index d58bc3f20e..d4cadac1a0 100644 --- a/ecmascript/js_number_format.h +++ b/ecmascript/js_number_format.h @@ -29,7 +29,13 @@ enum class StyleOption : uint8_t { DECIMAL = 0x01, CURRENCY, PERCENT, UNIT, EXCE enum class CompactDisplayOption : uint8_t { SHORT = 0x01, LONG, EXCEPTION }; -enum class SignDisplayOption : uint8_t { AUTO = 0x01, ALWAYS, NEVER, EXCEPTZERO, EXCEPTION }; +enum class UseGroupingOption : uint8_t { OFF = 0x01, MIN2 , AUTO, ALWAYS, EXCEPTION }; + +enum class SignDisplayOption : uint8_t { AUTO = 0x01, ALWAYS, NEVER, EXCEPTZERO, NEGATIVE, EXCEPTION }; + +enum class RoundingModeOption : uint8_t { CEIL = 0x01, FLOOR, EXPAND, TRUNC, HALFCEIL, HALFFLOOR, HALFEXPAND, HALFTRUNC, HALFEVEN, EXCEPTION }; + +enum class TrailingZeroDisplayOption : uint8_t { AUTO = 0x01, STRTPIFINTEGER, EXCEPTION }; enum class CurrencyDisplayOption : uint8_t { CODE = 0x01, SYMBOL, NARROWSYMBOL, NAME, EXCEPTION }; @@ -64,8 +70,8 @@ public: ACCESSORS(MaximumFractionDigits, MAXIMUM_FRACTION_DIGITS_OFFSET, MINIMUM_SIGNIFICANT_DIGITS_OFFSET) ACCESSORS(MinimumSignificantDigits, MINIMUM_SIGNIFICANT_DIGITS_OFFSET, MAXIMUM_SIGNIFICANT_DIGITS_OFFSET) ACCESSORS(MaximumSignificantDigits, MAXIMUM_SIGNIFICANT_DIGITS_OFFSET, USER_GROUPING_OFFSET) - ACCESSORS(UseGrouping, USER_GROUPING_OFFSET, BOUND_FORMAT_OFFSET) - ACCESSORS(BoundFormat, BOUND_FORMAT_OFFSET, ICU_FIELD_OFFSET) + // ACCESSORS(UseGrouping, USER_GROUPING_OFFSET, BOUND_FORMAT_OFFSET) + ACCESSORS(BoundFormat, USER_GROUPING_OFFSET, ICU_FIELD_OFFSET) ACCESSORS(IcuField, ICU_FIELD_OFFSET, BIT_FIELD_OFFSET) ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) DEFINE_ALIGN_SIZE(LAST_OFFSET); @@ -75,7 +81,10 @@ public: static constexpr size_t CURRENCY_SIGN_BITS = 2; static constexpr size_t CURRENCY_DISPLAY_BITS = 3; static constexpr size_t UNIT_DISPLAY_BITS = 3; - static constexpr size_t SIGN_DISPLAY_BITS = 3; + static constexpr size_t USE_GROUPING_BITS = 3; + static constexpr size_t SIGN_DISPLAY_BITS = 4; + static constexpr size_t ROUNDING_MODE_BITS = 5; + static constexpr size_t TRAILING_ZERO_DISPLAY_BITS = 3; static constexpr size_t COMPACT_DISPLAY_BITS = 2; static constexpr size_t NOTATION_BITS = 3; static constexpr size_t ROUNDING_TYPE_BITS = 3; @@ -83,8 +92,11 @@ public: NEXT_BIT_FIELD(BitField, CurrencySign, CurrencySignOption, CURRENCY_SIGN_BITS, Style) NEXT_BIT_FIELD(BitField, CurrencyDisplay, CurrencyDisplayOption, CURRENCY_DISPLAY_BITS, CurrencySign) NEXT_BIT_FIELD(BitField, UnitDisplay, UnitDisplayOption, UNIT_DISPLAY_BITS, CurrencyDisplay) - NEXT_BIT_FIELD(BitField, SignDisplay, SignDisplayOption, SIGN_DISPLAY_BITS, UnitDisplay) - NEXT_BIT_FIELD(BitField, CompactDisplay, CompactDisplayOption, COMPACT_DISPLAY_BITS, SignDisplay) + NEXT_BIT_FIELD(BitField, UseGrouping, UseGroupingOption, USE_GROUPING_BITS, UnitDisplay) + NEXT_BIT_FIELD(BitField, SignDisplay, SignDisplayOption, SIGN_DISPLAY_BITS, UseGrouping) + NEXT_BIT_FIELD(BitField, RoundingMode, RoundingModeOption, ROUNDING_MODE_BITS, SignDisplay) + NEXT_BIT_FIELD(BitField, TrailingZeroDisplay, TrailingZeroDisplayOption, TRAILING_ZERO_DISPLAY_BITS, RoundingMode) + NEXT_BIT_FIELD(BitField, CompactDisplay, CompactDisplayOption, COMPACT_DISPLAY_BITS, TrailingZeroDisplay) NEXT_BIT_FIELD(BitField, Notation, NotationOption, NOTATION_BITS, CompactDisplay) NEXT_BIT_FIELD(BitField, RoundingType, RoundingType, ROUNDING_TYPE_BITS, Notation) diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 92089ca2b4..ee608516d3 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -1064,7 +1064,7 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa JSNumberFormat::Cast(*obj)->SetMaximumFractionDigits(thread_, JSTaggedValue::Undefined()); JSNumberFormat::Cast(*obj)->SetMinimumSignificantDigits(thread_, JSTaggedValue::Undefined()); JSNumberFormat::Cast(*obj)->SetMaximumSignificantDigits(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetUseGrouping(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetUseGrouping(UseGroupingOption::EXCEPTION); JSNumberFormat::Cast(*obj)->SetBoundFormat(thread_, JSTaggedValue::Undefined()); JSNumberFormat::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); JSNumberFormat::Cast(*obj)->SetStyle(StyleOption::EXCEPTION); -- Gitee