Title: [263250] trunk/Source/_javascript_Core
Revision
263250
Author
ysuz...@apple.com
Date
2020-06-18 18:43:02 -0700 (Thu, 18 Jun 2020)

Log Message

[JSC] Remove dead non-ICU locale Date code since we are always using ICU version
https://bugs.webkit.org/show_bug.cgi?id=213362

Reviewed by Ross Kirsling.

There are old non-ICU version of Date locale code. But this is now dead code since we are always using ICU version,
which is invoked from builtin JS DatePrototype.js. We should remove these dead code.

* runtime/DatePrototype.cpp:
(JSC::DatePrototype::finishCreation):
(): Deleted.
(JSC::styleFromArgString): Deleted.
(JSC::formatLocaleDate): Deleted.
(JSC::dateProtoFuncToLocaleString): Deleted.
(JSC::dateProtoFuncToLocaleDateString): Deleted.
(JSC::dateProtoFuncToLocaleTimeString): Deleted.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (263249 => 263250)


--- trunk/Source/_javascript_Core/ChangeLog	2020-06-19 01:04:22 UTC (rev 263249)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-06-19 01:43:02 UTC (rev 263250)
@@ -1,3 +1,22 @@
+2020-06-18  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] Remove dead non-ICU locale Date code since we are always using ICU version
+        https://bugs.webkit.org/show_bug.cgi?id=213362
+
+        Reviewed by Ross Kirsling.
+
+        There are old non-ICU version of Date locale code. But this is now dead code since we are always using ICU version,
+        which is invoked from builtin JS DatePrototype.js. We should remove these dead code.
+
+        * runtime/DatePrototype.cpp:
+        (JSC::DatePrototype::finishCreation):
+        (): Deleted.
+        (JSC::styleFromArgString): Deleted.
+        (JSC::formatLocaleDate): Deleted.
+        (JSC::dateProtoFuncToLocaleString): Deleted.
+        (JSC::dateProtoFuncToLocaleDateString): Deleted.
+        (JSC::dateProtoFuncToLocaleTimeString): Deleted.
+
 2020-06-18  Ross Kirsling  <ross.kirsl...@sony.com>
 
         Unreviewed, address Darin's feedback on r263227.

Modified: trunk/Source/_javascript_Core/runtime/DatePrototype.cpp (263249 => 263250)


--- trunk/Source/_javascript_Core/runtime/DatePrototype.cpp	2020-06-19 01:04:22 UTC (rev 263249)
+++ trunk/Source/_javascript_Core/runtime/DatePrototype.cpp	2020-06-19 01:43:02 UTC (rev 263250)
@@ -36,14 +36,6 @@
 #include "JSString.h"
 #include <wtf/Assertions.h>
 
