Title: [263243] trunk/Source/_javascript_Core
Revision
263243
Author
ross.kirsl...@sony.com
Date
2020-06-18 16:13:16 -0700 (Thu, 18 Jun 2020)

Log Message

Unreviewed, address Darin's feedback on r263227.

* runtime/IntlRelativeTimeFormat.cpp:
(JSC::IntlRelativeTimeFormat::UNumberFormatDeleter::operator() const):
(JSC::IntlRelativeTimeFormat::initializeRelativeTimeFormat):
(JSC::IntlRelativeTimeFormat::formatToParts const):
* runtime/IntlRelativeTimeFormat.h:
Keep ownership over our UNumberFormat instance after all,
to avoid relying on behavior ICU isn't explicitly guaranteeing.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (263242 => 263243)


--- trunk/Source/_javascript_Core/ChangeLog	2020-06-18 23:11:50 UTC (rev 263242)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-06-18 23:13:16 UTC (rev 263243)
@@ -1,5 +1,17 @@
 2020-06-18  Ross Kirsling  <ross.kirsl...@sony.com>
 
+        Unreviewed, address Darin's feedback on r263227.
+
+        * runtime/IntlRelativeTimeFormat.cpp:
+        (JSC::IntlRelativeTimeFormat::UNumberFormatDeleter::operator() const):
+        (JSC::IntlRelativeTimeFormat::initializeRelativeTimeFormat):
+        (JSC::IntlRelativeTimeFormat::formatToParts const):
+        * runtime/IntlRelativeTimeFormat.h:
+        Keep ownership over our UNumberFormat instance after all,
+        to avoid relying on behavior ICU isn't explicitly guaranteeing.
+
+2020-06-18  Ross Kirsling  <ross.kirsl...@sony.com>
+
         [Intl] Enable RelativeTimeFormat and Locale by default
         https://bugs.webkit.org/show_bug.cgi?id=213324
 

Modified: trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.cpp (263242 => 263243)


--- trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.cpp	2020-06-18 23:11:50 UTC (rev 263242)
+++ trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.cpp	2020-06-18 23:13:16 UTC (rev 263243)
@@ -46,6 +46,12 @@
         ureldatefmt_close(relativeDateTimeFormatter);
 }
 
+void IntlRelativeTimeFormat::UNumberFormatDeleter::operator()(UNumberFormat* numberFormat) const
+{
+    if (numberFormat)
+        unum_close(numberFormat);
+}
+
 IntlRelativeTimeFormat* IntlRelativeTimeFormat::create(VM& vm, Structure* structure)
 {
     auto* format = new (NotNull, allocateCell<IntlRelativeTimeFormat>(vm.heap)) IntlRelativeTimeFormat(vm, structure);
@@ -143,15 +149,14 @@
     m_numeric = (numeric == "always");
 
     UErrorCode status = U_ZERO_ERROR;
-    m_rawNumberFormat = unum_open(UNUM_DECIMAL, nullptr, 0, dataLocaleWithExtensions.data(), nullptr, &status);
+    m_numberFormat = std::unique_ptr<UNumberFormat, UNumberFormatDeleter>(unum_open(UNUM_DECIMAL, nullptr, 0, dataLocaleWithExtensions.data(), nullptr, &status));
     if (UNLIKELY(U_FAILURE(status))) {
         throwTypeError(globalObject, scope, "failed to initialize RelativeTimeFormat"_s);
         return;
     }
 
-    m_relativeDateTimeFormatter = std::unique_ptr<URelativeDateTimeFormatter, URelativeDateTimeFormatterDeleter>(ureldatefmt_open(dataLocaleWithExtensions.data(), m_rawNumberFormat, m_style, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status));
+    m_relativeDateTimeFormatter = std::unique_ptr<URelativeDateTimeFormatter, URelativeDateTimeFormatterDeleter>(ureldatefmt_open(dataLocaleWithExtensions.data(), nullptr, m_style, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status));
     if (UNLIKELY(U_FAILURE(status))) {
-        unum_close(m_rawNumberFormat);
         throwTypeError(globalObject, scope, "failed to initialize RelativeTimeFormat"_s);
         return;
     }
@@ -277,7 +282,7 @@
     double absValue = std::abs(value);
 
     Vector<UChar, 32> buffer;
-    status = callBufferProducingFunction(unum_formatDoubleForFields, m_rawNumberFormat, absValue, buffer, iterator.get());
+    status = callBufferProducingFunction(unum_formatDoubleForFields, m_numberFormat.get(), absValue, buffer, iterator.get());
     if (U_FAILURE(status))
         return throwTypeError(globalObject, scope, "failed to format relative time"_s);
 

Modified: trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.h (263242 => 263243)


--- trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.h	2020-06-18 23:11:50 UTC (rev 263242)
+++ trunk/Source/_javascript_Core/runtime/IntlRelativeTimeFormat.h	2020-06-18 23:13:16 UTC (rev 263243)
@@ -69,9 +69,12 @@
     struct URelativeDateTimeFormatterDeleter {
         void operator()(URelativeDateTimeFormatter*) const;
     };
+    struct UNumberFormatDeleter {
+        void operator()(UNumberFormat*) const;
+    };
 
     std::unique_ptr<URelativeDateTimeFormatter, URelativeDateTimeFormatterDeleter> m_relativeDateTimeFormatter;
-    UNumberFormat* m_rawNumberFormat;
+    std::unique_ptr<UNumberFormat, UNumberFormatDeleter> m_numberFormat;
 
     String m_locale;
     String m_numberingSystem;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to