Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ endif()

if (HERMES_ENABLE_INTL)
add_definitions(-DHERMES_ENABLE_INTL)
if (NOT (HERMES_IS_ANDROID OR APPLE))
add_definitions(-DHERMES_INTL_FORMAT_RANGE)
endif()
endif()

if (HERMES_ENABLE_UNICODE_REGEXP_PROPERTY_ESCAPES)
Expand Down
11 changes: 11 additions & 0 deletions include/hermes/Platform/Intl/PlatformIntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ class DateTimeFormat : public vm::DecoratedObject::Decoration {

std::u16string format(double jsTimeValue) noexcept;
std::vector<Part> formatToParts(double jsTimeValue) noexcept;
#ifdef HERMES_INTL_FORMAT_RANGE
vm::CallResult<std::u16string> formatRange(
vm::Runtime &runtime,
double startUtcMs,
double endUtcMs) noexcept;

vm::CallResult<std::vector<Part>> formatRangeToParts(
vm::Runtime &runtime,
double startUtcMs,
double endUtcMs) noexcept;
#endif
};

class NumberFormat : public vm::DecoratedObject::Decoration {
Expand Down
32 changes: 0 additions & 32 deletions include/hermes/Platform/Intl/PlatformIntlShared.h

This file was deleted.

4 changes: 4 additions & 0 deletions include/hermes/VM/NativeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ NATIVE_FUNCTION(intlDateTimeFormatFormat)
NATIVE_FUNCTION(intlDateTimeFormatSupportedLocalesOf)
NATIVE_FUNCTION(intlDateTimeFormatPrototypeFormatGetter)
NATIVE_FUNCTION(intlDateTimeFormatPrototypeFormatToParts)
#ifdef HERMES_INTL_FORMAT_RANGE
NATIVE_FUNCTION(intlDateTimeFormatPrototypeFormatRange)
NATIVE_FUNCTION(intlDateTimeFormatPrototypeFormatRangeToParts)
#endif
NATIVE_FUNCTION(intlDateTimeFormatPrototypeResolvedOptions)

NATIVE_FUNCTION(intlNumberFormatConstructor)
Expand Down
4 changes: 4 additions & 0 deletions include/hermes/VM/PredefinedStrings.def
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ STR(Intl, "Intl")
STR(compare, "compare")
STR(format, "format")
STR(formatToParts, "formatToParts")
#ifdef HERMES_INTL_FORMAT_RANGE
STR(formatRange, "formatRange")
STR(formatRangeToParts, "formatRangeToParts")
#endif
STR(getCanonicalLocales, "getCanonicalLocales")
STR(resolvedOptions, "resolvedOptions")
STR(supportedLocalesOf, "supportedLocalesOf")
Expand Down
3 changes: 2 additions & 1 deletion lib/Platform/Intl/BCP47Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ bool isUnicodeRegionSubtag(const std::u16string &subtag) {
bool isUnicodeVariantSubtag(const std::u16string &subtag) {
// = (alphanum{5,8} | digit alphanum{3});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the code comment accordingly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing code comment is correct. The previous code incorrectly missed the "digit" part in the "digit alphanum{3}" check.

return isCharType(subtag, 5, 8, &isASCIILetterOrDigit) ||
isCharType(subtag, 3, 3, &isASCIILetterOrDigit);
(subtag.size() == 4 && isASCIIDigit(subtag.front()) &&
isCharType(subtag.substr(1), 3, 3, &isASCIILetterOrDigit));
}
bool isUnicodeExtensionAttribute(const std::u16string &subtag) {
// = alphanum{3,8};
Expand Down
3 changes: 2 additions & 1 deletion lib/Platform/Intl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ if(HERMES_ENABLE_INTL)
else()
add_hermes_library(hermesPlatformIntl STATIC
PlatformIntlICU.cpp
PlatformIntlShared.cpp
impl_icu/Collator.cpp
impl_icu/DateTimeFormat.cpp
impl_icu/IntlUtils.cpp
impl_icu/LocaleConverter.cpp
impl_icu/LocaleBCP47Object.cpp
impl_icu/LocaleResolver.cpp
impl_icu/OptionHelpers.cpp
impl_icu/NumberingSystem.cpp
LINK_LIBS
hermesBCP47Parser
hermesPublic
Expand Down
10 changes: 10 additions & 0 deletions lib/Platform/Intl/PlatformIntlApple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,16 @@ uint8_t getCurrencyDigits(std::u16string_view code) {
// 30. Let dataLocaleData be localeData.[[<dataLocale>]].
// 31. Let matcher be ? GetOption(options, "formatMatcher", "string", «
// "basic", "best fit" », "best fit").
// NOTE: Only best fit format matcher is implemented through use of NSDateFormatter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unclear to me. "basic" format matcher isn't implemented? Or it's implemented without Platform API? If it's not implemented, where do we early return?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "basic" format matcher algorithm defined in the spec is not implemented. The Apple implementation uses the Apple Platform API to implement the "best fit" format matcher. And the "best fit" format matcher is used even when "basic" is specified.

"best fit" is defined in the spec to be a platform implementation that produces results at least as good as "basic", so it is fine to just always use the "best fit" format matcher.

// The formatMatcher option is read and checked for valid values.
auto formatMatcherRes = getOptionString(
runtime,
options,
u"formatMatcher",
{u"basic", u"best fit"},
u"best fit");
if (LLVM_UNLIKELY(formatMatcherRes == vm::ExecutionStatus::EXCEPTION))
return vm::ExecutionStatus::EXCEPTION;
// 32. Let dateStyle be ? GetOption(options, "dateStyle", "string", « "full",
// "long", "medium", "short" », undefined).
static constexpr std::u16string_view dateStyles[] = {
Expand Down
Loading