-#if !(OS(DARWIN) && USE(CF))
-#include <unicode/udat.h>
-#endif
-
-#if USE(CF)
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
 namespace JSC {
 
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetDate(JSGlobalObject*, CallFrame*);
@@ -81,9 +73,6 @@
 EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCSeconds(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncToDateString(JSGlobalObject*, CallFrame*);
-EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleDateString(JSGlobalObject*, CallFrame*);
-EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleString(JSGlobalObject*, CallFrame*);
-EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleTimeString(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncToPrimitiveSymbol(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncToString(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncToTimeString(JSGlobalObject*, CallFrame*);
@@ -97,211 +86,6 @@
 
 namespace JSC {
 
-enum LocaleDateTimeFormat { LocaleDateAndTime, LocaleDate, LocaleTime };
- 
-#if OS(DARWIN) && USE(CF)
-
-// FIXME: Since this is superior to the strftime-based version, why limit this to OS(DARWIN)?
-// Instead we should consider using this whenever USE(CF) is true.
-
-static CFDateFormatterStyle styleFromArgString(const String& string, CFDateFormatterStyle defaultStyle)
-{
-    if (string == "short")
-        return kCFDateFormatterShortStyle;
-    if (string == "medium")
-        return kCFDateFormatterMediumStyle;
-    if (string == "long")
-        return kCFDateFormatterLongStyle;
-    if (string == "full")
-        return kCFDateFormatterFullStyle;
-    return defaultStyle;
-}
-
-static JSCell* formatLocaleDate(JSGlobalObject* globalObject, CallFrame* callFrame, DateInstance* dateObject, double timeInMilliseconds, LocaleDateTimeFormat format)
-{
-    VM& vm = globalObject->vm();
-    Integrity::auditStructureID(vm, dateObject->structureID());
-
-    CFDateFormatterStyle dateStyle = (format != LocaleTime ? kCFDateFormatterLongStyle : kCFDateFormatterNoStyle);
-    CFDateFormatterStyle timeStyle = (format != LocaleDate ? kCFDateFormatterLongStyle : kCFDateFormatterNoStyle);
-
-    bool useCustomFormat = false;
-    String customFormatString;
-
-    String arg0String = callFrame->argument(0).toWTFString(globalObject);
-    if (arg0String == "custom" && !callFrame->argument(1).isUndefined()) {
-        useCustomFormat = true;
-        customFormatString = callFrame->argument(1).toWTFString(globalObject);
-    } else if (format == LocaleDateAndTime && !callFrame->argument(1).isUndefined()) {
-        dateStyle = styleFromArgString(arg0String, dateStyle);
-        timeStyle = styleFromArgString(callFrame->argument(1).toWTFString(globalObject), timeStyle);
-    } else if (format != LocaleTime && !callFrame->argument(0).isUndefined())
-        dateStyle = styleFromArgString(arg0String, dateStyle);
-    else if (format != LocaleDate && !callFrame->argument(0).isUndefined())
-        timeStyle = styleFromArgString(arg0String, timeStyle);
-
-    CFAbsoluteTime absoluteTime = floor(timeInMilliseconds / msPerSecond) - kCFAbsoluteTimeIntervalSince1970;
-
-    auto formatter = adoptCF(CFDateFormatterCreate(kCFAllocatorDefault, adoptCF(CFLocaleCopyCurrent()).get(), dateStyle, timeStyle));
-    if (useCustomFormat)
-        CFDateFormatterSetFormat(formatter.get(), customFormatString.createCFString().get());
-    return jsNontrivialString(vm, adoptCF(CFDateFormatterCreateStringWithAbsoluteTime(kCFAllocatorDefault, formatter.get(), absoluteTime)).get());
-}
-
-#elif !UCONFIG_NO_FORMATTING
-
-static JSCell* formatLocaleDate(JSGlobalObject* globalObject, CallFrame*, DateInstance* dateObject, double timeInMilliseconds, LocaleDateTimeFormat format)
-{
-    VM& vm = globalObject->vm();
-    Integrity::auditStructureID(vm, dateObject->structureID());
-
-    UDateFormatStyle timeStyle = (format != LocaleDate ? UDAT_LONG : UDAT_NONE);
-    UDateFormatStyle dateStyle = (format != LocaleTime ? UDAT_LONG : UDAT_NONE);
-
-    UErrorCode status = U_ZERO_ERROR;
-    UDateFormat* df = udat_open(timeStyle, dateStyle, nullptr, nullptr, -1, nullptr, 0, &status);
-    if (!df)
-        return jsEmptyString(vm);
-
-    UChar buffer[128];
-    int32_t length;
-    length = udat_format(df, timeInMilliseconds, buffer, 128, nullptr, &status);
-    udat_close(df);
-    if (status != U_ZERO_ERROR)
-        return jsEmptyString(vm);
-
-    return jsNontrivialString(vm, String(buffer, length));
-}
-
-#else
-
-static JSCell* formatLocaleDate(JSGlobalObject* globalObject, CallFrame* callFrame, const GregorianDateTime& gdt, LocaleDateTimeFormat format)
-{
-    VM& vm = globalObject->vm();
-#if OS(WINDOWS)
-    SYSTEMTIME systemTime;
-    memset(&systemTime, 0, sizeof(systemTime));
-    systemTime.wYear = gdt.year();
-    systemTime.wMonth = gdt.month() + 1;
-    systemTime.wDay = gdt.monthDay();
-    systemTime.wDayOfWeek = gdt.weekDay();
-    systemTime.wHour = gdt.hour();
-    systemTime.wMinute = gdt.minute();
-    systemTime.wSecond = gdt.second();
-
-    Vector<UChar, 128> buffer;
-    size_t length = 0;
-
-    if (format == LocaleDate) {
-        buffer.resize(GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &systemTime, 0, 0, 0));
-        length = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &systemTime, 0, buffer.data(), buffer.size());
-    } else if (format == LocaleTime) {
-        buffer.resize(GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systemTime, 0, 0, 0));
-        length = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systemTime, 0, buffer.data(), buffer.size());
-    } else if (format == LocaleDateAndTime) {
-        buffer.resize(GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &systemTime, 0, 0, 0) + GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systemTime, 0, 0, 0));
-        length = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &systemTime, 0, buffer.data(), buffer.size());
-        if (length) {
-            buffer[length - 1] = ' ';
-            length += GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systemTime, 0, buffer.data() + length, buffer.size() - length);
-        }
-    } else
-        RELEASE_ASSERT_NOT_REACHED();
-
-    //  Remove terminating null character.
-    if (length)
-        length--;
-
-    return jsNontrivialString(vm, String(buffer.data(), length));
-
-#else // OS(WINDOWS)
-
-#if HAVE(LANGINFO_H)
-    static const nl_item formats[] = { D_T_FMT, D_FMT, T_FMT };
-#else
-    static const char* const formatStrings[] = { "%#c", "%#x", "%X" };
-#endif
-
-    // Offset year if needed
-    struct tm localTM = gdt;
-    int year = gdt.year();
-    bool yearNeedsOffset = year < 1900 || year > 2038;
-    if (yearNeedsOffset)
-        localTM.tm_year = equivalentYearForDST(year) - 1900;
-
-#if HAVE(LANGINFO_H)
-    // We do not allow strftime to generate dates with 2-digits years,
-    // both to avoid ambiguity, and a crash in strncpy, for years that
-    // need offset.
-    char* formatString = strdup(nl_langinfo(formats[format]));
-    char* yPos = strchr(formatString, 'y');
-    if (yPos)
-        *yPos = 'Y';
-#endif
-
-    // Do the formatting
-    const int bufsize = 128;
-    char timebuffer[bufsize];
-
-#if HAVE(LANGINFO_H)
-    size_t ret = strftime(timebuffer, bufsize, formatString, &localTM);
-    free(formatString);
-#else
-    size_t ret = strftime(timebuffer, bufsize, formatStrings[format], &localTM);
-#endif
-
-    if (ret == 0)
-        return jsEmptyString(vm);
-
-    // Copy original into the buffer
-    if (yearNeedsOffset && format != LocaleTime) {
-        static const int yearLen = 5;   // FIXME will be a problem in the year 10,000
-        char yearString[yearLen];
-
-        snprintf(yearString, yearLen, "%d", localTM.tm_year + 1900);
-        char* yearLocation = strstr(timebuffer, yearString);
-        snprintf(yearString, yearLen, "%d", year);
-
-        strncpy(yearLocation, yearString, yearLen - 1);
-    }
-
-    // Convert multi-byte result to UNICODE.
-    // If __STDC_ISO_10646__ is defined, wide character represents
-    // UTF-16 (or UTF-32) code point. In most modern Unix like system
-    // (e.g. Linux with glibc 2.2 and above) the macro is defined,
-    // and wide character represents UTF-32 code point.
-    // Here we static_cast potential UTF-32 to UTF-16, it should be
-    // safe because date and (or) time related characters in different languages
-    // should be in UNICODE BMP. If mbstowcs fails, we just fall
-    // back on using multi-byte result as-is.
-#ifdef __STDC_ISO_10646__
-    UChar buffer[bufsize];
-    wchar_t tempbuffer[bufsize];
-    size_t length = mbstowcs(tempbuffer, timebuffer, bufsize - 1);
-    if (length != static_cast<size_t>(-1)) {
-        for (size_t i = 0; i < length; ++i)
-            buffer[i] = static_cast<UChar>(tempbuffer[i]);
-        return jsNontrivialString(vm, String(buffer, length));
-    }
-#endif
-
-    return jsNontrivialString(vm, timebuffer);
-#endif // OS(WINDOWS)
-}
-
-static JSCell* formatLocaleDate(JSGlobalObject* globalObject, CallFrame* callFrame, DateInstance* dateObject, double, LocaleDateTimeFormat format)
-{
-    VM& vm = globalObject->vm();
-    Integrity::auditStructureID(vm, dateObject->structureID());
-
-    const GregorianDateTime* gregorianDateTime = dateObject->gregorianDateTime(vm.dateCache);
-    if (!gregorianDateTime)
-        return jsNontrivialString(vm, "Invalid Date"_s);
-    return formatLocaleDate(globalObject, callFrame, *gregorianDateTime, format);
-}
-
-#endif // OS(DARWIN) && USE(CF)
-
 static EncodedJSValue formateDateInstance(JSGlobalObject* globalObject, CallFrame* callFrame, DateTimeFormat format, bool asUTCVariant)
 {
     VM& vm = globalObject->vm();
@@ -427,17 +211,17 @@
     return ok;
 }
 
