Title: [269341] trunk/Source/_javascript_Core
Revision
269341
Author
ysuz...@apple.com
Date
2020-11-03 15:50:40 -0800 (Tue, 03 Nov 2020)

Log Message

[JSC] Obtain default timezone ID from cached icu::TimeZone
https://bugs.webkit.org/show_bug.cgi?id=218531
<rdar://problem/64265880>

Reviewed by Ross Kirsling.

ICU internally caches icu::TimeZone (icu::TimeZone::createDefault), and it is not updated even if system timezone is changed.
As a result, we will see wrong timezone in Intl.DateTimeFormat when system timezone is changed.
We have a mechanism that clears TimeZone cache for JS Date. However, this mechanism is not used for Intl.DateTimeFormat.

This patch retrieves timezone ID from cached icu::TimeZone in VM::dateCache. So system's timezone change can be effective for
Intl.DateTimeFormat, and timezone becomes consistent between JS Date and Intl.DateTimeFormat.

Unfortunately, we need to use C++ APIs since we do not have a way to get timezone ID from icu::TimeZone.
Once https://unicode-org.atlassian.net/browse/ICU-21372 is fixed, we can switch to C APIs.

* runtime/IntlDateTimeFormat.cpp:
(JSC::IntlDateTimeFormat::initializeDateTimeFormat):
(JSC::isUTCEquivalent): Deleted.
(JSC::defaultTimeZone): Deleted.
* runtime/JSDateMath.cpp:
(JSC::DateCache::defaultTimeZone):
* runtime/JSDateMath.h:
(JSC::isUTCEquivalent):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (269340 => 269341)


--- trunk/Source/_javascript_Core/ChangeLog	2020-11-03 23:44:44 UTC (rev 269340)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-11-03 23:50:40 UTC (rev 269341)
@@ -1,3 +1,30 @@
+2020-11-03  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] Obtain default timezone ID from cached icu::TimeZone
+        https://bugs.webkit.org/show_bug.cgi?id=218531
+        <rdar://problem/64265880>
+
+        Reviewed by Ross Kirsling.
+
+        ICU internally caches icu::TimeZone (icu::TimeZone::createDefault), and it is not updated even if system timezone is changed.
+        As a result, we will see wrong timezone in Intl.DateTimeFormat when system timezone is changed.
+        We have a mechanism that clears TimeZone cache for JS Date. However, this mechanism is not used for Intl.DateTimeFormat.
+
+        This patch retrieves timezone ID from cached icu::TimeZone in VM::dateCache. So system's timezone change can be effective for
+        Intl.DateTimeFormat, and timezone becomes consistent between JS Date and Intl.DateTimeFormat.
+
+        Unfortunately, we need to use C++ APIs since we do not have a way to get timezone ID from icu::TimeZone.
+        Once https://unicode-org.atlassian.net/browse/ICU-21372 is fixed, we can switch to C APIs.
+
+        * runtime/IntlDateTimeFormat.cpp:
+        (JSC::IntlDateTimeFormat::initializeDateTimeFormat):
+        (JSC::isUTCEquivalent): Deleted.
+        (JSC::defaultTimeZone): Deleted.
+        * runtime/JSDateMath.cpp:
+        (JSC::DateCache::defaultTimeZone):
+        * runtime/JSDateMath.h:
+        (JSC::isUTCEquivalent):
+
 2020-11-03  Saam Barati  <sbar...@apple.com>
 
         Don't assert there is no checkpoint side state when dropping the JSLock

Modified: trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp (269340 => 269341)


--- trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp	2020-11-03 23:44:44 UTC (rev 269340)
+++ trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp	2020-11-03 23:50:40 UTC (rev 269341)
@@ -85,31 +85,6 @@
     m_boundFormat.set(vm, this, format);
 }
 
