Skip to content

Commit

Permalink
[JSC] Rebaseline Intl implementation based on lowest dependency ICU 70
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=280762
rdar://137128937

Reviewed by Yijia Huang.

Now, Apple and
https://docs.webkit.org/Ports/WebKitGTK%20and%20WPE%20WebKit/DependenciesPolicy.html
dependency has ICU 70. This significantly cleans up Intl implementation
and make them maintainable and extendable easily. This patch removes
ifdefs based on ICU 70 requirement.

* Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp:
(JSC::IntlDateTimeFormat::formatRange):
(JSC::IntlDateTimeFormat::formatRangeToParts):
* Source/JavaScriptCore/runtime/IntlDateTimeFormat.h:
* Source/JavaScriptCore/runtime/IntlDateTimeFormatPrototype.cpp:
(JSC::IntlDateTimeFormatPrototype::finishCreation):
* Source/JavaScriptCore/runtime/IntlDurationFormat.cpp:
(JSC::IntlDurationFormat::initializeDurationFormat):
(JSC::IntlDurationFormat::format const):
(JSC::IntlDurationFormat::formatToParts const):
* Source/JavaScriptCore/runtime/IntlDurationFormat.h:
* Source/JavaScriptCore/runtime/IntlListFormat.cpp:
(JSC::IntlListFormat::initializeListFormat):
(JSC::stringListFromIterable):
(JSC::IntlListFormat::format const):
(JSC::IntlListFormat::formatToParts const):
* Source/JavaScriptCore/runtime/IntlListFormat.h:
* Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:
(JSC::UNumberFormatterDeleter::operator()):
(JSC::UNumberRangeFormatterDeleter::operator()):
(JSC::partTypeString):
(JSC::IntlNumberFormat::initializeNumberFormat):
(JSC::IntlNumberFormat::format const):
(JSC::IntlNumberFormat::formatRange const):
(JSC::IntlNumberFormat::formatRangeToParts const):
(JSC::IntlNumberFormat::formatToParts const):
* Source/JavaScriptCore/runtime/IntlNumberFormat.h:
* Source/JavaScriptCore/runtime/IntlNumberFormatPrototype.cpp:
(JSC::IntlNumberFormatPrototype::finishCreation):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/IntlObject.cpp:
(JSC::IntlObject::finishCreation):
* Source/JavaScriptCore/runtime/IntlPluralRules.cpp:
(JSC::IntlPluralRules::initializePluralRules):
(JSC::IntlPluralRules::select const):
(JSC::IntlPluralRules::selectRange const):
* Source/JavaScriptCore/runtime/IntlPluralRules.h:
* Source/JavaScriptCore/runtime/IntlPluralRulesPrototype.cpp:
(JSC::IntlPluralRulesPrototype::finishCreation):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/IntlWorkaround.cpp:
(JSC::cloneUBreakIterator):
* Source/JavaScriptCore/runtime/JSDateMath.cpp:
(JSC::OpaqueICUTimeZoneDeleter::operator()):
(JSC::DateCache::calculateLocalTimeOffset):
(JSC::DateCache::defaultTimeZone):
(JSC::DateCache::timeZoneDisplayName):
(JSC::DateCache::timeZoneCacheSlow):
(JSC::toICUTimeZone): Deleted.
(JSC::toOpaqueICUTimeZone): Deleted.

Canonical link: https://commits.webkit.org/284568@main
  • Loading branch information
Constellation authored and mnutt committed Nov 20, 2024
1 parent 6bfa257 commit 0ea263d
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 478 deletions.
27 changes: 0 additions & 27 deletions Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@
#include <wtf/unicode/CharacterNames.h>
#include <wtf/unicode/icu/ICUHelpers.h>

#if HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)
#include <unicode/uformattedvalue.h>
#ifdef U_HIDE_DRAFT_API
#undef U_HIDE_DRAFT_API
#endif
#endif // HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)
#include <unicode/udateintervalformat.h>
#if HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)
#define U_HIDE_DRAFT_API 1
#endif // HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)

