Changeset 242189 in webkit


Ignore:
Timestamp:
Feb 27, 2019 8:35:25 PM (5 years ago)
Author:
Simon Fraser
Message:

Roll out r242014; it caused crashes in compositing logging (webkit.org/b/195141)

Source/JavaScriptCore:

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::nameForRegister):

Source/WebCore:

  • dom/Document.cpp:

(WebCore::Document::lastModified const):

  • html/FTPDirectoryDocument.cpp:

(WebCore::processFileDateString):

  • mathml/MathMLElement.cpp:

(WebCore::convertToPercentageIfNeeded):
(WebCore::MathMLElement::collectStyleForPresentationAttribute):

  • page/cocoa/ResourceUsageOverlayCocoa.mm:

(WebCore::ResourceUsageOverlay::platformDraw):

  • page/linux/ResourceUsageOverlayLinux.cpp:

(WebCore::cpuUsageString):
(WebCore::gcTimerString):

  • platform/DateComponents.cpp:

(WebCore::DateComponents::toStringForTime const):
(WebCore::DateComponents::toString const):

  • platform/LocalizedStrings.cpp:

(WebCore::localizedString):

  • platform/audio/HRTFElevation.cpp:

(WebCore::HRTFElevation::calculateKernelsForAzimuthElevation):

  • platform/mock/MockRealtimeVideoSource.cpp:

(WebCore::MockRealtimeVideoSource::drawText):

  • rendering/RenderLayerCompositor.cpp:

(WebCore::RenderLayerCompositor::logLayerInfo):

  • rendering/RenderTheme.cpp:

(WebCore::RenderTheme::formatMediaControlsTime const):

Source/WebKit:

  • UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:

(WebKit::LocalAuthenticator::getAssertion):

Source/WebKitLegacy/win:

  • FullscreenVideoController.cpp:

(timeToString):

Source/WTF:

  • wtf/Assertions.cpp:

(WTF::createWithFormatAndArguments): Deleted.

  • wtf/HexNumber.h:

(WTF::StringTypeAdapter<HexNumberBuffer>::toString const):

  • wtf/text/StringConcatenate.h:

(WTF::makeString):
(WTF::pad): Deleted.
(WTF::StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>>::StringTypeAdapter): Deleted.
(WTF::StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>>::length const): Deleted.
(WTF::StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>>::is8Bit const): Deleted.
(WTF::StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>>::writeTo const): Deleted.

  • wtf/text/StringConcatenateNumbers.h:

(WTF::FormattedNumber::fixedPrecision):
(WTF::FormattedNumber::fixedWidth):
(WTF::StringTypeAdapter<FormattedNumber>::toString const):

  • wtf/text/StringOperators.h:

(WTF::StringAppend::StringAppend):

  • wtf/text/StringView.h:

(WTF::StringView::invalidate):

  • wtf/text/WTFString.cpp:

(WTF::createWithFormatAndArguments):
(WTF::String::format):

  • wtf/text/WTFString.h:
