Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (263496 => 263497)
--- trunk/Source/_javascript_Core/ChangeLog 2020-06-25 03:28:41 UTC (rev 263496)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-06-25 03:58:07 UTC (rev 263497)
@@ -1,3 +1,21 @@
+2020-06-24 Ross Kirsling <[email protected]>
+
+ [Intl] Disprefer using ICU enums directly as instance variables
+ https://bugs.webkit.org/show_bug.cgi?id=213587
+
+ Reviewed by Yusuke Suzuki.
+
+ * runtime/IntlPluralRules.cpp:
+ (JSC::IntlPluralRules::initializePluralRules):
+ (JSC::IntlPluralRules::resolvedOptions const):
+ * runtime/IntlPluralRules.h:
+ * runtime/IntlRelativeTimeFormat.cpp:
+ (JSC::IntlRelativeTimeFormat::initializeRelativeTimeFormat):
+ (JSC::IntlRelativeTimeFormat::styleString): Renamed from JSC::styleString.
+ (JSC::IntlRelativeTimeFormat::resolvedOptions const):
+ (JSC::numericString): Deleted.
+ * runtime/IntlRelativeTimeFormat.h:
+
2020-06-24 Caitlin Potter <[email protected]>
[JSC] handle Put/DefinePrivateField in resetPutByID
Modified: trunk/Source/_javascript_Core/runtime/IntlPluralRules.cpp (263496 => 263497)
--- trunk/Source/_javascript_Core/runtime/IntlPluralRules.cpp 2020-06-25 03:28:41 UTC (rev 263496)
+++ trunk/Source/_javascript_Core/runtime/IntlPluralRules.cpp 2020-06-25 03:58:07 UTC (rev 263497)
@@ -123,7 +123,7 @@
String typeString = intlStringOption(globalObject, options, vm.propertyNames->type, { "cardinal", "ordinal" }, "type must be \"cardinal\" or \"ordinal\"", "cardinal");
RETURN_IF_EXCEPTION(scope, void());
- m_type = typeString == "ordinal" ? UPLURAL_TYPE_ORDINAL : UPLURAL_TYPE_CARDINAL;
+ m_type = typeString == "ordinal" ? Type::Ordinal : Type::Cardinal;
unsigned minimumIntegerDigits = intlNumberOption(globalObject, options, Identifier::fromString(vm, "minimumIntegerDigits"), 1, 21, 1);
RETURN_IF_EXCEPTION(scope, void());
@@ -172,7 +172,7 @@
}
status = U_ZERO_ERROR;
- m_pluralRules = std::unique_ptr<UPluralRules, UPluralRulesDeleter>(uplrules_openForType(m_locale.utf8().data(), m_type, &status));
+ m_pluralRules = std::unique_ptr<UPluralRules, UPluralRulesDeleter>(uplrules_openForType(m_locale.utf8().data(), m_type == Type::Ordinal ? UPLURAL_TYPE_ORDINAL : UPLURAL_TYPE_CARDINAL, &status));
if (U_FAILURE(status)) {
throwTypeError(globalObject, scope, "failed to initialize PluralRules"_s);
return;
@@ -189,7 +189,7 @@
JSObject* options = constructEmptyObject(globalObject);
options->putDirect(vm, vm.propertyNames->locale, jsNontrivialString(vm, m_locale));
- options->putDirect(vm, vm.propertyNames->type, jsNontrivialString(vm, m_type == UPLURAL_TYPE_ORDINAL ? "ordinal"_s : "cardinal"_s));
+ options->putDirect(vm, vm.propertyNames->type, jsNontrivialString(vm, m_type == Type::Ordinal ? "ordinal"_s : "cardinal"_s));
options->putDirect(vm, Identifier::fromString(vm, "minimumIntegerDigits"), jsNumber(m_minimumIntegerDigits));
options->putDirect(vm, Identifier::fromString(vm, "minimumFractionDigits"), jsNumber(m_minimumFractionDigits));
options->putDirect(vm, Identifier::fromString(vm, "maximumFractionDigits"), jsNumber(m_maximumFractionDigits));
Modified: trunk/Source/_javascript_Core/runtime/IntlPluralRules.h (263496 => 263497)
--- trunk/Source/_javascript_Core/runtime/IntlPluralRules.h 2020-06-25 03:28:41 UTC (rev 263496)
+++ trunk/Source/_javascript_Core/runtime/IntlPluralRules.h 2020-06-25 03:58:07 UTC (rev 263497)
@@ -64,6 +64,8 @@
static Vector<String> localeData(const String&, size_t);
+ enum class Type : bool { Cardinal, Ordinal };
+
struct UPluralRulesDeleter {
void operator()(UPluralRules*) const;
};
@@ -75,12 +77,12 @@
std::unique_ptr<UNumberFormat, UNumberFormatDeleter> m_numberFormat;
String m_locale;
- UPluralType m_type { UPLURAL_TYPE_CARDINAL };
unsigned m_minimumIntegerDigits { 1 };
unsigned m_minimumFractionDigits { 0 };
unsigned m_maximumFractionDigits { 3 };
Optional<unsigned> m_minimumSignificantDigits;
Optional<unsigned> m_maximumSignificantDigits;
+ Type m_type { Type::Cardinal };
};
} // namespace JSC
Modified: trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.cpp (263496 => 263497)
--- trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.cpp 2020-06-25 03:28:41 UTC (rev 263496)
+++ trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.cpp 2020-06-25 03:58:07 UTC (rev 263497)
@@ -135,14 +135,18 @@
String style = intlStringOption(globalObject, options, vm.propertyNames->style, { "long", "short", "narrow" }, "style must be either \"long\", \"short\", or \"narrow\"", "long");
RETURN_IF_EXCEPTION(scope, void());
- if (style == "long")
- m_style = UDAT_STYLE_LONG;
- else if (style == "short")
- m_style = UDAT_STYLE_SHORT;
- else if (style == "narrow")
- m_style = UDAT_STYLE_NARROW;
- else
- ASSERT_NOT_REACHED();
+ UDateRelativeDateTimeFormatterStyle icuStyle;
+ if (style == "long") {
+ icuStyle = UDAT_STYLE_LONG;
+ m_style = Style::Long;
+ } else if (style == "short") {
+ icuStyle = UDAT_STYLE_SHORT;
+ m_style = Style::Short;
+ } else {
+ ASSERT(style == "narrow");
+ icuStyle = UDAT_STYLE_NARROW;
+ m_style = Style::Narrow;
+ }
String numeric = intlStringOption(globalObject, options, vm.propertyNames->numeric, { "always", "auto" }, "numeric must be either \"always\" or \"auto\"", "always");
RETURN_IF_EXCEPTION(scope, void());
@@ -155,7 +159,7 @@
return;
}
- m_relativeDateTimeFormatter = std::unique_ptr<URelativeDateTimeFormatter, URelativeDateTimeFormatterDeleter>(ureldatefmt_open(dataLocaleWithExtensions.data(), nullptr, m_style, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status));
+ m_relativeDateTimeFormatter = std::unique_ptr<URelativeDateTimeFormatter, URelativeDateTimeFormatterDeleter>(ureldatefmt_open(dataLocaleWithExtensions.data(), nullptr, icuStyle, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status));
if (UNLIKELY(U_FAILURE(status))) {
throwTypeError(globalObject, scope, "failed to initialize RelativeTimeFormat"_s);
return;
@@ -162,14 +166,14 @@
}
}
-static ASCIILiteral styleString(UDateRelativeDateTimeFormatterStyle style)
+ASCIILiteral IntlRelativeTimeFormat::styleString(Style style)
{
switch (style) {
- case UDAT_STYLE_LONG:
+ case Style::Long:
return "long"_s;
- case UDAT_STYLE_SHORT:
+ case Style::Short:
return "short"_s;
- case UDAT_STYLE_NARROW:
+ case Style::Narrow:
return "narrow"_s;
}
ASSERT_NOT_REACHED();
@@ -176,11 +180,6 @@
return ASCIILiteral::null();
}
-static ASCIILiteral numericString(bool numeric)
-{
- return numeric ? "always"_s : "auto"_s;
-}
-
// https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
JSObject* IntlRelativeTimeFormat::resolvedOptions(JSGlobalObject* globalObject) const
{
@@ -188,7 +187,7 @@
JSObject* options = constructEmptyObject(globalObject);
options->putDirect(vm, vm.propertyNames->locale, jsNontrivialString(vm, m_locale));
options->putDirect(vm, vm.propertyNames->style, jsNontrivialString(vm, styleString(m_style)));
- options->putDirect(vm, vm.propertyNames->numeric, jsNontrivialString(vm, numericString(m_numeric)));
+ options->putDirect(vm, vm.propertyNames->numeric, jsNontrivialString(vm, m_numeric ? "always"_s : "auto"_s));
options->putDirect(vm, vm.propertyNames->numberingSystem, jsNontrivialString(vm, m_numberingSystem));
return options;
}
Modified: trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.h (263496 => 263497)
--- trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.h 2020-06-25 03:28:41 UTC (rev 263496)
+++ trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.h 2020-06-25 03:58:07 UTC (rev 263497)
@@ -66,6 +66,8 @@
String formatInternal(JSGlobalObject*, double, StringView unit) const;
+ enum class Style : uint8_t { Long, Short, Narrow };
+
struct URelativeDateTimeFormatterDeleter {
void operator()(URelativeDateTimeFormatter*) const;
};
@@ -73,12 +75,14 @@
void operator()(UNumberFormat*) const;
};
+ static ASCIILiteral styleString(Style);
+
std::unique_ptr<URelativeDateTimeFormatter, URelativeDateTimeFormatterDeleter> m_relativeDateTimeFormatter;
std::unique_ptr<UNumberFormat, UNumberFormatDeleter> m_numberFormat;
String m_locale;
String m_numberingSystem;
- UDateRelativeDateTimeFormatterStyle m_style { UDAT_STYLE_LONG };
+ Style m_style { Style::Long };
bool m_numeric { true };
};