Changeset 292484 in webkit


Ignore:
Timestamp:
Apr 6, 2022 11:48:46 AM (2 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Substring resolving should check 8bit / 16bit again
https://bugs.webkit.org/show_bug.cgi?id=236775
<rdar://problem/89253391>

Reviewed by Saam Barati.

JSTests:

  • stress/8bit-16bit-atomize-conversion.js: Added.

(main.v64):
(main):

Source/JavaScriptCore:

Substring JSString is wrapping JSString. Thus it is possible that underlying JSString's 8Bit / 16Bit status
becomes different from substring JSString wrapper's bit. We should not assume they are the same.

  • runtime/JSString.cpp:

(JSC::JSRopeString::resolveRopeInternal const):
(JSC::JSRopeString::resolveRopeToAtomString const):
(JSC::JSRopeString::resolveRopeToExistingAtomString const):
(JSC::JSRopeString::resolveRopeInternal8 const): Deleted.
(JSC::JSRopeString::resolveRopeInternal16 const): Deleted.

  • runtime/JSString.h:
Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r292481 r292484  
     12022-04-06  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Substring resolving should check 8bit / 16bit again
     4        https://bugs.webkit.org/show_bug.cgi?id=236775
     5        <rdar://problem/89253391>
     6
     7        Reviewed by Saam Barati.
     8
     9        * stress/8bit-16bit-atomize-conversion.js: Added.
     10        (main.v64):
     11        (main):
     12
    1132022-04-06  Alexey Shvayka  <ashvayka@apple.com>
    214
  • trunk/Source/JavaScriptCore/ChangeLog

    r292477 r292484  
     12022-04-06  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Substring resolving should check 8bit / 16bit again
     4        https://bugs.webkit.org/show_bug.cgi?id=236775
     5        <rdar://problem/89253391>
     6
     7        Reviewed by Saam Barati.
     8
     9        Substring JSString is wrapping JSString. Thus it is possible that underlying JSString's 8Bit / 16Bit status
     10        becomes different from substring JSString wrapper's bit. We should not assume they are the same.
     11
     12        * runtime/JSString.cpp:
     13        (JSC::JSRopeString::resolveRopeInternal const):
     14        (JSC::JSRopeString::resolveRopeToAtomString const):
     15        (JSC::JSRopeString::resolveRopeToExistingAtomString const):
     16        (JSC::JSRopeString::resolveRopeInternal8 const): Deleted.
     17        (JSC::JSRopeString::resolveRopeInternal16 const): Deleted.
     18        * runtime/JSString.h:
     19
    1202022-04-06  Chris Dumez  <cdumez@apple.com>
    221
  • trunk/Source/JavaScriptCore/runtime/JSString.cpp

    r291937 r292484  
    153153static constexpr unsigned maxLengthForOnStackResolve = 2048;
    154154
    155 void JSRopeString::resolveRopeInternal8(LChar* buffer) const
     155template<typename CharacterType>
     156void JSRopeString::resolveRopeInternal(CharacterType* buffer) const
    156157{
    157158    if (isSubstring()) {
    158         StringImpl::copyCharacters(buffer, substringBase()->valueInternal().characters8() + substringOffset(), length());
    159         return;
    160     }
    161    
    162     resolveRopeInternalNoSubstring(buffer);
    163 }
    164 
    165 void JSRopeString::resolveRopeInternal16(UChar* buffer) const
    166 {
    167     if (isSubstring()) {
    168         StringImpl::copyCharacters(
    169             buffer, substringBase()->valueInternal().characters16() + substringOffset(), length());
     159        // It is possible that underlying string becomes 8bit/16bit while wrapper substring is saying it is 16bit/8bit.
     160        // But It is definitely true that substring part can be represented as its parent's status 8bit/16bit, which is described as CharacterType.
     161        auto& string = substringBase()->valueInternal();
     162        if (string.is8Bit())
     163            StringImpl::copyCharacters(buffer, string.characters8() + substringOffset(), length());
     164        else
     165            StringImpl::copyCharacters(buffer, string.characters16() + substringOffset(), length());
    170166        return;
    171167    }
     
    211207    if (is8Bit()) {
    212208        LChar buffer[maxLengthForOnStackResolve];
    213         resolveRopeInternal8(buffer);
     209        resolveRopeInternal(buffer);
    214210        convertToNonRope(AtomStringImpl::add(buffer, length()));
    215211    } else {
    216212        UChar buffer[maxLengthForOnStackResolve];
    217         resolveRopeInternal16(buffer);
     213        resolveRopeInternal(buffer);
    218214        convertToNonRope(AtomStringImpl::add(buffer, length()));
    219215    }
     
    256252    if (is8Bit()) {
    257253        LChar buffer[maxLengthForOnStackResolve];
    258         resolveRopeInternal8(buffer);
     254        resolveRopeInternal(buffer);
    259255        if (RefPtr<AtomStringImpl> existingAtomString = AtomStringImpl::lookUp(buffer, length())) {
    260256            convertToNonRope(*existingAtomString);
     
    263259    } else {
    264260        UChar buffer[maxLengthForOnStackResolve];
    265         resolveRopeInternal16(buffer);
     261        resolveRopeInternal(buffer);
    266262        if (RefPtr<AtomStringImpl> existingAtomString = AtomStringImpl::lookUp(buffer, length())) {
    267263            convertToNonRope(*existingAtomString);
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r291937 r292484  
    609609    Identifier toIdentifier(JSGlobalObject*) const;
    610610    void outOfMemory(JSGlobalObject* nullOrGlobalObjectForOOM) const;
    611     void resolveRopeInternal8(LChar*) const;
    612     void resolveRopeInternal16(UChar*) const;
     611    template<typename CharacterType> void resolveRopeInternal(CharacterType*) const;
    613612    StringView unsafeView(JSGlobalObject*) const;
    614613    StringViewWithUnderlyingString viewWithUnderlyingString(JSGlobalObject*) const;
Note: See TracChangeset for help on using the changeset viewer.