-static ALWAYS_INLINE bool isUTCEquivalent(StringView timeZone)
-{
-    return timeZone == "Etc/UTC" || timeZone == "Etc/GMT";
-}
-
-// https://tc39.es/ecma402/#sec-defaulttimezone
-static String defaultTimeZone()
-{
-    String canonical;
-
-    Vector<UChar, 32> buffer;
-    auto status = callBufferProducingFunction(ucal_getDefaultTimeZone, buffer);
-    if (U_SUCCESS(status)) {
-        Vector<UChar, 32> canonicalBuffer;
-        status = callBufferProducingFunction(ucal_getCanonicalTimeZoneID, buffer.data(), buffer.size(), canonicalBuffer, nullptr);
-        if (U_SUCCESS(status))
-            canonical = String(canonicalBuffer);
-    }
-
-    if (canonical.isNull() || isUTCEquivalent(canonical))
-        return "UTC"_s;
-
-    return canonical;
-}
-
 static String canonicalizeTimeZoneName(const String& timeZoneName)
 {
     // 6.4.1 IsValidTimeZoneName (timeZone)
@@ -603,7 +578,7 @@
             return;
         }
     } else
-        tz = defaultTimeZone();
+        tz = vm.dateCache.defaultTimeZone();
     m_timeZone = tz;
 
     StringBuilder skeletonBuilder;

Modified: trunk/Source/_javascript_Core/runtime/JSDateMath.cpp (269340 => 269341)


--- trunk/Source/_javascript_Core/runtime/JSDateMath.cpp	2020-11-03 23:44:44 UTC (rev 269340)
+++ trunk/Source/_javascript_Core/runtime/JSDateMath.cpp	2020-11-03 23:50:40 UTC (rev 269341)
@@ -82,6 +82,7 @@
 #define U_SHOW_CPLUSPLUS_API 1
 #include <unicode/basictz.h>
 #include <unicode/timezone.h>
+#include <unicode/unistr.h>
 #undef U_SHOW_CPLUSPLUS_API
 #define U_SHOW_CPLUSPLUS_API 0
 
@@ -182,6 +183,27 @@
     return value;
 }
 
+// https://tc39.es/ecma402/#sec-defaulttimezone
+String DateCache::defaultTimeZone()
+{
+    icu::UnicodeString timeZoneID;
+    icu::UnicodeString canonicalTimeZoneID;
+    auto& timeZone = *bitwise_cast<icu::TimeZone*>(timeZoneCache());
+    timeZone.getID(timeZoneID);
+
+    UErrorCode status = U_ZERO_ERROR;
+    UBool isSystem = false;
+    icu::TimeZone::getCanonicalID(timeZoneID, canonicalTimeZoneID, isSystem, status);
+    if (U_FAILURE(status))
+        return "UTC"_s;
+
+    String canonical = String(canonicalTimeZoneID.getBuffer(), canonicalTimeZoneID.length());
+    if (isUTCEquivalent(canonical))
+        return "UTC"_s;
+
+    return canonical;
+}
+
 // To confine icu::TimeZone destructor invocation in this file.
 DateCache::DateCache() = default;
 DateCache::~DateCache() = default;

Modified: trunk/Source/_javascript_Core/runtime/JSDateMath.h (269340 => 269341)


--- trunk/Source/_javascript_Core/runtime/JSDateMath.h	2020-11-03 23:44:44 UTC (rev 269340)
+++ trunk/Source/_javascript_Core/runtime/JSDateMath.h	2020-11-03 23:50:40 UTC (rev 269341)
@@ -67,6 +67,8 @@
 
     JS_EXPORT_PRIVATE void reset();
 
+    String defaultTimeZone();
+
     OpaqueICUTimeZone* timeZoneCache()
     {
         if (!m_timeZoneCache)
@@ -89,4 +91,9 @@
     DateInstanceCache m_dateInstanceCache;
 };
 
+ALWAYS_INLINE bool isUTCEquivalent(StringView timeZone)
+{
+    return timeZone == "Etc/UTC"_s || timeZone == "Etc/GMT"_s;
+}
+
 } // namespace JSC
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to