namespace JSC {

Expand Down Expand Up @@ -1445,8 +1441,6 @@ UDateIntervalFormat* IntlDateTimeFormat::createDateIntervalFormatIfNecessary(JSG
return m_dateIntervalFormat.get();
}

#if HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)

static std::unique_ptr<UFormattedDateInterval, ICUDeleter<udtitvfmt_closeResult>> formattedValueFromDateRange(UDateIntervalFormat& dateIntervalFormat, UDateFormat& dateFormat, double startDate, double endDate, UErrorCode& status)
{
auto result = std::unique_ptr<UFormattedDateInterval, ICUDeleter<udtitvfmt_closeResult>>(udtitvfmt_openResult(&status));
Expand Down Expand Up @@ -1525,8 +1519,6 @@ static bool dateFieldsPracticallyEqual(const UFormattedValue* formattedValue, UE
return !hasSpan;
}

#endif // HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)

JSValue IntlDateTimeFormat::formatRange(JSGlobalObject* globalObject, double startDate, double endDate)
{
ASSERT(m_dateFormat);
Expand All @@ -1545,7 +1537,6 @@ JSValue IntlDateTimeFormat::formatRange(JSGlobalObject* globalObject, double sta
auto* dateIntervalFormat = createDateIntervalFormatIfNecessary(globalObject);
RETURN_IF_EXCEPTION(scope, { });

#if HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)
UErrorCode status = U_ZERO_ERROR;
auto result = formattedValueFromDateRange(*dateIntervalFormat, *m_dateFormat, startDate, endDate, status);
if (U_FAILURE(status)) {
Expand Down Expand Up @@ -1583,17 +1574,6 @@ JSValue IntlDateTimeFormat::formatRange(JSGlobalObject* globalObject, double sta
replaceNarrowNoBreakSpaceOrThinSpaceWithNormalSpace(buffer);

return jsString(vm, String(WTFMove(buffer)));
#else
Vector<UChar, 32> buffer;
auto status = callBufferProducingFunction(udtitvfmt_format, dateIntervalFormat, startDate, endDate, buffer, nullptr);
if (U_FAILURE(status)) {
throwTypeError(globalObject, scope, "Failed to format date interval"_s);
return { };
}
replaceNarrowNoBreakSpaceOrThinSpaceWithNormalSpace(buffer);

return jsString(vm, String(WTFMove(buffer)));
#endif
}

JSValue IntlDateTimeFormat::formatRangeToParts(JSGlobalObject* globalObject, double startDate, double endDate)
Expand All @@ -1603,7 +1583,6 @@ JSValue IntlDateTimeFormat::formatRangeToParts(JSGlobalObject* globalObject, dou
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

#if HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)
// http://tc39.es/proposal-intl-DateTimeFormat-formatRange/#sec-partitiondatetimerangepattern
startDate = timeClip(startDate);
endDate = timeClip(endDate);
Expand Down Expand Up @@ -1807,12 +1786,6 @@ JSValue IntlDateTimeFormat::formatRangeToParts(JSGlobalObject* globalObject, dou
}

return parts;
#else
UNUSED_PARAM(startDate);
UNUSED_PARAM(endDate);
throwTypeError(globalObject, scope, "Failed to format date interval"_s);
return { };
#endif
}


Expand Down
6 changes: 0 additions & 6 deletions Source/JavaScriptCore/runtime/IntlDateTimeFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@

struct UDateIntervalFormat;

#if !defined(HAVE_ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)
#if U_ICU_VERSION_MAJOR_NUM >= 64
#define HAVE_ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS 1
#endif
#endif

namespace JSC {

enum class RelevantExtensionKey : uint8_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const ClassInfo IntlDateTimeFormatPrototype::s_info = { "Intl.DateTimeFormat"_s,
@begin dateTimeFormatPrototypeTable
format intlDateTimeFormatPrototypeGetterFormat DontEnum|ReadOnly|CustomAccessor
formatRange intlDateTimeFormatPrototypeFuncFormatRange DontEnum|Function 2
formatRangeToParts intlDateTimeFormatPrototypeFuncFormatRangeToParts DontEnum|Function 2
formatToParts intlDateTimeFormatPrototypeFuncFormatToParts DontEnum|Function 1
resolvedOptions intlDateTimeFormatPrototypeFuncResolvedOptions DontEnum|Function 0
@end
Expand All @@ -82,12 +83,7 @@ void IntlDateTimeFormatPrototype::finishCreation(VM& vm, JSGlobalObject* globalO
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
#if HAVE(ICU_U_DATE_INTERVAL_FORMAT_FORMAT_RANGE_TO_PARTS)
JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("formatRangeToParts"_s, intlDateTimeFormatPrototypeFuncFormatRangeToParts, static_cast<unsigned>(PropertyAttribute::DontEnum), 2, ImplementationVisibility::Public);
#else
UNUSED_PARAM(globalObject);
UNUSED_PARAM(&intlDateTimeFormatPrototypeFuncFormatRangeToParts);
#endif
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}

Expand Down
27 changes: 0 additions & 27 deletions Source/JavaScriptCore/runtime/IntlDurationFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,14 @@
// While UListFormatter APIs are draft in ICU 67, they are stable in ICU 68 with the same function signatures.
// So we can assume that these signatures of draft APIs are stable.
// If UListFormatter is available, UNumberFormatter is also available.
#if HAVE(ICU_U_LIST_FORMATTER)
#ifdef U_HIDE_DRAFT_API
#undef U_HIDE_DRAFT_API
#endif
#endif
#include <unicode/ulistformatter.h>
#include <unicode/unumberformatter.h>
#include <unicode/ures.h>
#if HAVE(ICU_U_LIST_FORMATTER)
#define U_HIDE_DRAFT_API 1
#endif

#if HAVE(ICU_U_LIST_FORMATTER)
#include <unicode/uformattedvalue.h>
#endif

namespace JSC {
namespace IntlDurationFormatInternal {
Expand Down Expand Up @@ -245,7 +238,6 @@ void IntlDurationFormat::initializeDurationFormat(JSGlobalObject* globalObject,
m_fractionalDigits = intlNumberOption(globalObject, options, vm.propertyNames->fractionalDigits, 0, 9, fractionalDigitsUndefinedValue);
RETURN_IF_EXCEPTION(scope, void());

#if HAVE(ICU_U_LIST_FORMATTER)
{
auto toUListFormatterWidth = [](Style style) {
// 6. Let listStyle be durationFormat.[[Style]].
Expand All @@ -272,15 +264,8 @@ void IntlDurationFormat::initializeDurationFormat(JSGlobalObject* globalObject,
return;
}
}
#else
UNUSED_PARAM(IntlDurationFormatInternal::verbose);
throwTypeError(globalObject, scope, "Failed to initialize Intl.DurationFormat since this feature is not supported in the linked ICU version"_s);
return;
#endif
}

#if HAVE(ICU_U_LIST_FORMATTER)

static String retrieveSeparator(const CString& locale, const String& numberingSystem)
{
ASCIILiteral fallbackTimeSeparator = ":"_s;
Expand Down Expand Up @@ -540,15 +525,12 @@ static Vector<Element> collectElements(JSGlobalObject* globalObject, const IntlD
return elements;
}

#endif

// https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.format
JSValue IntlDurationFormat::format(JSGlobalObject* globalObject, ISO8601::Duration duration) const
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

#if HAVE(ICU_U_LIST_FORMATTER)
auto elements = collectElements(globalObject, this, WTFMove(duration));
RETURN_IF_EXCEPTION(scope, { });

Expand Down Expand Up @@ -584,10 +566,6 @@ JSValue IntlDurationFormat::format(JSGlobalObject* globalObject, ISO8601::Durati
return throwTypeError(globalObject, scope, "failed to format list of strings"_s);

return jsString(vm, String(WTFMove(result)));
#else
UNUSED_PARAM(duration);
return throwTypeError(globalObject, scope, "failed to format list of strings"_s);
#endif
}

// https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts
Expand All @@ -596,7 +574,6 @@ JSValue IntlDurationFormat::formatToParts(JSGlobalObject* globalObject, ISO8601:
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

#if HAVE(ICU_U_LIST_FORMATTER)
auto elements = collectElements(globalObject, this, WTFMove(duration));
RETURN_IF_EXCEPTION(scope, { });

Expand Down Expand Up @@ -749,10 +726,6 @@ JSValue IntlDurationFormat::formatToParts(JSGlobalObject* globalObject, ISO8601:
}

return parts;
#else
UNUSED_PARAM(duration);
return throwTypeError(globalObject, scope, "failed to format list of strings"_s);
#endif
}

// https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.resolvedOptions
Expand Down
2 changes: 0 additions & 2 deletions Source/JavaScriptCore/runtime/IntlDurationFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ class IntlDurationFormat final : public JSNonFinalObject {
static ASCIILiteral unitStyleString(UnitStyle);
static ASCIILiteral displayString(Display);

#if HAVE(ICU_U_LIST_FORMATTER)
std::unique_ptr<UListFormatter, UListFormatterDeleter> m_listFormat;
#endif
String m_locale;
String m_numberingSystem;
CString m_dataLocaleWithExtensions;
Expand Down
24 changes: 0 additions & 24 deletions Source/JavaScriptCore/runtime/IntlListFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,12 @@

// While UListFormatter APIs are draft in ICU 67, they are stable in ICU 68 with the same function signatures.
// So we can assume that these signatures of draft APIs are stable.
#if HAVE(ICU_U_LIST_FORMATTER)
#ifdef U_HIDE_DRAFT_API
#undef U_HIDE_DRAFT_API
#endif
#endif
#include <unicode/ulistformatter.h>
#if HAVE(ICU_U_LIST_FORMATTER)
#define U_HIDE_DRAFT_API 1
#endif

#if HAVE(ICU_U_LIST_FORMATTER)
#include <unicode/uformattedvalue.h>
#endif

namespace JSC {

Expand Down Expand Up @@ -112,7 +105,6 @@ void IntlListFormat::initializeListFormat(JSGlobalObject* globalObject, JSValue
m_style = intlOption<Style>(globalObject, options, vm.propertyNames->style, { { "long"_s, Style::Long }, { "short"_s, Style::Short }, { "narrow"_s, Style::Narrow } }, "style must be either \"long\", \"short\", or \"narrow\""_s, Style::Long);
RETURN_IF_EXCEPTION(scope, void());

#if HAVE(ICU_U_LIST_FORMATTER)
auto toUListFormatterType = [](Type type) {
switch (type) {
case Type::Conjunction:
Expand Down Expand Up @@ -143,13 +135,8 @@ void IntlListFormat::initializeListFormat(JSGlobalObject* globalObject, JSValue
throwTypeError(globalObject, scope, "failed to initialize ListFormat"_s);
return;
}
#else
throwTypeError(globalObject, scope, "Failed to initialize Intl.ListFormat since this feature is not supported in the linked ICU version"_s);
return;
#endif
}

#if HAVE(ICU_U_LIST_FORMATTER)
static Vector<String, 4> stringListFromIterable(JSGlobalObject* globalObject, JSValue iterable)
{
Vector<String, 4> result;
Expand All @@ -169,15 +156,13 @@ static Vector<String, 4> stringListFromIterable(JSGlobalObject* globalObject, JS
});
return result;
}
#endif

// https://tc39.es/proposal-intl-list-format/#sec-Intl.ListFormat.prototype.format
JSValue IntlListFormat::format(JSGlobalObject* globalObject, JSValue list) const
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

#if HAVE(ICU_U_LIST_FORMATTER)
auto stringList = stringListFromIterable(globalObject, list);
RETURN_IF_EXCEPTION(scope, { });

Expand All @@ -189,10 +174,6 @@ JSValue IntlListFormat::format(JSGlobalObject* globalObject, JSValue list) const
return throwTypeError(globalObject, scope, "failed to format list of strings"_s);

return jsString(vm, String(WTFMove(result)));
#else
UNUSED_PARAM(list);
return throwTypeError(globalObject, scope, "failed to format list of strings"_s);
#endif
}

// https://tc39.es/proposal-intl-list-format/#sec-Intl.ListFormat.prototype.formatToParts
Expand All @@ -201,7 +182,6 @@ JSValue IntlListFormat::formatToParts(JSGlobalObject* globalObject, JSValue list
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

#if HAVE(ICU_U_LIST_FORMATTER)
auto stringList = stringListFromIterable(globalObject, list);
RETURN_IF_EXCEPTION(scope, { });

Expand Down Expand Up @@ -287,10 +267,6 @@ JSValue IntlListFormat::formatToParts(JSGlobalObject* globalObject, JSValue list
}

return parts;
#else
UNUSED_PARAM(list);
return throwTypeError(globalObject, scope, "failed to format list of strings"_s);
#endif
}

// https://tc39.es/proposal-intl-list-format/#sec-Intl.ListFormat.prototype.resolvedOptions
Expand Down
6 changes: 0 additions & 6 deletions Source/JavaScriptCore/runtime/IntlListFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
#include "JSObject.h"
#include <wtf/unicode/icu/ICUHelpers.h>

#if !defined(HAVE_ICU_U_LIST_FORMATTER)
#if U_ICU_VERSION_MAJOR_NUM >= 67 || (U_ICU_VERSION_MAJOR_NUM >= 66 && USE(APPLE_INTERNAL_SDK))
#define HAVE_ICU_U_LIST_FORMATTER 1
#endif
#endif

struct UListFormatter;

namespace JSC {
Expand Down
Loading

0 comments on commit 0ea263d

Please sign in to comment.