-const ClassInfo DatePrototype::s_info = {"Object", &JSNonFinalObject::s_info, &dateTable, nullptr, CREATE_METHOD_TABLE(DatePrototype)};
+const ClassInfo DatePrototype::s_info = {"Object", &Base::s_info, &datePrototypeTable, nullptr, CREATE_METHOD_TABLE(DatePrototype)};
 
 /* Source for DatePrototype.lut.h
-@begin dateTable
+@begin datePrototypeTable
   toString              dateProtoFuncToString                DontEnum|Function       0
   toISOString           dateProtoFuncToISOString             DontEnum|Function       0
   toDateString          dateProtoFuncToDateString            DontEnum|Function       0
   toTimeString          dateProtoFuncToTimeString            DontEnum|Function       0
-  toLocaleString        dateProtoFuncToLocaleString          DontEnum|Function       0
-  toLocaleDateString    dateProtoFuncToLocaleDateString      DontEnum|Function       0
-  toLocaleTimeString    dateProtoFuncToLocaleTimeString      DontEnum|Function       0
+  toLocaleString        JSBuiltin                            DontEnum|Function       0
+  toLocaleDateString    JSBuiltin                            DontEnum|Function       0
+  toLocaleTimeString    JSBuiltin                            DontEnum|Function       0
   valueOf               dateProtoFuncGetTime                 DontEnum|Function       0  DatePrototypeGetTimeIntrinsic
   getTime               dateProtoFuncGetTime                 DontEnum|Function       0  DatePrototypeGetTimeIntrinsic
   getFullYear           dateProtoFuncGetFullYear             DontEnum|Function       0  DatePrototypeGetFullYearIntrinsic
@@ -495,10 +279,6 @@
     putDirectWithoutTransition(vm, toUTCStringName, toUTCStringFunction, static_cast<unsigned>(PropertyAttribute::DontEnum));
     putDirectWithoutTransition(vm, Identifier::fromString(vm, "toGMTString"_s), toUTCStringFunction, static_cast<unsigned>(PropertyAttribute::DontEnum));
 
-    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("toLocaleString", datePrototypeToLocaleStringCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
-    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("toLocaleDateString", datePrototypeToLocaleDateStringCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
-    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("toLocaleTimeString", datePrototypeToLocaleTimeStringCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
-
     JSFunction* toPrimitiveFunction = JSFunction::create(vm, globalObject, 1, "[Symbol.toPrimitive]"_s, dateProtoFuncToPrimitiveSymbol, NoIntrinsic);
     putDirectWithoutTransition(vm, vm.propertyNames->toPrimitiveSymbol, toPrimitiveFunction, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
 
@@ -568,42 +348,6 @@
     return formateDateInstance(globalObject, callFrame, DateTimeFormatTime, asUTCVariant);
 }
 
-EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleString(JSGlobalObject* globalObject, CallFrame* callFrame)
-{
-    VM& vm = globalObject->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-    JSValue thisValue = callFrame->thisValue();
-    auto* thisDateObj = jsDynamicCast<DateInstance*>(vm, thisValue);
-    if (UNLIKELY(!thisDateObj))
-        return throwVMTypeError(globalObject, scope);
-
-    return JSValue::encode(formatLocaleDate(globalObject, callFrame, thisDateObj, thisDateObj->internalNumber(), LocaleDateAndTime));
-}
-
-EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleDateString(JSGlobalObject* globalObject, CallFrame* callFrame)
-{
-    VM& vm = globalObject->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-    JSValue thisValue = callFrame->thisValue();
-    auto* thisDateObj = jsDynamicCast<DateInstance*>(vm, thisValue);
-    if (UNLIKELY(!thisDateObj))
-        return throwVMTypeError(globalObject, scope);
-
-    return JSValue::encode(formatLocaleDate(globalObject, callFrame, thisDateObj, thisDateObj->internalNumber(), LocaleDate));
-}
-
-EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleTimeString(JSGlobalObject* globalObject, CallFrame* callFrame)
-{
-    VM& vm = globalObject->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-    JSValue thisValue = callFrame->thisValue();
-    auto* thisDateObj = jsDynamicCast<DateInstance*>(vm, thisValue);
-    if (UNLIKELY(!thisDateObj))
-        return throwVMTypeError(globalObject, scope);
-
-    return JSValue::encode(formatLocaleDate(globalObject, callFrame, thisDateObj, thisDateObj->internalNumber(), LocaleTime));
-}
-
 EncodedJSValue JSC_HOST_CALL dateProtoFuncToPrimitiveSymbol(JSGlobalObject* globalObject, CallFrame* callFrame)
 {
     VM& vm = globalObject->vm();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to