⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 293301 in webkit


Ignore:
Timestamp:
Apr 23, 2022, 9:48:31 PM (4 years ago)
Author:
Chris Dumez
Message:

[IDL] Add support for [AtomString] with USVString & ByteString types
https://bugs.webkit.org/show_bug.cgi?id=239695

Reviewed by Cameron McCormack.

Add support for [AtomString] with USVString and ByteString types in our WebIDL
bindings. This is needed to mark the AtomString(const String&) constructor
explicit.

  • Source/WTF/wtf/text/AtomString.cpp:

(WTF::replaceUnpairedSurrogatesWithReplacementCharacterInternal):
(WTF::replaceUnpairedSurrogatesWithReplacementCharacter):

  • Source/WTF/wtf/text/AtomString.h:
  • Source/WTF/wtf/text/WTFString.cpp:

(WTF::replaceUnpairedSurrogatesWithReplacementCharacter): Deleted.

  • Source/WTF/wtf/text/WTFString.h:
  • Source/WebCore/Modules/fetch/FetchResponse.h:
  • Source/WebCore/Modules/fetch/FetchResponse.idl:
  • Source/WebCore/bindings/js/JSDOMConvertStrings.cpp:

(WebCore::throwIfInvalidByteString):
(WebCore::identifierToByteString):
(WebCore::valueToByteString):
(WebCore::valueToByteAtomString):
(WebCore::valueToUSVAtomString):
(WebCore::stringToByteString): Deleted.

  • Source/WebCore/bindings/js/JSDOMConvertStrings.h:

(WebCore::Converter<IDLAtomStringAdaptor<T>>::convert):
(WebCore::Converter<IDLAtomStringAdaptor<IDLUSVString>>::convert):
(WebCore::Converter<IDLAtomStringAdaptor<IDLByteString>>::convert):
(WebCore::JSConverter<IDLAtomStringAdaptor<T>>::convert):
(WebCore::JSConverter<IDLAtomStringAdaptor<IDLUSVString>>::convert):
(WebCore::JSConverter<IDLAtomStringAdaptor<IDLByteString>>::convert):

  • Source/WebCore/html/HTMLAnchorElement.idl:
  • Source/WebCore/html/HTMLAreaElement.idl:
  • Source/WebCore/platform/network/ResourceResponseBase.cpp:

(WebCore::ResourceResponseBase::crossThreadData const):
(WebCore::ResourceResponseBase::fromCrossThreadData):
(WebCore::ResourceResponseBase::httpStatusText const):
(WebCore::ResourceResponseBase::setHTTPStatusText):

  • Source/WebCore/platform/network/ResourceResponseBase.h:

Canonical link: https://commits.webkit.org/249926@main

Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/wtf/text/AtomString.cpp

    r293285 r293301  
    2828
    2929#include <wtf/dtoa.h>
     30#include <wtf/text/StringBuilder.h>
     31#include <wtf/unicode/CharacterNames.h>
    3032
    3133namespace WTF {
     
    161163}
    162164
     165static inline StringBuilder replaceUnpairedSurrogatesWithReplacementCharacterInternal(StringView view)
     166{
     167    // Slow path: https://infra.spec.whatwg.org/#javascript-string-convert
     168    // Replaces unpaired surrogates with the replacement character.
     169    StringBuilder result;
     170    result.reserveCapacity(view.length());
     171    for (auto codePoint : view.codePoints()) {
     172        if (U_IS_SURROGATE(codePoint))
     173            result.append(replacementCharacter);
     174        else
     175            result.appendCharacter(codePoint);
     176    }
     177    return result;
     178}
     179
     180AtomString replaceUnpairedSurrogatesWithReplacementCharacter(AtomString&& string)
     181{
     182    // Fast path for the case where there are no unpaired surrogates.
     183    if (LIKELY(!hasUnpairedSurrogate(string)))
     184        return WTFMove(string);
     185    return replaceUnpairedSurrogatesWithReplacementCharacterInternal(string).toAtomString();
     186}
     187
     188String replaceUnpairedSurrogatesWithReplacementCharacter(String&& string)
     189{
     190    // Fast path for the case where there are no unpaired surrogates.
     191    if (LIKELY(!hasUnpairedSurrogate(string)))
     192        return WTFMove(string);
     193    return replaceUnpairedSurrogatesWithReplacementCharacterInternal(string).toString();
     194}
     195
    163196} // namespace WTF
  • trunk/Source/WTF/wtf/text/AtomString.h

    r293292 r293301  
    209209template<unsigned length> bool equalLettersIgnoringASCIICase(const AtomString&, const char (&lowercaseLetters)[length]);
    210210
     211WTF_EXPORT_PRIVATE AtomString replaceUnpairedSurrogatesWithReplacementCharacter(AtomString&&);
     212WTF_EXPORT_PRIVATE String replaceUnpairedSurrogatesWithReplacementCharacter(String&&);
     213
    211214inline AtomString::AtomString()
    212215{
  • trunk/Source/WTF/wtf/text/WTFString.cpp

    r292945 r293301  
    666666}
    667667
    668 String replaceUnpairedSurrogatesWithReplacementCharacter(String&& string)
    669 {
    670     // Fast path for the case where there are no unpaired surrogates.
    671     if (!hasUnpairedSurrogate(string))
    672         return WTFMove(string);
    673 
    674     // Slow path: https://infra.spec.whatwg.org/#javascript-string-convert
    675     // Replaces unpaired surrogates with the replacement character.
    676     StringBuilder result;
    677     result.reserveCapacity(string.length());
    678     StringView view { string };
    679     for (auto codePoint : view.codePoints()) {
    680         if (U_IS_SURROGATE(codePoint))
    681             result.append(replacementCharacter);
    682         else
    683             result.appendCharacter(codePoint);
    684     }
    685     return result.toString();
    686 }
    687 
    688668} // namespace WTF
    689669
  • trunk/Source/WTF/wtf/text/WTFString.h

    r293056 r293301  
    414414#endif
    415415
    416 WTF_EXPORT_PRIVATE String replaceUnpairedSurrogatesWithReplacementCharacter(String&&);
    417 
    418416// Definitions of string operations
    419417
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r289533 r293301  
    5454    struct Init {
    5555        unsigned short status { 200 };
    56         String statusText;
     56        AtomString statusText;
    5757        std::optional<FetchHeaders::Init> headers;
    5858    };
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.idl

    r289117 r293301  
    3434dictionary FetchResponseInit {
    3535    unsigned short status = 200;
    36     ByteString statusText = "";
     36    [AtomString] ByteString statusText = "";
    3737    HeadersInit headers;
    3838};
  • trunk/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp

    r280181 r293301  
    4444}
    4545
    46 static inline String stringToByteString(JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, String&& string)
     46static inline bool throwIfInvalidByteString(JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, const String& string)
    4747{
    48     if (!string.isAllLatin1()) {
     48    if (UNLIKELY(!string.isAllLatin1())) {
    4949        throwTypeError(&lexicalGlobalObject, scope);
    50         return { };
     50        return true;
    5151    }
    52 
    53     return WTFMove(string);
     52    return false;
    5453}
    5554
     
    6160    auto string = identifierToString(lexicalGlobalObject, identifier);
    6261    RETURN_IF_EXCEPTION(scope, { });
    63     return stringToByteString(lexicalGlobalObject, scope, WTFMove(string));
     62    if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string)))
     63        return { };
     64    return string;
    6465}
    6566
     
    7273    RETURN_IF_EXCEPTION(scope, { });
    7374
    74     return stringToByteString(lexicalGlobalObject, scope, WTFMove(string));
     75    if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string)))
     76        return { };
     77    return string;
     78}
     79
     80AtomString valueToByteAtomString(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)
     81{
     82    VM& vm = lexicalGlobalObject.vm();
     83    auto scope = DECLARE_THROW_SCOPE(vm);
     84
     85    auto string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject);
     86    RETURN_IF_EXCEPTION(scope, { });
     87
     88    if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string.string())))
     89        return nullAtom();
     90
     91    return string;
    7592}
    7693
     
    91108}
    92109
     110AtomString valueToUSVAtomString(JSGlobalObject& lexicalGlobalObject, JSValue value)
     111{
     112    VM& vm = lexicalGlobalObject.vm();
     113    auto scope = DECLARE_THROW_SCOPE(vm);
     114
     115    auto string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject);
     116    RETURN_IF_EXCEPTION(scope, { });
     117
     118    return replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(string));
     119}
     120
    93121} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/JSDOMConvertStrings.h

    r280181 r293301  
    3535WEBCORE_EXPORT String identifierToByteString(JSC::JSGlobalObject&, const JSC::Identifier&);
    3636WEBCORE_EXPORT String valueToByteString(JSC::JSGlobalObject&, JSC::JSValue);
     37WEBCORE_EXPORT AtomString valueToByteAtomString(JSC::JSGlobalObject&, JSC::JSValue);
    3738WEBCORE_EXPORT String identifierToUSVString(JSC::JSGlobalObject&, const JSC::Identifier&);
    3839WEBCORE_EXPORT String valueToUSVString(JSC::JSGlobalObject&, JSC::JSValue);
     40WEBCORE_EXPORT AtomString valueToUSVAtomString(JSC::JSGlobalObject&, JSC::JSValue);
    3941
    4042inline String propertyNameToString(JSC::PropertyName propertyName)
     
    178180};
    179181
     182template<> struct Converter<IDLAtomStringAdaptor<IDLUSVString>> : DefaultConverter<IDLAtomStringAdaptor<IDLUSVString>> {
     183    static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)
     184    {
     185        return valueToUSVAtomString(lexicalGlobalObject, value);
     186    }
     187};
     188
     189template<> struct Converter<IDLAtomStringAdaptor<IDLByteString>> : DefaultConverter<IDLAtomStringAdaptor<IDLByteString>> {
     190    static String convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)
     191    {
     192        return valueToByteAtomString(lexicalGlobalObject, value);
     193    }
     194};
     195
    180196template<typename T>  struct JSConverter<IDLAtomStringAdaptor<T>> {
    181197    static constexpr bool needsState = true;
     
    187203
    188204        return JSConverter<T>::convert(lexicalGlobalObject, value);
     205    }
     206};
     207
     208template<>  struct JSConverter<IDLAtomStringAdaptor<IDLUSVString>> {
     209    static constexpr bool needsState = true;
     210    static constexpr bool needsGlobalObject = false;
     211
     212    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value)
     213    {
     214        return JSConverter<IDLUSVString>::convert(lexicalGlobalObject, value.string());
     215    }
     216};
     217
     218template<>  struct JSConverter<IDLAtomStringAdaptor<IDLByteString>> {
     219    static constexpr bool needsState = true;
     220    static constexpr bool needsGlobalObject = false;
     221
     222    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value)
     223    {
     224        return JSConverter<IDLByteString>::convert(lexicalGlobalObject, value.string());
    189225    }
    190226};
  • trunk/Source/WebCore/html/HTMLAnchorElement.idl

    r293292 r293301  
    3030    [CEReactions=NotNeeded, Reflect] attribute [AtomString] DOMString hreflang;
    3131    [CEReactions=NotNeeded, Reflect] attribute [AtomString] DOMString name;
    32     [CEReactions=NotNeeded, Reflect] attribute USVString ping;
     32    [CEReactions=NotNeeded, Reflect] attribute [AtomString] USVString ping;
    3333    [CEReactions=NotNeeded, Reflect] attribute [AtomString] DOMString rel;
    3434    [CEReactions=NotNeeded, Reflect] attribute [AtomString] DOMString rev;
  • trunk/Source/WebCore/html/HTMLAreaElement.idl

    r293292 r293301  
    2525    [CEReactions=NotNeeded, Reflect] attribute [AtomString] DOMString coords;
    2626    [CEReactions=NotNeeded, Reflect] attribute boolean noHref;
    27     [CEReactions=NotNeeded, Reflect] attribute USVString ping;
     27    [CEReactions=NotNeeded, Reflect] attribute [AtomString] USVString ping;
    2828    [CEReactions=NotNeeded, Reflect] attribute DOMString rel;
    2929    [CEReactions=NotNeeded, Reflect] attribute DOMString shape;
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp

    r293056 r293301  
    9898
    9999    data.httpStatusCode = httpStatusCode();
    100     data.httpStatusText = httpStatusText().isolatedCopy();
     100    data.httpStatusText = httpStatusText().string().isolatedCopy();
    101101    data.httpVersion = httpVersion().isolatedCopy();
    102102
     
    122122
    123123    response.setHTTPStatusCode(data.httpStatusCode);
    124     response.setHTTPStatusText(data.httpStatusText);
     124    response.setHTTPStatusText(AtomString { data.httpStatusText });
    125125    response.setHTTPVersion(data.httpVersion);
    126126
     
    343343}
    344344
    345 const String& ResourceResponseBase::httpStatusText() const
     345const AtomString& ResourceResponseBase::httpStatusText() const
    346346{
    347347    lazyInit(AllFields);
     
    350350}
    351351
    352 void ResourceResponseBase::setHTTPStatusText(const String& statusText)
     352void ResourceResponseBase::setHTTPStatusText(const AtomString& statusText)
    353353{
    354354    lazyInit(AllFields);
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.h

    r293292 r293301  
    107107    WEBCORE_EXPORT bool isRedirection() const;
    108108
    109     WEBCORE_EXPORT const String& httpStatusText() const;
    110     WEBCORE_EXPORT void setHTTPStatusText(const String&);
     109    WEBCORE_EXPORT const AtomString& httpStatusText() const;
     110    WEBCORE_EXPORT void setHTTPStatusText(const AtomString&);
    111111
    112112    WEBCORE_EXPORT const String& httpVersion() const;
Note: See TracChangeset for help on using the changeset viewer.