diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index 42d1379d78d1dd7afe2e623577cd609962dcc486..6f4f7c4c60018aaf0aa0e8efcdcc3fdfd9662894 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -5580,7 +5580,7 @@ void JSRelativeTimeFormat::DumpForSnapshot(std::vector &vec) const void JSNumberFormat::DumpForSnapshot(std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below - constexpr int16_t NUM_OF_ITEMS = 20; + constexpr int16_t NUM_OF_ITEMS = 24; vec.reserve(vec.size() + NUM_OF_ITEMS); vec.emplace_back(CString("Locale"), GetLocale()); vec.emplace_back(CString("NumberingSystem"), GetNumberingSystem()); @@ -5629,7 +5629,7 @@ void JSCollator::DumpForSnapshot(std::vector &vec) const void JSPluralRules::DumpForSnapshot(std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below - constexpr int16_t NUM_OF_ITEMS = 10; + constexpr int16_t NUM_OF_ITEMS = 14; vec.reserve(vec.size() + NUM_OF_ITEMS); vec.emplace_back(CString("Locale"), GetLocale()); vec.emplace_back(CString("MinimumIntegerDigits"), GetMinimumIntegerDigits()); diff --git a/ecmascript/ecma_macros.h b/ecmascript/ecma_macros.h index ef3c7ec1ee1718ca8fde4b7c4d57880fa0e303f6..04b7e58bfcace2e83ba3d360bb13ef4aa80ad55f 100644 --- a/ecmascript/ecma_macros.h +++ b/ecmascript/ecma_macros.h @@ -392,6 +392,9 @@ #define THROW_TYPE_ERROR(thread, message) \ THROW_ERROR(thread, ErrorType::TYPE_ERROR, message) +#define THROW_RANGE_ERROR(thread, message) \ + THROW_ERROR(thread, ErrorType::RANGE_ERROR, message) + // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_OOM_ERROR(thread, message) \ THROW_UNCATCHABLE_ERROR(thread, ErrorType::OOM_ERROR, message) diff --git a/ecmascript/js_list_format.cpp b/ecmascript/js_list_format.cpp index 80dfbf467349342622230cf65d74f5421c202fd7..6f1797c05603516596a48e6b6c8ea45ecd061fd6 100644 --- a/ecmascript/js_list_format.cpp +++ b/ecmascript/js_list_format.cpp @@ -104,6 +104,8 @@ JSHandle JSListFormat::InitializeListFormat(JSThread *thread, JSHandle optionsObject; if (options->IsUndefined()) { optionsObject = factory->CreateNullJSObject(); + } else if (!options->IsJSObject()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "options is not Object", listFormat); } else { optionsObject = JSTaggedValue::ToObject(thread, options); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread); diff --git a/ecmascript/js_locale.h b/ecmascript/js_locale.h index 35ce01e366560080a2d4d14968790d54831d9ede..7270d411ecf714d4bbc9a0047956be291cbe040b 100644 --- a/ecmascript/js_locale.h +++ b/ecmascript/js_locale.h @@ -65,12 +65,11 @@ enum class LocaleType : uint8_t { }; enum class TypeOption : uint8_t { CARDINAL = 0x01, ORDINAL, EXCEPTION }; - -enum class RoundingType : uint8_t { FRACTIONDIGITS = 0x01, SIGNIFICANTDIGITS, LESSPRECISION, MOREPRECISION, EXCEPTION }; +enum class RoundingTypeOption : uint8_t { FRACTIONDIGITS = 0x01, SIGNIFICANTDIGITS, LESSPRECISION, MOREPRECISION, EXCEPTION }; enum class NotationOption : uint8_t { STANDARD = 0x01, SCIENTIFIC, ENGINEERING, COMPACT, EXCEPTION }; -enum class RoundingPriority : uint8_t { AUTO = 0x01, MOREPRECISION, LESSPRECISION, EXCEPTION }; -enum class RoundingMode : uint8_t { CEIL = 0x01, FLOOR, EXPAND, TRUNC, HALFCEIL, HALFFLOOR, HALFEXPAND, HALFTRUNC, HALFEVEN, EXCEPTION }; -enum class TrailingZeroDisplay : uint8_t { AUTO = 0x01, STRIPIFINTEGER, EXCEPTION }; +enum class RoundingPriorityOption : uint8_t { AUTO = 0x01, MOREPRECISION, LESSPRECISION, EXCEPTION }; +enum class RoundingModeOption : uint8_t { CEIL = 0x01, FLOOR, EXPAND, TRUNC, HALFCEIL, HALFFLOOR, HALFEXPAND, HALFTRUNC, HALFEVEN, EXCEPTION }; +enum class TrailingZeroDisplayOption : uint8_t { AUTO = 0x01, STRIPIFINTEGER, EXCEPTION }; constexpr uint32_t MAX_DIGITS = 21; constexpr uint32_t MAX_FRACTION_DIGITS = 20; @@ -602,12 +601,12 @@ public: auto roundingIncrement = GetNumberOption(thread, JSHandle::Cast(options), property, 1, 5000, 1); // If roundingIncrement is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a RangeError exception. if (!IsValidRoundingIncrement(roundingIncrement)) { - RETURN_IF_ABRUPT_COMPLETION(thread); + THROW_RANGE_ERROR(thread, "is not in"); } RETURN_IF_ABRUPT_COMPLETION(thread); if (roundingIncrement != 1) { mnfdDefault = mxfdDefault; - if (intlObj->GetRoundingType() != RoundingType::FRACTIONDIGITS) { + if (intlObj->GetRoundingType() != RoundingTypeOption ::FRACTIONDIGITS) { THROW_TYPE_ERROR(thread, "is not fractionDigits"); } } @@ -615,27 +614,29 @@ public: // Let roundingMode be ? GetOption(options, "roundingMode", string, « "ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven" », "halfExpand"). property = globalConst->GetHandledRoundingModeString(); - auto roundingMode = JSLocale::GetOptionOfString( + auto roundingMode = JSLocale::GetOptionOfString( thread, JSHandle::Cast(options), property, - {RoundingMode::CEIL, RoundingMode::FLOOR, RoundingMode::EXPAND, RoundingMode::TRUNC, RoundingMode::HALFCEIL, - RoundingMode::HALFFLOOR, RoundingMode::HALFEXPAND, RoundingMode::HALFTRUNC, RoundingMode::HALFEVEN}, - {"ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven"}, RoundingMode::HALFEXPAND); + {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); intlObj->SetRoundingMode(roundingMode); // Let roundingPriority be ? GetOption(options, "roundingPriority", string, « "auto", "morePrecision", "lessPrecision" », "auto"). property = globalConst->GetHandledRoundingPriorityString(); - auto roundingPriority = JSLocale::GetOptionOfString(thread, JSHandle::Cast(options), property, {RoundingPriority::AUTO, - RoundingPriority::MOREPRECISION, RoundingPriority::LESSPRECISION}, {"auto", "morePrecision", "lessPrecision"}, RoundingPriority::AUTO); + auto roundingPriority = JSLocale::GetOptionOfString( + thread, JSHandle::Cast(options), property, + {RoundingPriorityOption::AUTO, RoundingPriorityOption::MOREPRECISION, RoundingPriorityOption::LESSPRECISION}, + {"auto", "morePrecision", "lessPrecision"}, RoundingPriorityOption::AUTO); RETURN_IF_ABRUPT_COMPLETION(thread); intlObj->SetRoundingPriority(roundingPriority); // Let trailingZeroDisplay be ? GetOption(options, "trailingZeroDisplay", string, « "auto", "stripIfInteger" », "auto"). property = globalConst->GetHandledTrailingZeroDisplayString(); - auto trailingZeroDisplay = JSLocale::GetOptionOfString( + auto trailingZeroDisplay = JSLocale::GetOptionOfString( thread, JSHandle::Cast(options), property, - {TrailingZeroDisplay::AUTO, TrailingZeroDisplay::STRIPIFINTEGER}, - {"auto", "stripIfInteger"}, TrailingZeroDisplay::AUTO); + {TrailingZeroDisplayOption::AUTO, TrailingZeroDisplayOption::STRIPIFINTEGER}, + {"auto", "stripIfInteger"}, TrailingZeroDisplayOption::AUTO); RETURN_IF_ABRUPT_COMPLETION(thread); intlObj->SetTrailingZeroDisplay(trailingZeroDisplay); @@ -659,12 +660,15 @@ public: JSHandle mxsdKey = globalConst->GetHandledMaximumSignificantDigitsString(); JSHandle mxsd = JSTaggedValue::GetProperty(thread, options, mxsdKey).GetValue(); RETURN_IF_ABRUPT_COMPLETION(thread); - - // 10. Set intlObj.[[MinimumIntegerDigits]] to mnid. - // 11. If mnsd is not undefined or mxsd is not undefined, then +//HasProperty + if (IsValidRoundingIncrement(roundingIncrement) && mxfd->IsUndefined()) { + intlObj->SetRoundingIncrement(thread, JSTaggedValue(roundingIncrement)); + } else if (roundingIncrement != 1 && mxfd != mnfd) { + THROW_RANGE_ERROR(thread, "is not equal"); + } if (!mnsd->IsUndefined() || !mxsd->IsUndefined()) { // a. Set intlObj.[[RoundingType]] to significantDigits. - intlObj->SetRoundingType(RoundingType::SIGNIFICANTDIGITS); + intlObj->SetRoundingType(RoundingTypeOption::SIGNIFICANTDIGITS); // b. Let mnsd be ? DefaultNumberOption(mnsd, 1, 21, 1). mnsd = JSHandle( thread, JSTaggedValue(JSLocale::DefaultNumberOption(thread, mnsd, 1, MAX_DIGITS, 1))); @@ -681,7 +685,7 @@ public: if (!mnfd->IsUndefined() || !mxfd->IsUndefined()) { // 12. Else if mnfd is not undefined or mxfd is not undefined, then // a. Set intlObj.[[RoundingType]] to fractionDigits. - intlObj->SetRoundingType(RoundingType::FRACTIONDIGITS); + intlObj->SetRoundingType(RoundingTypeOption::FRACTIONDIGITS); if (!mxfd->IsUndefined()) { JSTaggedValue mxfdValue = JSTaggedValue(JSLocale::DefaultNumberOption(thread, mxfd, 0, MAX_FRACTION_DIGITS, mxfdDefault)); @@ -706,11 +710,12 @@ public: } else if (notation == NotationOption::COMPACT) { // 13. Else if notation is "compact", then // a. Set intlObj.[[RoundingType]] to compactRounding. - intlObj->SetRoundingType(RoundingType::LESSPRECISION); + intlObj->SetRoundingType(RoundingTypeOption::LESSPRECISION); + // intlObj->SetRoundingType(RoundingType::COMPACTROUNDING); } else { // 14. else, // a.Set intlObj.[[RoundingType]] to fractionDigits. - intlObj->SetRoundingType(RoundingType::FRACTIONDIGITS); + intlObj->SetRoundingType(RoundingTypeOption::FRACTIONDIGITS); // b.Set intlObj.[[MinimumFractionDigits]] to mnfdDefault. intlObj->SetMinimumFractionDigits(thread, JSTaggedValue(mnfdDefault)); // c.Set intlObj.[[MaximumFractionDigits]] to mxfdDefault. diff --git a/ecmascript/js_number_format.cpp b/ecmascript/js_number_format.cpp index 494ecc269d63c373b97b4fdfcd638f4ef2115908..55339c0b9c5c3edbf8c11458168469b9d8030e4a 100644 --- a/ecmascript/js_number_format.cpp +++ b/ecmascript/js_number_format.cpp @@ -200,37 +200,37 @@ JSHandle OptionToEcmaString(JSThread *thread, SignDisplayOption s return result; } -JSHandle OptionToEcmaString(JSThread *thread, RoundingMode roundingMode) +JSHandle OptionToEcmaString(JSThread *thread, RoundingModeOption roundingMode) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); auto globalConst = thread->GlobalConstants(); switch (roundingMode) { - case RoundingMode::CEIL: + case RoundingModeOption::CEIL: result.Update(globalConst->GetHandledCeilString().GetTaggedValue()); break; - case RoundingMode::FLOOR: + case RoundingModeOption::FLOOR: result.Update(globalConst->GetHandledFloorString().GetTaggedValue()); break; - case RoundingMode::EXPAND: + case RoundingModeOption::EXPAND: result.Update(globalConst->GetHandledExpandString().GetTaggedValue()); break; - case RoundingMode::TRUNC: + case RoundingModeOption::TRUNC: result.Update(globalConst->GetHandledTruncString().GetTaggedValue()); break; - case RoundingMode::HALFCEIL: + case RoundingModeOption::HALFCEIL: result.Update(globalConst->GetHandledHalfCeilString().GetTaggedValue()); break; - case RoundingMode::HALFFLOOR: + case RoundingModeOption::HALFFLOOR: result.Update(globalConst->GetHandledHalfFloorString().GetTaggedValue()); break; - case RoundingMode::HALFEXPAND: + case RoundingModeOption::HALFEXPAND: result.Update(globalConst->GetHandledHalfExpandString().GetTaggedValue()); break; - case RoundingMode::HALFTRUNC: + case RoundingModeOption::HALFTRUNC: result.Update(globalConst->GetHandledHalfTruncString().GetTaggedValue()); break; - case RoundingMode::HALFEVEN: + case RoundingModeOption::HALFEVEN: result.Update(globalConst->GetHandledHalfEvenString().GetTaggedValue()); break; default: @@ -240,19 +240,19 @@ JSHandle OptionToEcmaString(JSThread *thread, RoundingMode roundi return result; } -JSHandle OptionToEcmaString(JSThread *thread, RoundingPriority roundingPriority) +JSHandle OptionToEcmaString(JSThread *thread, RoundingPriorityOption roundingPriority) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); auto globalConst = thread->GlobalConstants(); switch (roundingPriority) { - case RoundingPriority::AUTO: + case RoundingPriorityOption::AUTO: result.Update(globalConst->GetHandledAutoString().GetTaggedValue()); break; - case RoundingPriority::MOREPRECISION: + case RoundingPriorityOption::MOREPRECISION: result.Update(globalConst->GetHandledMorePrecisionString().GetTaggedValue()); break; - case RoundingPriority::LESSPRECISION: + case RoundingPriorityOption::LESSPRECISION: result.Update(globalConst->GetHandledLessPrecisionString().GetTaggedValue()); break; default: @@ -261,15 +261,15 @@ JSHandle OptionToEcmaString(JSThread *thread, RoundingPriority ro return result; } -JSHandle OptionToEcmaString(JSThread *thread, TrailingZeroDisplay trailingZeroDisplay) +JSHandle OptionToEcmaString(JSThread *thread, TrailingZeroDisplayOption trailingZeroDisplay) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); auto globalConst = thread->GlobalConstants(); switch (trailingZeroDisplay) { - case TrailingZeroDisplay::AUTO: + case TrailingZeroDisplayOption::AUTO: result.Update(globalConst->GetHandledAutoString().GetTaggedValue()); break; - case TrailingZeroDisplay::STRIPIFINTEGER: + case TrailingZeroDisplayOption::STRIPIFINTEGER: result.Update(globalConst->GetHandledStripIfIntegerString().GetTaggedValue()); break; default: @@ -640,31 +640,31 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleGetUnitDisplay(); + // 16. Let style be numberFormat.[[Style]]. + StyleOption style = numberFormat->GetStyle(); // Trans unitDisplay option to ICU display option - UNumberUnitWidth uNumberUnitWidth; - switch (unitDisplay) { - case UnitDisplayOption::SHORT: - uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT; - break; - case UnitDisplayOption::NARROW: - uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; - break; - case UnitDisplayOption::LONG: - // UNUM_UNIT_WIDTH_FULL_NAME Print the full name of the unit, without any abbreviations. - uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME; - break; - default: - LOG_ECMA(FATAL) << "this branch is unreachable"; - UNREACHABLE(); - } - if (unitDisplay != UnitDisplayOption::SHORT) { + if (style == StyleOption::UNIT) { + UnitDisplayOption unitDisplay = numberFormat->GetUnitDisplay(); + UNumberUnitWidth uNumberUnitWidth; + switch (unitDisplay) { + case UnitDisplayOption::SHORT: + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT; + break; + case UnitDisplayOption::NARROW: + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; + break; + case UnitDisplayOption::LONG: + // UNUM_UNIT_WIDTH_FULL_NAME Print the full name of the unit, without any abbreviations. + uNumberUnitWidth = UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME; + break; + default: + LOG_ECMA(FATAL) << "this branch is unreachable"; + UNREACHABLE(); + } icuNumberFormatter = icuNumberFormatter.unitWidth(uNumberUnitWidth); } - // 16. Let style be numberFormat.[[Style]]. - StyleOption style = numberFormat->GetStyle(); if (style == StyleOption::PERCENT) { icuNumberFormatter = icuNumberFormatter.unit(icu::MeasureUnit::getPercent()). scale(icu::number::Scale::powerOfTen(2)); // means 10^2 @@ -733,7 +733,6 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleSetUseGrouping(useGrouping); // 25. Set numberFormat.[[UseGrouping]] to useGrouping. - switch (useGrouping) { case UseGroupingOption::OFF: icuNumberFormatter = icuNumberFormatter.grouping(UNumberGroupingStrategy::UNUM_GROUPING_OFF); @@ -751,35 +750,34 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleGetRoundingMode(); + RoundingModeOption roundingMode = numberFormat->GetRoundingMode(); switch (roundingMode) { - case RoundingMode::CEIL: + case RoundingModeOption::CEIL: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_CEILING); break; - case RoundingMode::FLOOR: + case RoundingModeOption::FLOOR: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_FLOOR); break; - case RoundingMode::EXPAND: + case RoundingModeOption::EXPAND: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_UP); break; - case RoundingMode::TRUNC: + case RoundingModeOption::TRUNC: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_DOWN); break; - case RoundingMode::HALFCEIL: + case RoundingModeOption::HALFCEIL: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALF_CEILING); break; - case RoundingMode::HALFFLOOR: + case RoundingModeOption::HALFFLOOR: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALF_FLOOR); break; - case RoundingMode::HALFEXPAND: + case RoundingModeOption::HALFEXPAND: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALFUP); break; - case RoundingMode::HALFTRUNC: + case RoundingModeOption::HALFTRUNC: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALFDOWN); break; - case RoundingMode::HALFEVEN: + case RoundingModeOption::HALFEVEN: icuNumberFormatter = icuNumberFormatter.roundingMode(UNumberFormatRoundingMode::UNUM_ROUND_HALFEVEN); break; default: @@ -997,13 +995,13 @@ void GroupToParts(JSThread *thread, const icu::number::FormattedNumber &formatte start = start + groupLeapLength; lastFieldGroup = false; } - // Special case in ICU when style is unit and unit is percentU + // Special case in ICU when style is unit and unit is percent if (styleOption == StyleOption::UNIT && static_cast(fieldId) == UNUM_PERCENT_FIELD) { typeString.Update(globalConst->GetUnitString()); } else { typeString.Update(JSLocale::GetNumberFieldType(thread, x, fieldId).GetTaggedValue()); } - JSHandle substring = intl::LocaleHelper::UStringToString(thread, formattedText, previousLimit, limit); + JSHandle substring = intl::LocaleHelper::UStringToString(thread, formattedText, start, limit); JSLocale::PutElement(thread, index, receiver, typeString, JSHandle::Cast(substring)); RETURN_IF_ABRUPT_COMPLETION(thread); index++; @@ -1190,8 +1188,8 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetRoundingType(); - if (roundingType == RoundingType::SIGNIFICANTDIGITS) { + RoundingTypeOption roundingType = numberFormat->GetRoundingType(); + if (roundingType == RoundingTypeOption::SIGNIFICANTDIGITS) { // [[MinimumSignificantDigits]] property = globalConst->GetHandledMinimumSignificantDigitsString(); JSHandle minimumSignificantDigits(thread, numberFormat->GetMinimumSignificantDigits()); @@ -1215,7 +1213,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledMinimumSignificantDigitsString(); JSHandle minimumSignificantDigits(thread, numberFormat->GetMinimumSignificantDigits()); @@ -1273,20 +1271,20 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledRoundingModeString(); - RoundingMode roundingMode= numberFormat->GetRoundingMode(); + RoundingModeOption roundingMode= numberFormat->GetRoundingMode(); JSHandle roundingModeString = OptionToEcmaString(thread, roundingMode); JSObject::CreateDataPropertyOrThrow(thread, options, property, roundingModeString); RETURN_IF_ABRUPT_COMPLETION(thread); // [[roundingPriority]] property = globalConst->GetHandledRoundingPriorityString(); - RoundingPriority roundingPriority = numberFormat->GetRoundingPriority(); + RoundingPriorityOption roundingPriority = numberFormat->GetRoundingPriority(); JSHandle roundingPriorityString = OptionToEcmaString(thread, roundingPriority); JSObject::CreateDataPropertyOrThrow(thread, options, property, roundingPriorityString); RETURN_IF_ABRUPT_COMPLETION(thread); // [[MinimumFractionDigits]] - if(roundingPriority == RoundingPriority::MOREPRECISION) { + if(roundingPriority == RoundingPriorityOption::MOREPRECISION) { property = globalConst->GetHandledMinimumFractionDigitsString(); JSHandle minimumFractionDigits(thread, numberFormat->GetMinimumFractionDigits()); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumFractionDigits); @@ -1300,7 +1298,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledTrailingZeroDisplayString(); - TrailingZeroDisplay trailingZeroDisplay = numberFormat->GetTrailingZeroDisplay(); + TrailingZeroDisplayOption trailingZeroDisplay = numberFormat->GetTrailingZeroDisplay(); JSHandle trailingZeroDisplayString = OptionToEcmaString(thread, trailingZeroDisplay); JSObject::CreateDataPropertyOrThrow(thread, options, property, trailingZeroDisplayString); RETURN_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/js_number_format.h b/ecmascript/js_number_format.h index c19dd1b592e108ec17f13827a219c3930d60fb8b..bfba2ab1e04c0bd6bcf69751dd10aee554df9934 100644 --- a/ecmascript/js_number_format.h +++ b/ecmascript/js_number_format.h @@ -91,12 +91,12 @@ public: NEXT_BIT_FIELD(BitField, UnitDisplay, UnitDisplayOption, UNIT_DISPLAY_BITS, CurrencyDisplay) 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, RoundingMode, ROUNDING_MODE_BITS, SignDisplay) - NEXT_BIT_FIELD(BitField, TrailingZeroDisplay, TrailingZeroDisplay, TRAILING_ZERO_DISPLAY_BITS, RoundingMode) + 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, RoundingPriority, RoundingPriority, ROUNDING_PRIORITY_BITS, Notation) - NEXT_BIT_FIELD(BitField, RoundingType, RoundingType, ROUNDING_TYPE_BITS, RoundingPriority) + NEXT_BIT_FIELD(BitField, RoundingPriority, RoundingPriorityOption, ROUNDING_PRIORITY_BITS, Notation) + NEXT_BIT_FIELD(BitField, RoundingType, RoundingTypeOption, ROUNDING_TYPE_BITS, RoundingPriority) DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() @@ -166,9 +166,9 @@ public: int roundingIncrement = formatter->GetRoundingIncrement().GetInt(); // If roundingtype is "compact-rounding" return ICU formatter - RoundingType roundingType = formatter->GetRoundingType(); - TrailingZeroDisplay trailingZeroDisplay = formatter->GetTrailingZeroDisplay(); - if (roundingType == RoundingType::LESSPRECISION) { + RoundingTypeOption roundingType = formatter->GetRoundingType(); + TrailingZeroDisplayOption trailingZeroDisplay = formatter->GetTrailingZeroDisplay(); + if (roundingType == RoundingTypeOption::LESSPRECISION) { return icuNumberformatter; } // Else, Set ICU formatter FractionDigits and SignificantDigits @@ -187,7 +187,7 @@ public: precision = icu::number::Precision::incrementExact(roundingIncrement, -maximumFractionDigits).withMinFraction(minimumFractionDigits); } - if (trailingZeroDisplay == TrailingZeroDisplay::STRIPIFINTEGER) { + if (trailingZeroDisplay == TrailingZeroDisplayOption::STRIPIFINTEGER) { precision = precision.trailingZeroDisplay(UNUM_TRAILING_ZERO_HIDE_IF_WHOLE); } return icuNumberformatter.precision(precision); diff --git a/ecmascript/js_plural_rules.cpp b/ecmascript/js_plural_rules.cpp index 6413e238d454e52393597b06a7aebb8d3a994f78..6fc000f31cc283505814e46167d353821c79dc69 100644 --- a/ecmascript/js_plural_rules.cpp +++ b/ecmascript/js_plural_rules.cpp @@ -330,8 +330,8 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandleGetRoundingType(); - if (roundingType == RoundingType::SIGNIFICANTDIGITS) { + RoundingTypeOption roundingType = pluralRules->GetRoundingType(); + if (roundingType == RoundingTypeOption::SIGNIFICANTDIGITS) { // [[MinimumSignificantDigits]] property = globalConst->GetHandledMinimumSignificantDigitsString(); JSHandle minimumSignificantDigits(thread, pluralRules->GetMinimumSignificantDigits()); diff --git a/ecmascript/js_plural_rules.h b/ecmascript/js_plural_rules.h index 9d15525759aad24ade4d2b99cb5d3894700cc493..3dc0352986f4af92c8c81dccac45b966b187333a 100644 --- a/ecmascript/js_plural_rules.h +++ b/ecmascript/js_plural_rules.h @@ -50,12 +50,11 @@ public: static constexpr size_t ROUNDING_MODE_BITS = 4; static constexpr size_t TRAILING_ZERO_DISPLAY_BITS = 2; static constexpr size_t TYPE_BITS = 2; - FIRST_BIT_FIELD(BitField, RoundingType, RoundingType, ROUNDING_TYPE_BITS) - NEXT_BIT_FIELD(BitField, RoundingPriority, RoundingPriority, ROUNDING_PRIORITY_BITS, RoundingType) - NEXT_BIT_FIELD(BitField, RoundingMode, RoundingMode, ROUNDING_MODE_BITS, RoundingPriority) - NEXT_BIT_FIELD(BitField, TrailingZeroDisplay, TrailingZeroDisplay, TRAILING_ZERO_DISPLAY_BITS, RoundingMode) + FIRST_BIT_FIELD(BitField, RoundingType, RoundingTypeOption, ROUNDING_TYPE_BITS) + NEXT_BIT_FIELD(BitField, RoundingPriority, RoundingPriorityOption, ROUNDING_PRIORITY_BITS, RoundingType) + NEXT_BIT_FIELD(BitField, RoundingMode, RoundingModeOption, ROUNDING_MODE_BITS, RoundingPriority) + NEXT_BIT_FIELD(BitField, TrailingZeroDisplay, TrailingZeroDisplayOption, TRAILING_ZERO_DISPLAY_BITS, RoundingMode) NEXT_BIT_FIELD(BitField, Type, TypeOption, TYPE_BITS, TrailingZeroDisplay) - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() diff --git a/ecmascript/js_segmenter.cpp b/ecmascript/js_segmenter.cpp index 5b359f8189782679dfddec525e34d0c88463bba2..45cac23fb74ef0d30bce355aad80efacd9d42a23 100644 --- a/ecmascript/js_segmenter.cpp +++ b/ecmascript/js_segmenter.cpp @@ -102,6 +102,8 @@ JSHandle JSSegmenter::InitializeSegmenter(JSThread *thread, JSHandle optionsObject; if (options->IsUndefined()) { optionsObject = factory->CreateNullJSObject(); + } else if (!options->IsJSObject()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "options is not Object", segmenter); } else { optionsObject = JSTaggedValue::ToObject(thread, options); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread); diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 92e1ea50381acdbfe014f62945c26c252c581942..a62bc74d690d695cd73fc7baf5f1a7239cbfcc75 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -1075,10 +1075,10 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa JSNumberFormat::Cast(*obj)->SetSignDisplay(SignDisplayOption::EXCEPTION); JSNumberFormat::Cast(*obj)->SetCompactDisplay(CompactDisplayOption::EXCEPTION); JSNumberFormat::Cast(*obj)->SetNotation(NotationOption::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetRoundingMode(RoundingMode::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetRoundingPriority(RoundingPriority::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetRoundingType(RoundingType::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetTrailingZeroDisplay(TrailingZeroDisplay::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetRoundingIncrement(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetRoundingType(RoundingTypeOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetTrailingZeroDisplay(TrailingZeroDisplayOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetRoundingPriority(RoundingPriorityOption::EXCEPTION); break; } case JSType::JS_RELATIVE_TIME_FORMAT: { @@ -1111,10 +1111,10 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa JSPluralRules::Cast(*obj)->SetRoundingIncrement(thread_, JSTaggedValue::Undefined()); JSPluralRules::Cast(*obj)->SetIcuPR(thread_, JSTaggedValue::Undefined()); JSPluralRules::Cast(*obj)->SetIcuNF(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetRoundingMode(RoundingMode::EXCEPTION); - JSPluralRules::Cast(*obj)->SetRoundingPriority(RoundingPriority::EXCEPTION); - JSPluralRules::Cast(*obj)->SetTrailingZeroDisplay(TrailingZeroDisplay::EXCEPTION); - JSPluralRules::Cast(*obj)->SetRoundingType(RoundingType::EXCEPTION); + JSPluralRules::Cast(*obj)->SetRoundingPriority(RoundingPriorityOption::EXCEPTION); + JSPluralRules::Cast(*obj)->SetRoundingMode(RoundingModeOption::EXCEPTION); + JSPluralRules::Cast(*obj)->SetTrailingZeroDisplay(TrailingZeroDisplayOption::EXCEPTION); + JSPluralRules::Cast(*obj)->SetRoundingType(RoundingTypeOption::EXCEPTION); JSPluralRules::Cast(*obj)->SetType(TypeOption::EXCEPTION); break; }