Ignore:
Timestamp:
Jan 16, 2014, 10:50:26 PM (11 years ago)
Author:
[email protected]
Message:

Get rid of OpaqueJSString::deprecatedCharacters()
https://bugs.webkit.org/show_bug.cgi?id=127161

Reviewed by Sam Weinig.

Handle OpaqueJSString::m_string being either 8-bit or 16-bit and add extra
code paths for the 8-bit cases.

Unfortunately, JSStringGetCharactersPtr is still expected to return a 16-bit character pointer.
Handle this by storing a separate 16-bit string and initializing it on demand when JSStringGetCharactersPtr
is called. This has the nice side effect of making JSStringGetCharactersPtr thread-safe when it wasn't before.
(In theory, someone could have a JSStringRef backed by an 8-bit string and call JSStringGetCharactersPtr on it
causing an unsafe upconversion to a 16-bit string).

  • API/JSStringRef.cpp:

(JSStringGetCharactersPtr):
Call OpaqueJSString::characters.

(JSStringGetUTF8CString):
Add a code path that handles 8-bit strings.

(JSStringIsEqual):
Call OpaqueJSString::equal.

  • API/JSStringRefCF.cpp:

(JSStringCreateWithCFString):
Reformat the code to use an early return instead of putting most of the code inside the body of an if statement.

(JSStringCopyCFString):
Create an 8-bit CFStringRef if possible.

  • API/OpaqueJSString.cpp:

(OpaqueJSString::create):
Use nullptr.

(OpaqueJSString::~OpaqueJSString):
Free m_characters.

(OpaqueJSString::characters):
Do the up-conversion and store the result in m_characters.

(OpaqueJSString::equal):
New helper function.

  • API/OpaqueJSString.h:

(OpaqueJSString::is8Bit):
New function that returns whether a string is 8-bit or not.

(OpaqueJSString::characters8):
(OpaqueJSString::characters16):
Add getters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/OpaqueJSString.h

    r161851 r162185  
    3636
    3737struct OpaqueJSString : public ThreadSafeRefCounted<OpaqueJSString> {
    38 
    39     static PassRefPtr<OpaqueJSString> create() // null
     38    static PassRefPtr<OpaqueJSString> create()
    4039    {
    4140        return adoptRef(new OpaqueJSString);
     
    5453    JS_EXPORT_PRIVATE static PassRefPtr<OpaqueJSString> create(const String&);
    5554
    56     const UChar* characters() { return deprecatedCharacters(); } // FIXME: Delete this.
    57     const UChar* deprecatedCharacters() { return this ? m_string.deprecatedCharacters() : nullptr; }
     55    ~OpaqueJSString();
     56
     57    bool is8Bit() { return this ? m_string.is8Bit() : false; }
     58    const LChar* characters8() { return this ? m_string.characters8() : nullptr; }
     59    const UChar* characters16() { return this ? m_string.characters16() : nullptr; }
    5860    unsigned length() { return this ? m_string.length() : 0; }
     61
     62    const UChar* characters();
    5963
    6064    JS_EXPORT_PRIVATE String string() const;
    6165    JSC::Identifier identifier(JSC::VM*) const;
     66
     67    static bool equal(const OpaqueJSString*, const OpaqueJSString*);
    6268
    6369private:
     
    7076    OpaqueJSString(const String& string)
    7177        : m_string(string.isolatedCopy())
     78        , m_characters(nullptr)
    7279    {
    7380    }
     
    7582    OpaqueJSString(const LChar* characters, unsigned length)
    7683        : m_string(characters, length)
     84        , m_characters(nullptr)
    7785    {
    7886    }
     
    8088    OpaqueJSString(const UChar* characters, unsigned length)
    8189        : m_string(characters, length)
     90        , m_characters(nullptr)
    8291    {
    8392    }
    8493
    8594    String m_string;
     95
     96    // This will be initialized on demand when characters() is called.
     97    std::atomic<UChar*> m_characters;
    8698};
    8799
Note: See TracChangeset for help on using the changeset viewer.