<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [INTL] Implement Number Format Functions"
   href="https://bugs.webkit.org/show_bug.cgi?id=147605#c13">Comment # 13</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [INTL] Implement Number Format Functions"
   href="https://bugs.webkit.org/show_bug.cgi?id=147605">bug 147605</a>
              from <span class="vcard"><a class="email" href="mailto:sukolsak&#64;gmail.com" title="Sukolsak Sakshuwong &lt;sukolsak&#64;gmail.com&gt;"> <span class="fn">Sukolsak Sakshuwong</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=147605#c10">comment #10</a>)
<span class="quote">&gt; Comment on <span class="bz_obsolete"><a href="attachment.cgi?id=271263&amp;action=diff" name="attach_271263" title="Patch">attachment 271263</a> <a href="attachment.cgi?id=271263&amp;action=edit" title="Patch">[details]</a></span>
&gt; Patch
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=271263&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=271263&amp;action=review</a>
&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:70
&gt; &gt; +IntlNumberFormat::~IntlNumberFormat()
&gt; &gt; +{
&gt; &gt; +    if (m_numberFormat)
&gt; &gt; +        unum_close(m_numberFormat);
&gt; &gt; +}
&gt; 
&gt; I would have slightly preferred that we use std::unique_ptr instead.
&gt; 
&gt;     struct UNumberFormatDeleter {
&gt;         void operator()(UNumberFormat* numberFormat) const
&gt;         {
&gt;             if (numberFormat)
&gt;                 unum_close(numberFormat);
&gt;         }
&gt;     };
&gt; 
&gt;     std::unique_ptr&lt;UNumberFormat, UNumberFormatDeleter&gt; m_numberFormat;
&gt; 
&gt; If we did that, we would not need to define ~IntlNumberFormat() and other
&gt; code would be a bit simpler as well.
&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:401
&gt; &gt; +    UNumberFormat* numberFormat = unum_open(style, nullptr, 0, m_locale.utf8().data(), nullptr, &amp;status);
&gt; 
&gt; If we used std::unique_ptr this would be:
&gt; 
&gt;     auto numberFormat = std::unique_ptr&lt;UNumberFormat,
&gt; UNumberFormatDeleter&gt;(unum_open(style, nullptr, 0, m_locale.utf8().data(),
&gt; nullptr, &amp;status));
&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:406
&gt; &gt; +        unum_setTextAttribute(numberFormat, UNUM_CURRENCY_CODE, StringView(m_currency).upconvertedCharacters(), 3, &amp;status);
&gt; 
&gt; If we used std::unique_ptr, these lines would need to use get().
&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:419
&gt; &gt; +        unum_close(numberFormat);
&gt; 
&gt; We would not need this if we used std::unique_ptr.
&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:423
&gt; &gt; +    m_numberFormat = numberFormat;
&gt; 
&gt; This line would need to be:
&gt; 
&gt;     m_numberFormat = WTFMove(numberFormat);</span >

Done. Thanks. I will update other Intl classes to std::unique_ptr in a separate patch.

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:436
&gt; &gt; +    if (bitwise_cast&lt;uint64_t&gt;(number) == bitwise_cast&lt;uint64_t&gt;(-0.0))
&gt; &gt; +        number = 0.0;
&gt; 
&gt; How is the bitwise_cast code better than:
&gt; 
&gt;     // Map negative zero to positive zero.
&gt;     if (!number)
&gt;         number = 0;
&gt; 
&gt; I don’t think it is.</span >

Fixed.

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:447
&gt; &gt; +        return state.vm().throwException(&amp;state, createError(&amp;state, ASCIILiteral(&quot;Failed to format a number.&quot;)));
&gt; 
&gt; Where is the test coverage for this? When can this fail?</span >

The ICU spec doesn't say what can cause unum_formatUFormattable to fail, and I can't find a case that makes it fail. I put the check in there just in case.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>