Location:
trunk/Source
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r242137 r242189  
     12019-02-27  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Roll out r242014; it caused crashes in compositing logging (webkit.org/b/195141)
     4
     5        * bytecode/CodeBlock.cpp:
     6        (JSC::CodeBlock::nameForRegister):
     7
    182019-02-27  Antoine Quint  <graouts@apple.com>
    29
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r242014 r242189  
    9393#include <wtf/SimpleStats.h>
    9494#include <wtf/StringPrintStream.h>
    95 #include <wtf/text/StringConcatenateNumbers.h>
    9695#include <wtf/text/UniquedStringImpl.h>
    9796
     
    28902889        return "this"_s;
    28912890    if (virtualRegister.isArgument())
    2892         return makeString("arguments[", pad(' ', 3, virtualRegister.toArgument()), ']');
    2893 
    2894     return emptyString();
     2891        return String::format("arguments[%3d]", virtualRegister.toArgument());
     2892
     2893    return "";
    28952894}
    28962895
  • trunk/Source/WTF/ChangeLog

    r242127 r242189  
     12019-02-27  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Roll out r242014; it caused crashes in compositing logging (webkit.org/b/195141)
     4
     5        * wtf/Assertions.cpp:
     6        (WTF::createWithFormatAndArguments): Deleted.
     7        * wtf/HexNumber.h:
     8        (WTF::StringTypeAdapter<HexNumberBuffer>::toString const):
     9        * wtf/text/StringConcatenate.h:
     10        (WTF::makeString):
     11        (WTF::pad): Deleted.
     12        (WTF::StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>>::StringTypeAdapter): Deleted.
     13        (WTF::StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>>::length const): Deleted.
     14        (WTF::StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>>::is8Bit const): Deleted.
     15        (WTF::StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>>::writeTo const): Deleted.
     16        * wtf/text/StringConcatenateNumbers.h:
     17        (WTF::FormattedNumber::fixedPrecision):
     18        (WTF::FormattedNumber::fixedWidth):
     19        (WTF::StringTypeAdapter<FormattedNumber>::toString const):
     20        * wtf/text/StringOperators.h:
     21        (WTF::StringAppend::StringAppend):
     22        * wtf/text/StringView.h:
     23        (WTF::StringView::invalidate):
     24        * wtf/text/WTFString.cpp:
     25        (WTF::createWithFormatAndArguments):
     26        (WTF::String::format):
     27        * wtf/text/WTFString.h:
     28
    1292019-02-26  Mark Lam  <mark.lam@apple.com>
    230
  • trunk/Source/WTF/wtf/Assertions.cpp

    r242075 r242189  
    7575#endif
    7676
    77 namespace WTF {
    78 
    79 WTF_ATTRIBUTE_PRINTF(1, 0) static String createWithFormatAndArguments(const char* format, va_list args)
    80 {
    81     va_list argsCopy;
    82     va_copy(argsCopy, args);
    83 
    84     ALLOW_NONLITERAL_FORMAT_BEGIN
    85 
    86 #if USE(CF) && !OS(WINDOWS)
    87     if (strstr(format, "%@")) {
    88         auto cfFormat = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, format, kCFStringEncodingUTF8));
    89         auto result = adoptCF(CFStringCreateWithFormatAndArguments(kCFAllocatorDefault, nullptr, cfFormat.get(), args));
    90         va_end(argsCopy);
    91         return result.get();
    92     }
    93 #endif
    94 
    95     // Do the format once to get the length.
    96 #if COMPILER(MSVC)
    97     int result = _vscprintf(format, args);
    98 #else
    99     char ch;
    100     int result = vsnprintf(&ch, 1, format, args);
    101 #endif
    102 
    103     if (!result) {
    104         va_end(argsCopy);
    105         return emptyString();
    106     }
    107     if (result < 0) {
    108         va_end(argsCopy);
    109         return { };
    110     }
    111 
    112     Vector<char, 256> buffer;
    113     unsigned length = result;
    114     buffer.grow(length + 1);
    115 
    116     // Now do the formatting again, guaranteed to fit.
    117     vsnprintf(buffer.data(), buffer.size(), format, argsCopy);
    118     va_end(argsCopy);
    119 
    120     ALLOW_NONLITERAL_FORMAT_END
    121 
    122     return StringImpl::create(reinterpret_cast<const LChar*>(buffer.data()), length);
    123 }
    124 
    125 }
    126 
    12777extern "C" {
    12878
     
    444394
    445395    ALLOW_NONLITERAL_FORMAT_BEGIN
    446     String loggingString = WTF::createWithFormatAndArguments(format, args);
     396    String loggingString = String::format(format, args);
    447397    ALLOW_NONLITERAL_FORMAT_END
    448398
  • trunk/Source/WTF/wtf/HexNumber.h

    r242014 r242189  
    103103    bool is8Bit() const { return true; }
    104104    template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, characters(), length()); }
     105    String toString() const { return { characters(), length() }; }
    105106
    106107private:
  • trunk/Source/WTF/wtf/text/StringConcatenate.h

    r242014 r242189  
    2626#pragma once
    2727
    28 #include <cstring>
     28#include <string.h>
    2929#include <wtf/CheckedArithmetic.h>
    3030#include <wtf/text/AtomicString.h>
     
    3939namespace WTF {
    4040
    41 template<> class StringTypeAdapter<char, void> {
     41template<typename StringType, typename>
     42class StringTypeAdapter;
     43
     44template<>
     45class StringTypeAdapter<char, void> {
    4246public:
    4347    StringTypeAdapter(char character)
    44         : m_character { character }
     48        : m_character(character)
    4549    {
    4650    }
     
    4852    unsigned length() { return 1; }
    4953    bool is8Bit() { return true; }
    50     template<typename CharacterType> void writeTo(CharacterType* destination) const { *destination = m_character; }
     54
     55    void writeTo(LChar* destination) const
     56    {
     57        *destination = m_character;
     58    }
     59
     60    void writeTo(UChar* destination) const
     61    {
     62        *destination = m_character;
     63    }
     64
     65    String toString() const { return String(&m_character, 1); }
    5166
    5267private:
     
    5469};
    5570
    56 template<> class StringTypeAdapter<UChar, void> {
     71template<>
     72class StringTypeAdapter<UChar, void> {
    5773public:
    5874    StringTypeAdapter(UChar character)
    59         : m_character { character }
     75        : m_character(character)
    6076    {
    6177    }
    6278
    6379    unsigned length() const { return 1; }
    64     bool is8Bit() const { return isLatin1(m_character); }
     80    bool is8Bit() const { return m_character <= 0xff; }
    6581
    6682    void writeTo(LChar* destination) const
    6783    {
    6884        ASSERT(is8Bit());
     85        *destination = static_cast<LChar>(m_character);
     86    }
     87
     88    void writeTo(UChar* destination) const
     89    {
    6990        *destination = m_character;
    7091    }
    7192
    72     void writeTo(UChar* destination) const { *destination = m_character; }
     93    String toString() const { return String(&m_character, 1); }
    7394
    7495private:
     
    7697};
    7798
    78 template<> class StringTypeAdapter<const LChar*, void> {
     99template<>
     100class StringTypeAdapter<const LChar*, void> {
    79101public:
    80102    StringTypeAdapter(const LChar* characters)
    81         : m_characters { characters }
    82         , m_length { computeLength(characters) }
    83     {
     103        : m_characters(characters)
     104    {
     105        size_t length = strlen(reinterpret_cast<const char*>(characters));
     106        RELEASE_ASSERT(length <= String::MaxLength);
     107        m_length = static_cast<unsigned>(length);
    84108    }
    85109
    86110    unsigned length() const { return m_length; }
    87111    bool is8Bit() const { return true; }
    88     template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, m_characters, m_length); }
    89 
    90 private:
    91     static unsigned computeLength(const LChar* characters)
    92     {
    93         size_t length = std::strlen(reinterpret_cast<const char*>(characters));
    94         RELEASE_ASSERT(length <= String::MaxLength);
    95         return static_cast<unsigned>(length);
    96     }
    97 
     112
     113    void writeTo(LChar* destination) const
     114    {
     115        StringView(m_characters, m_length).getCharactersWithUpconvert(destination);
     116    }
     117
     118    void writeTo(UChar* destination) const
     119    {
     120        StringView(m_characters, m_length).getCharactersWithUpconvert(destination);
     121    }
     122
     123    String toString() const { return String(m_characters, m_length); }
     124
     125private:
    98126    const LChar* m_characters;
    99127    unsigned m_length;
    100128};
    101129
    102 template<> class StringTypeAdapter<const UChar*, void> {
     130template<>
     131class StringTypeAdapter<const UChar*, void> {
    103132public:
    104133    StringTypeAdapter(const UChar* characters)
    105         : m_characters { characters }
    106         , m_length { computeLength(characters) }
    107     {
    108     }
    109 
    110     unsigned length() const { return m_length; }
    111     bool is8Bit() const { return !m_length; }
    112     void writeTo(LChar*) const { ASSERT(!m_length); }
    113     void writeTo(UChar* destination) const { StringImpl::copyCharacters(destination, m_characters, m_length); }
    114 
    115 private:
    116     static unsigned computeLength(const UChar* characters)
     134        : m_characters(characters)
    117135    {
    118136        size_t length = 0;
    119         while (characters[length])
     137        while (m_characters[length])
    120138            ++length;
    121139        RELEASE_ASSERT(length <= String::MaxLength);
    122         return static_cast<unsigned>(length);
    123     }
    124 
     140        m_length = static_cast<unsigned>(length);
     141    }
     142
     143    unsigned length() const { return m_length; }
     144    bool is8Bit() const { return false; }
     145
     146    NO_RETURN_DUE_TO_CRASH void writeTo(LChar*) const
     147    {
     148        CRASH(); // FIXME make this a compile-time failure https://bugs.webkit.org/show_bug.cgi?id=165791
     149    }
     150
     151    void writeTo(UChar* destination) const
     152    {
     153        memcpy(destination, m_characters, m_length * sizeof(UChar));
     154    }
     155
     156    String toString() const { return String(m_characters, m_length); }
     157
     158private:
    125159    const UChar* m_characters;
    126160    unsigned m_length;
    127161};
    128162
    129 template<> class StringTypeAdapter<const char*, void> : public StringTypeAdapter<const LChar*, void> {
     163template<>
     164class StringTypeAdapter<const char*, void> : public StringTypeAdapter<const LChar*, void> {
    130165public:
    131166    StringTypeAdapter(const char* characters)
    132         : StringTypeAdapter<const LChar*, void> { reinterpret_cast<const LChar*>(characters) }
    133     {
    134     }
    135 };
    136 
    137 template<> class StringTypeAdapter<char*, void> : public StringTypeAdapter<const char*, void> {
     167        : StringTypeAdapter<const LChar*, void>(reinterpret_cast<const LChar*>(characters))
     168    {
     169    }
     170};
     171
     172template<>
     173class StringTypeAdapter<char*, void> : public StringTypeAdapter<const char*, void> {
    138174public:
    139175    StringTypeAdapter(const char* characters)
    140         : StringTypeAdapter<const char*, void> { characters }
    141     {
    142     }
    143 };
    144 
    145 template<> class StringTypeAdapter<ASCIILiteral, void> : public StringTypeAdapter<const char*, void> {
     176        : StringTypeAdapter<const char*, void>(characters)
     177    {
     178    }
     179};
     180
     181template<>
     182class StringTypeAdapter<ASCIILiteral, void> : public StringTypeAdapter<const char*, void> {
    146183public:
    147184    StringTypeAdapter(ASCIILiteral characters)
    148         : StringTypeAdapter<const char*, void> { characters }
    149     {
    150     }
    151 };
    152 
    153 template<> class StringTypeAdapter<Vector<char>, void> {
     185        : StringTypeAdapter<const char*, void>(characters)
     186    {
     187    }
     188};
     189
     190template<>
     191class StringTypeAdapter<Vector<char>, void> {
    154192public:
    155193    StringTypeAdapter(const Vector<char>& vector)
    156         : m_vector { vector }
     194        : m_vector(vector)
    157195    {
    158196    }
     
    160198    size_t length() const { return m_vector.size(); }
    161199    bool is8Bit() const { return true; }
    162     template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, characters(), length()); }
    163 
    164 private:
    165     const LChar* characters() const
    166     {
    167         return reinterpret_cast<const LChar*>(m_vector.data());
    168     }
    169 
     200
     201    void writeTo(LChar* destination) const
     202    {
     203        StringView(reinterpret_cast<const LChar*>(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination);
     204    }
     205
     206    void writeTo(UChar* destination) const
     207    {
     208        StringView(reinterpret_cast<const LChar*>(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination);
     209    }
     210
     211    String toString() const { return String(m_vector.data(), m_vector.size()); }
     212
     213private:
    170214    const Vector<char>& m_vector;
    171215};
    172216
    173 template<> class StringTypeAdapter<String, void> {
     217template<>
     218class StringTypeAdapter<String, void> {
    174219public:
    175220    StringTypeAdapter(const String& string)
    176         : m_string { string }
     221        : m_string(string)
    177222    {
    178223    }
     
    180225    unsigned length() const { return m_string.length(); }
    181226    bool is8Bit() const { return m_string.isNull() || m_string.is8Bit(); }
    182     template<typename CharacterType> void writeTo(CharacterType* destination) const
    183     {
    184         StringView { m_string }.getCharactersWithUpconvert(destination);
     227
     228    void writeTo(LChar* destination) const
     229    {
     230        StringView(m_string).getCharactersWithUpconvert(destination);
    185231        WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
    186232    }
    187233
     234    void writeTo(UChar* destination) const
     235    {
     236        StringView(m_string).getCharactersWithUpconvert(destination);
     237        WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
     238    }
     239
     240    String toString() const { return m_string; }
     241
    188242private:
    189243    const String& m_string;
    190244};
    191245
    192 template<> class StringTypeAdapter<AtomicString, void> : public StringTypeAdapter<String, void> {
     246template<>
     247class StringTypeAdapter<AtomicString, void> : public StringTypeAdapter<String, void> {
    193248public:
    194249    StringTypeAdapter(const AtomicString& string)
    195         : StringTypeAdapter<String, void> { string.string() }
    196     {
    197     }
    198 };
    199 
    200 template<typename UnderlyingAdapterType> struct PaddingSpecification {
    201     LChar character;
    202     unsigned length;
    203     UnderlyingAdapterType underlyingAdapter;
    204 };
    205 
    206 template<typename StringType> PaddingSpecification<StringTypeAdapter<StringType>> pad(char character, unsigned length, StringType adapter)
    207 {
    208     return { static_cast<LChar>(character), length, StringTypeAdapter<StringType> { adapter } };
    209 }
    210 
    211 template<typename UnderlyingAdapterType> class StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>> {
    212 public:
    213     StringTypeAdapter(const PaddingSpecification<UnderlyingAdapterType>& padding)
    214         : m_padding { padding }
    215     {
    216     }
    217 
    218     unsigned length() const { return std::max(m_padding.length, m_padding.underlyingAdapter.length()); }
    219     bool is8Bit() const { return m_padding.underlyingAdapter.is8Bit(); }
    220     template<typename CharacterType> void writeTo(CharacterType* destination) const
    221     {
    222         unsigned underlyingLength = m_padding.underlyingAdapter.length();
    223         unsigned count = 0;
    224         if (underlyingLength < m_padding.length) {
    225             count = m_padding.length - underlyingLength;
    226             for (unsigned i = 0; i < count; ++i)
    227                 destination[i] = m_padding.character;
    228         }
    229         m_padding.underlyingAdapter.writeTo(destination + count);
    230     }
    231 
    232 private:
    233     const PaddingSpecification<UnderlyingAdapterType>& m_padding;
     250        : StringTypeAdapter<String, void>(string.string())
     251    {
     252    }
    234253};
    235254
     
    296315}
    297316
     317// Convenience only.
     318template<typename StringType>
     319String makeString(StringType string)
     320{
     321    return String(string);
     322}
     323
    298324template<typename... StringTypes>
    299325String makeString(StringTypes... strings)
     
    308334
    309335using WTF::makeString;
    310 using WTF::pad;
    311336using WTF::tryMakeString;
    312337
  • trunk/Source/WTF/wtf/text/StringConcatenateNumbers.h

    r242014 r242189  
    4343    bool is8Bit() const { return true; }
    4444    template<typename CharacterType> void writeTo(CharacterType* destination) const { writeNumberToBufferSigned(m_number, destination); }
     45    String toString() const { return String::number(m_number); }
    4546
    4647private:
     
    5960    bool is8Bit() const { return true; }
    6061    template<typename CharacterType> void writeTo(CharacterType* destination) const { writeNumberToBufferUnsigned(m_number, destination); }
     62    String toString() const { return String::number(m_number); }
    6163
    6264private:
     
    7072    {
    7173        numberToString(number, m_buffer);
    72         m_length = std::strlen(m_buffer);
     74        m_length = strlen(m_buffer);
    7375    }
    7476
     
    7678    bool is8Bit() const { return true; }
    7779    template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, buffer(), m_length); }
     80    String toString() const { return { buffer(), m_length }; }
    7881
    7982private:
     
    9093        FormattedNumber numberFormatter;
    9194        numberToFixedPrecisionString(number, significantFigures, numberFormatter.m_buffer, trailingZerosTruncatingPolicy == TruncateTrailingZeros);
    92         numberFormatter.m_length = std::strlen(numberFormatter.m_buffer);
     95        numberFormatter.m_length = strlen(numberFormatter.m_buffer);
    9396        return numberFormatter;
    9497    }
     
    98101        FormattedNumber numberFormatter;
    99102        numberToFixedWidthString(number, decimalPlaces, numberFormatter.m_buffer);
    100         numberFormatter.m_length = std::strlen(numberFormatter.m_buffer);
     103        numberFormatter.m_length = strlen(numberFormatter.m_buffer);
    101104        return numberFormatter;
    102105    }
     
    110113};
    111114
    112 template<> class StringTypeAdapter<FormattedNumber> {
     115template<>
     116class StringTypeAdapter<FormattedNumber> {
    113117public:
    114118    StringTypeAdapter(const FormattedNumber& number)
     
    120124    bool is8Bit() const { return true; }
    121125    template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, m_number.buffer(), m_number.length()); }
     126    String toString() const { return { m_number.buffer(), m_number.length() }; }
    122127
    123128private:
  • trunk/Source/WTF/wtf/text/StringOperators.h

    r242014 r242189  
    2424namespace WTF {
    2525
    26 template<typename StringType1, typename StringType2> class StringAppend {
     26template<typename StringType1, typename StringType2>
     27class StringAppend {
    2728public:
    2829    StringAppend(StringType1 string1, StringType2 string2)
    29         : m_string1 { string1 }
    30         , m_string2 { string2 }
     30        : m_string1(string1)
     31        , m_string2(string2)
    3132    {
    3233    }
     
    8586public:
    8687    StringTypeAdapter<StringAppend<StringType1, StringType2>>(StringAppend<StringType1, StringType2>& buffer)
    87         : m_buffer { buffer }
     88        : m_buffer(buffer)
    8889    {
    8990    }
    9091
    91     unsigned length() const { return m_buffer.length(); }
    92     bool is8Bit() const { return m_buffer.is8Bit(); }
    93     template<typename CharacterType> void writeTo(CharacterType* destination) const { m_buffer.writeTo(destination); }
     92    unsigned length() { return m_buffer.length(); }
     93
     94    bool is8Bit() { return m_buffer.is8Bit(); }
     95
     96    void writeTo(LChar* destination) { m_buffer.writeTo(destination); }
     97    void writeTo(UChar* destination) { m_buffer.writeTo(destination); }
     98
     99    String toString() const { return m_buffer; }
    94100
    95101private:
  • trunk/Source/WTF/wtf/text/StringView.h

    r242014 r242189  
    566566
    567567#if !CHECK_STRINGVIEW_LIFETIME
    568 
    569568inline void StringView::invalidate(const StringImpl&)
    570569{
    571570}
    572 
    573571#endif
     572
     573template<typename StringType, typename> class StringTypeAdapter;
    574574
    575575template<> class StringTypeAdapter<StringView, void> {
    576576public:
    577577    StringTypeAdapter(StringView string)
    578         : m_string { string }
     578        : m_string(string)
    579579    {
    580580    }
     
    582582    unsigned length() { return m_string.length(); }
    583583    bool is8Bit() { return m_string.is8Bit(); }
    584     template<typename CharacterType> void writeTo(CharacterType* destination) { m_string.getCharactersWithUpconvert(destination); }
     584    void writeTo(LChar* destination) { m_string.getCharactersWithUpconvert(destination); }
     585    void writeTo(UChar* destination) { m_string.getCharactersWithUpconvert(destination); }
     586
     587    String toString() const { return m_string.toString(); }
    585588
    586589private:
  • trunk/Source/WTF/wtf/text/WTFString.cpp

    r242014 r242189  
    450450}
    451451
     452WTF_ATTRIBUTE_PRINTF(1, 0) static String createWithFormatAndArguments(const char *format, va_list args)
     453{
     454    va_list argsCopy;
     455    va_copy(argsCopy, args);
     456
     457    ALLOW_NONLITERAL_FORMAT_BEGIN
     458
     459#if USE(CF) && !OS(WINDOWS)
     460    if (strstr(format, "%@")) {
     461        auto cfFormat = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, format, kCFStringEncodingUTF8));
     462        auto result = adoptCF(CFStringCreateWithFormatAndArguments(kCFAllocatorDefault, nullptr, cfFormat.get(), args));
     463        va_end(argsCopy);
     464        return result.get();
     465    }
     466#endif
     467
     468    // Do the format once to get the length.
     469#if COMPILER(MSVC)
     470    int result = _vscprintf(format, args);
     471#else
     472    char ch;
     473    int result = vsnprintf(&ch, 1, format, args);
     474#endif
     475
     476    if (!result) {
     477        va_end(argsCopy);
     478        return emptyString();
     479    }
     480    if (result < 0) {
     481        va_end(argsCopy);
     482        return String();
     483    }
     484
     485    Vector<char, 256> buffer;
     486    unsigned len = result;
     487    buffer.grow(len + 1);
     488
     489    // Now do the formatting again, guaranteed to fit.
     490    vsnprintf(buffer.data(), buffer.size(), format, argsCopy);
     491    va_end(argsCopy);
     492
     493    ALLOW_NONLITERAL_FORMAT_END
     494
     495    return StringImpl::create(reinterpret_cast<const LChar*>(buffer.data()), len);
     496}
     497
     498String String::format(const char *format, ...)
     499{
     500    va_list args;
     501    va_start(args, format);
     502    String result = createWithFormatAndArguments(format, args);
     503    va_end(args);
     504    return result;
     505}
     506
    452507String String::number(int number)
    453508{
  • trunk/Source/WTF/wtf/text/WTFString.h

    r242014 r242189  
    261261    // Use convertToASCIILowercase instead if ASCII case insensitive comparison is desired.
    262262    WTF_EXPORT_PRIVATE String foldCase() const;
     263
     264    WTF_EXPORT_PRIVATE static String format(const char *, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    263265
    264266    // Returns an uninitialized string. The characters needs to be written
  • trunk/Source/WebCore/ChangeLog

    r242184 r242189  
     12019-02-27  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Roll out r242014; it caused crashes in compositing logging (webkit.org/b/195141)
     4
     5        * dom/Document.cpp:
     6        (WebCore::Document::lastModified const):
     7        * html/FTPDirectoryDocument.cpp:
     8        (WebCore::processFileDateString):
     9        * mathml/MathMLElement.cpp:
     10        (WebCore::convertToPercentageIfNeeded):
     11        (WebCore::MathMLElement::collectStyleForPresentationAttribute):
     12        * page/cocoa/ResourceUsageOverlayCocoa.mm:
     13        (WebCore::ResourceUsageOverlay::platformDraw):
     14        * page/linux/ResourceUsageOverlayLinux.cpp:
     15        (WebCore::cpuUsageString):
     16        (WebCore::gcTimerString):
     17        * platform/DateComponents.cpp:
     18        (WebCore::DateComponents::toStringForTime const):
     19        (WebCore::DateComponents::toString const):
     20        * platform/LocalizedStrings.cpp:
     21        (WebCore::localizedString):
     22        * platform/audio/HRTFElevation.cpp:
     23        (WebCore::HRTFElevation::calculateKernelsForAzimuthElevation):
     24        * platform/mock/MockRealtimeVideoSource.cpp:
     25        (WebCore::MockRealtimeVideoSource::drawText):
     26        * rendering/RenderLayerCompositor.cpp:
     27        (WebCore::RenderLayerCompositor::logLayerInfo):
     28        * rendering/RenderTheme.cpp:
     29        (WebCore::RenderTheme::formatMediaControlsTime const):
     30
    1312019-02-27  Zalan Bujtas  <zalan@apple.com>
    232
  • trunk/Source/WebCore/dom/Document.cpp

    r242137 r242189  
    49974997        dateTime = loader()->response().lastModified();
    49984998
    4999     // FIXME: If this document came from the file system, the HTML specification tells
    5000     // us to read the last modification date from the file system.
     4999    // FIXME: If this document came from the file system, the HTML5
     5000    // specification tells us to read the last modification date from the file
     5001    // system.
    50015002    if (!dateTime)
    50025003        dateTime = WallTime::now();
     
    50045005    auto ctime = dateTime.value().secondsSinceEpoch().secondsAs<time_t>();
    50055006    auto localDateTime = std::localtime(&ctime);
    5006     return makeString(pad('0', 2, localDateTime->tm_mon + 1), '/',
    5007         pad('0', 2, localDateTime->tm_mday), '/',
    5008         pad('0', 4, 1900 + localDateTime->tm_year), ' ',
    5009         pad('0', 2, localDateTime->tm_hour), ':',
    5010         pad('0', 2, localDateTime->tm_min), ':',
    5011         pad('0', 2, localDateTime->tm_sec));
     5007    return String::format("%02d/%02d/%04d %02d:%02d:%02d", localDateTime->tm_mon + 1, localDateTime->tm_mday, 1900 + localDateTime->tm_year, localDateTime->tm_hour, localDateTime->tm_min, localDateTime->tm_sec);
    50125008}
    50135009
  • trunk/Source/WebCore/html/FTPDirectoryDocument.cpp

    r242014 r242189  
    211211            if (hour == 0)
    212212                hour = 12;
    213             timeOfDay = makeString(", ", hour, ':', pad('0', 2, fileTime.tm_min), " AM");
     213            timeOfDay = String::format(", %i:%02i AM", hour, fileTime.tm_min);
    214214        } else {
    215215            hour = hour - 12;
    216216            if (hour == 0)
    217217                hour = 12;
    218             timeOfDay = makeString(", ", hour, ':', pad('0', 2, fileTime.tm_min), " PM");
     218            timeOfDay = String::format(", %i:%02i PM", hour, fileTime.tm_min);
    219219        }
    220220    }
  • trunk/Source/WebCore/mathml/MathMLElement.cpp

    r242014 r242189  
    4040#include "RenderTableCell.h"
    4141#include <wtf/IsoMallocInlines.h>
    42 #include <wtf/text/StringConcatenateNumbers.h>
    4342
    4443namespace WebCore {
     
    101100static String convertToPercentageIfNeeded(const AtomicString& value)
    102101{
    103     // FIXME: Might be better to use double than float.
    104     // FIXME: Might be better to use "shortest" numeric formatting instead of fixed width.
    105102    bool ok = false;
    106103    float unitlessValue = value.toFloat(&ok);
    107     if (!ok)
    108         return value;
    109     return makeString(FormattedNumber::fixedWidth(unitlessValue * 100, 3), '%');
     104    if (ok)
     105        return String::format("%.3f%%", unitlessValue * 100.0);
     106    return value;
    110107}
    111108
     
    120117    } else if (name == mathcolorAttr)
    121118        addPropertyToPresentationAttributeStyle(style, CSSPropertyColor, value);
    122     // FIXME: The following are deprecated attributes that should lose if there is a conflict with a non-deprecated attribute.
     119    // FIXME: deprecated attributes that should loose in a conflict with a non deprecated attribute
    123120    else if (name == fontsizeAttr)
    124121        addPropertyToPresentationAttributeStyle(style, CSSPropertyFontSize, value);
     
    138135    }  else {
    139136        ASSERT(!isPresentationAttribute(name));
    140         StyledElement::collectStyleForPresentationAttribute(name, value, style);
     137        StyledElement::collectStyleForPresentationAttribute(name, value
     138        , style);
    141139    }
    142140}
  • trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm

    r242014 r242189  
    469469        size_t external = category.externalSize.last();
    470470       
    471         String label = makeString(pad(' ', 11, category.name), ": ", formatByteNumber(dirty));
     471        String label = String::format("% 11s: %s", category.name.ascii().data(), formatByteNumber(dirty).ascii().data());
    472472        if (external)
    473473            label = label + makeString(" + ", formatByteNumber(external));
  • trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp

    r242014 r242189  
    4747    if (cpuUsage < 0)
    4848        return "<unknown>"_s;
    49     return makeString(FormattedNumber::fixedWidth(cpuUsage, 1), '%');
     49    return String::format("%.1f%%", cpuUsage);
    5050}
    5151
     
    6565    if (std::isnan(timerFireDate))
    6666        return "[not scheduled]"_s;
    67     return String::number((timerFireDate - now).seconds());
     67    return String::format("%g", (timerFireDate - now).seconds());
    6868}
    6969
  • trunk/Source/WebCore/platform/DateComponents.cpp

    r242014 r242189  
    3636#include <wtf/DateMath.h>
    3737#include <wtf/MathExtras.h>
    38 #include <wtf/text/StringConcatenateNumbers.h>
     38#include <wtf/text/WTFString.h>
    3939
    4040namespace WebCore {
     
    694694#endif
    695695    case None:
    696         return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute));
     696        return String::format("%02d:%02d", m_hour, m_minute);
    697697    case Second:
    698         return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute), ':', pad('0', 2, m_second));
     698        return String::format("%02d:%02d:%02d", m_hour, m_minute, m_second);
    699699    case Millisecond:
    700         return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute), ':', pad('0', 2, m_second), '.', pad('0', 3, m_millisecond));
     700        return String::format("%02d:%02d:%02d.%03d", m_hour, m_minute, m_second, m_millisecond);
    701701    }
    702702}
     
    706706    switch (m_type) {
    707707    case Date:
    708         return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1), '-', pad('0', 2, m_monthDay));
     708        return String::format("%04d-%02d-%02d", m_year, m_month + 1, m_monthDay);
    709709    case DateTime:
    710         return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1), '-', pad('0', 2, m_monthDay), 'T', toStringForTime(format), 'Z');
     710        return String::format("%04d-%02d-%02dT", m_year, m_month + 1, m_monthDay)
     711            + toStringForTime(format) + "Z"_str;
    711712    case DateTimeLocal:
    712         return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1), '-', pad('0', 2, m_monthDay), 'T', toStringForTime(format));
     713        return String::format("%04d-%02d-%02dT", m_year, m_month + 1, m_monthDay)
     714            + toStringForTime(format);
    713715    case Month:
    714         return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1));
     716        return String::format("%04d-%02d", m_year, m_month + 1);
    715717    case Time:
    716718        return toStringForTime(format);
    717719    case Week:
    718         return makeString(pad('0', 4, m_year), "-W", pad('0', 2, m_week));
     720        return String::format("%04d-W%02d", m_year, m_week);
    719721    case Invalid:
    720722        break;
  • trunk/Source/WebCore/platform/LocalizedStrings.cpp

    r242014 r242189  
    4444namespace WebCore {
    4545
    46 // Because |format| is used as the second parameter to va_start, it cannot be a reference
     46// We can't use String::format for two reasons:
     47//  1) It doesn't handle non-ASCII characters in the format string.
     48//  2) It doesn't handle the %2$d syntax.
     49// Note that because |format| is used as the second parameter to va_start, it cannot be a reference
    4750// type according to section 18.7/3 of the C++ N1905 standard.
    4851String formatLocalizedString(String format, ...)
     
    7174
    7275#if !USE(CF)
    73 
    7476String localizedString(const char* key)
    7577{
    7678    return String::fromUTF8(key, strlen(key));
    7779}
    78 
    7980#endif
    8081
  • trunk/Source/WebCore/platform/audio/HRTFElevation.cpp

    r242014 r242189  
    177177    AudioChannel* rightEarImpulseResponse = response->channel(AudioBus::ChannelRight);
    178178#else
    179     String resourceName = makeString("IRC_", subjectName, "_C_R0195_T", pad('0', 3, azimuth), "_P", pad('0', 3, positiveElevation));
     179    String resourceName = String::format("IRC_%s_C_R0195_T%03d_P%03d", subjectName.utf8().data(), azimuth, positiveElevation);
    180180
    181181    RefPtr<AudioBus> impulseResponse(AudioBus::loadPlatformResource(resourceName.utf8().data(), sampleRate));
  • trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp

    r242014 r242189  
    351351    context.setFillColor(Color::white);
    352352    context.setTextDrawingMode(TextModeFill);
    353     String string = makeString(pad('0', 2, hours), ':', pad('0', 2, minutes), ':', pad('0', 2, seconds), '.', pad('0', 3, milliseconds % 1000));
     353    String string = String::format("%02u:%02u:%02u.%03u", hours, minutes, seconds, milliseconds % 1000);
    354354    context.drawText(timeFont, TextRun((StringView(string))), timeLocation);
    355355
    356     string = makeString(pad('0', 6, m_frameNumber++));
     356    string = String::format("%06u", m_frameNumber++);
    357357    timeLocation.move(0, m_baseFontSize);
    358358    context.drawText(timeFont, TextRun((StringView(string))), timeLocation);
  • trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp

    r242014 r242189  
    6161#include "TiledBacking.h"
    6262#include "TransformState.h"
    63 #include <wtf/HexNumber.h>
    6463#include <wtf/MemoryPressureHandler.h>
    6564#include <wtf/SetForScope.h>
     
    13251324   
    13261325    StringBuilder logString;
    1327     logString.append(makeString(pad(' ', 12 + depth * 2, hex(reinterpret_cast<uintptr_t>(&layer))), " id ", backing->graphicsLayer()->primaryLayerID(), " (", FormattedNumber::fixedWidth(absoluteBounds.x().toFloat(), 3), ',', FormattedNumber::fixedWidth(absoluteBounds.y().toFloat(), 3), '-', FormattedNumber::fixedWidth(absoluteBounds.maxX().toFloat(), 3), ',', FormattedNumber::fixedWidth(absoluteBounds.maxY().toFloat(), 3), ") ", FormattedNumber::fixedWidth(backing->backingStoreMemoryEstimate() / 1024, 2), "KB"));
    1328 
     1326    logString.append(String::format("%*p id %" PRIu64 " (%.3f,%.3f-%.3f,%.3f) %.2fKB", 12 + depth * 2, &layer, backing->graphicsLayer()->primaryLayerID(),
     1327        absoluteBounds.x().toFloat(), absoluteBounds.y().toFloat(), absoluteBounds.maxX().toFloat(), absoluteBounds.maxY().toFloat(),
     1328        backing->backingStoreMemoryEstimate() / 1024));
     1329   
    13291330    if (!layer.renderer().style().hasAutoZIndex())
    13301331        logString.append(makeString(" z-index: ", layer.renderer().style().zIndex()));
  • trunk/Source/WebCore/rendering/RenderTheme.cpp

    r242014 r242189  
    4747#include <wtf/FileSystem.h>
    4848#include <wtf/NeverDestroyed.h>
    49 #include <wtf/text/StringConcatenateNumbers.h>
    5049
    5150#if ENABLE(METER_ELEMENT)
     
    570569    if (!std::isfinite(time))
    571570        time = 0;
    572     // FIXME: Seems like it would be better to use std::lround here.
    573     int seconds = static_cast<int>(std::abs(time));
     571    int seconds = (int)fabsf(time);
    574572    int hours = seconds / (60 * 60);
    575573    int minutes = (seconds / 60) % 60;
    576574    seconds %= 60;
    577     if (hours)
    578         return makeString((time < 0 ? "-" : ""), hours, ':', pad('0', 2, minutes), ':', pad('0', 2, seconds));
    579     return makeString((time < 0 ? "-" : ""), pad('0', 2, minutes), ':', pad('0', 2, seconds));
     575    if (hours) {
     576        if (hours > 9)
     577            return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
     578
     579        return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
     580    }
     581
     582    return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
    580583}
    581584
  • trunk/Source/WebKit/ChangeLog

    r242187 r242189  
     12019-02-27  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Roll out r242014; it caused crashes in compositing logging (webkit.org/b/195141)
     4
     5        * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
     6        (WebKit::LocalAuthenticator::getAssertion):
     7
    182019-02-27  Michael Catanzaro  <mcatanzaro@igalia.com>
    29
  • trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm

    r242014 r242189  
    401401        weakThis->continueGetAssertionAfterUserConsented(consent, context, credentialId, userhandle);
    402402    };
    403     NSData *idData = selectedCredentialAttributes[(id)kSecAttrApplicationTag];
    404     StringView idStringView { static_cast<const LChar*>([idData bytes]), static_cast<unsigned>([idData length]) };
    405403    m_connection->getUserConsent(
    406         makeString("Log into ", requestData().requestOptions.rpId, " with ", idStringView, '.'),
     404        String::format("Log into %s with %s.", requestData().requestOptions.rpId.utf8().data(), selectedCredentialAttributes[(id)kSecAttrApplicationTag]),
    407405        (__bridge SecAccessControlRef)selectedCredentialAttributes[(id)kSecAttrAccessControl],
    408406        WTFMove(callback));
  • trunk/Source/WebKitLegacy/win/ChangeLog

    r242082 r242189  
     12019-02-27  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Roll out r242014; it caused crashes in compositing logging (webkit.org/b/195141)
     4
     5        * FullscreenVideoController.cpp:
     6        (timeToString):
     7
    182019-02-26  Philippe Normand  <pnormand@igalia.com>
    29
  • trunk/Source/WebKitLegacy/win/FullscreenVideoController.cpp

    r242014 r242189  
    4242#include <windowsx.h>
    4343#include <wtf/StdLibExtras.h>
    44 #include <wtf/text/StringConcatenateNumbers.h>
    4544
    4645#if USE(CA)
     
    472471    int minutes = (seconds / 60) % 60;
    473472    seconds %= 60;
    474     if (hours)
    475         return makeString((time < 0 ? "-" : ""), hours, ':', pad('0', 2, minutes), ':', pad('0', 2, seconds));
    476     return makeString((time < 0 ? "-" : ""), pad('0', 2, minutes), ':', pad('0', 2, seconds));
     473
     474    if (hours) {
     475        if (hours > 9)
     476            return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
     477        return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
     478    }
     479
     480    return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
    477481}
    478482
Note: See TracChangeset for help on using the changeset viewer.