Title: [279962] trunk
Revision
279962
Author
[email protected]
Date
2021-07-15 13:44:57 -0700 (Thu, 15 Jul 2021)

Log Message

[JSC] Harden defaultTimeZone retrieval
https://bugs.webkit.org/show_bug.cgi?id=227996
JSTests:

Reviewed by Mark Lam.

* complex.yaml:
* complex/intl-timezone-check.js: Added.
(shouldBe):

Source/_javascript_Core:

rdar://80540300

Reviewed by Mark Lam.

We received the report that "UTC" can appear in Intl.DateTimeFormat's default timezone.
While we cannot reproduce it, this patch attempts to avoid using TimeZone from UCalendar
so that the code gets the same to the old defaultTimeZone implementation.

* runtime/JSDateMath.cpp:
(JSC::DateCache::defaultTimeZone):
(JSC::DateCache::timeZoneCacheSlow):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (279961 => 279962)


--- trunk/JSTests/ChangeLog	2021-07-15 20:42:53 UTC (rev 279961)
+++ trunk/JSTests/ChangeLog	2021-07-15 20:44:57 UTC (rev 279962)
@@ -1,3 +1,14 @@
+2021-07-15  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Harden defaultTimeZone retrieval
+        https://bugs.webkit.org/show_bug.cgi?id=227996
+
+        Reviewed by Mark Lam.
+
+        * complex.yaml:
+        * complex/intl-timezone-check.js: Added.
+        (shouldBe):
+
 2021-07-15  Mark Lam  <[email protected]>
 
         JITWorklist::waitUntilAllPlansForVMAreReady() should also be notified when plans are cancelled.

Added: trunk/JSTests/complex/intl-timezone-check.js (0 => 279962)


--- trunk/JSTests/complex/intl-timezone-check.js	                        (rev 0)
+++ trunk/JSTests/complex/intl-timezone-check.js	2021-07-15 20:44:57 UTC (rev 279962)
@@ -0,0 +1,6 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+shouldBe(Intl.DateTimeFormat().resolvedOptions().timeZone, "America/Los_Angeles");

Modified: trunk/JSTests/complex.yaml (279961 => 279962)


--- trunk/JSTests/complex.yaml	2021-07-15 20:42:53 UTC (rev 279961)
+++ trunk/JSTests/complex.yaml	2021-07-15 20:44:57 UTC (rev 279962)
@@ -43,3 +43,6 @@
 
 - path: complex/date-parse-milliseconds.js
   cmd: runComplexTest [], [], "TZ=America/Los_Angeles", "--useDollarVM=1"
+
+- path: complex/intl-timezone-check.js
+  cmd: runComplexTest [], [], "TZ=America/Los_Angeles", "--useDollarVM=1"

Modified: trunk/Source/_javascript_Core/ChangeLog (279961 => 279962)


--- trunk/Source/_javascript_Core/ChangeLog	2021-07-15 20:42:53 UTC (rev 279961)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-07-15 20:44:57 UTC (rev 279962)
@@ -1,3 +1,19 @@
+2021-07-15  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Harden defaultTimeZone retrieval
+        https://bugs.webkit.org/show_bug.cgi?id=227996
+        rdar://80540300
+
+        Reviewed by Mark Lam.
+
+        We received the report that "UTC" can appear in Intl.DateTimeFormat's default timezone.
+        While we cannot reproduce it, this patch attempts to avoid using TimeZone from UCalendar
+        so that the code gets the same to the old defaultTimeZone implementation.
+
+        * runtime/JSDateMath.cpp:
+        (JSC::DateCache::defaultTimeZone):
+        (JSC::DateCache::timeZoneCacheSlow):
+
 2021-07-15  Mark Lam  <[email protected]>
 
         JITWorklist::waitUntilAllPlansForVMAreReady() should also be notified when plans are cancelled.

Modified: trunk/Source/_javascript_Core/runtime/JSDateMath.cpp (279961 => 279962)


--- trunk/Source/_javascript_Core/runtime/JSDateMath.cpp	2021-07-15 20:42:53 UTC (rev 279961)
+++ trunk/Source/_javascript_Core/runtime/JSDateMath.cpp	2021-07-15 20:44:57 UTC (rev 279962)
@@ -103,6 +103,7 @@
     WTF_MAKE_FAST_ALLOCATED(OpaqueICUTimeZone);
 public:
     std::unique_ptr<UCalendar, ICUDeleter<ucal_close>> m_calendar;
+    String m_canonicalTimeZoneID;
 };
 #endif
 
@@ -334,22 +335,7 @@
 String DateCache::defaultTimeZone()
 {
 #if HAVE(ICU_C_TIMEZONE_API)
-    auto& timeZone = *timeZoneCache();
-    Vector<UChar, 32> buffer;
-    auto status = callBufferProducingFunction(ucal_getTimeZoneID, timeZone.m_calendar.get(), buffer);
-    if (U_FAILURE(status))
-        return "UTC"_s;
-
-    Vector<UChar, 32> canonicalBuffer;
-    status = callBufferProducingFunction(ucal_getCanonicalTimeZoneID, buffer.data(), buffer.size(), canonicalBuffer, nullptr);
-    if (U_FAILURE(status))
-        return "UTC"_s;
-
-    String canonical = String(canonicalBuffer);
-    if (isUTCEquivalent(canonical))
-        return "UTC"_s;
-
-    return canonical;
+    return timeZoneCache()->m_canonicalTimeZoneID;
 #else
     icu::UnicodeString timeZoneID;
     icu::UnicodeString canonicalTimeZoneID;
@@ -384,9 +370,21 @@
     ASSERT(!m_timeZoneCache);
 #if HAVE(ICU_C_TIMEZONE_API)
     auto* cache = new OpaqueICUTimeZone;
+
+    String canonical;
     Vector<UChar, 32> timeZoneID;
     auto status = callBufferProducingFunction(ucal_getHostTimeZone, timeZoneID);
-    ASSERT_UNUSED(status, U_SUCCESS(status));
+    if (U_SUCCESS(status)) {
+        Vector<UChar, 32> canonicalBuffer;
+        auto status = callBufferProducingFunction(ucal_getCanonicalTimeZoneID, timeZoneID.data(), timeZoneID.size(), canonicalBuffer, nullptr);
+        if (U_SUCCESS(status))
+            canonical = String(canonicalBuffer);
+    }
+    if (canonical.isNull() || isUTCEquivalent(canonical))
+        canonical = "UTC"_s;
+    cache->m_canonicalTimeZoneID = WTFMove(canonical);
+
+    status = U_ZERO_ERROR;
     cache->m_calendar = std::unique_ptr<UCalendar, ICUDeleter<ucal_close>>(ucal_open(timeZoneID.data(), timeZoneID.size(), "", UCAL_DEFAULT, &status));
     ASSERT_UNUSED(status, U_SUCCESS(status));
     ucal_setGregorianChange(cache->m_calendar.get(), minECMAScriptTime, &status); // Ignore "unsupported" error.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to