Unreviewed, rolling out r162185, r162186, and r162187.

http://trac.webkit.org/changeset/162185
http://trac.webkit.org/changeset/162186
http://trac.webkit.org/changeset/162187
https://bugs.webkit.org/show_bug.cgi?id=127164

Broke JSStringCreateWithCharactersNoCopy, as evidenced by a
JSC API test (Requested by ap on #webkit).

* API/JSStringRef.cpp:
(JSStringGetCharactersPtr):
(JSStringGetUTF8CString):
(JSStringIsEqual):
* API/JSStringRefCF.cpp:
(JSStringCreateWithCFString):
(JSStringCopyCFString):
* API/OpaqueJSString.cpp:
(OpaqueJSString::create):
(OpaqueJSString::identifier):
* API/OpaqueJSString.h:
(OpaqueJSString::create):
(OpaqueJSString::characters):
(OpaqueJSString::deprecatedCharacters):
(OpaqueJSString::OpaqueJSString):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@162192 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 65ed1aae
......@@ -83,7 +83,7 @@ size_t JSStringGetLength(JSStringRef string)
const JSChar* JSStringGetCharactersPtr(JSStringRef string)
{
return string->characters();
return string->deprecatedCharacters();
}
size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string)
......@@ -97,26 +97,20 @@ size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSiz
if (!bufferSize)
return 0;
char* destination = buffer;
ConversionResult result;
if (string->is8Bit()) {
const LChar* source = string->characters8();
result = convertLatin1ToUTF8(&source, source + string->length(), &destination, destination + bufferSize - 1);
} else {
const UChar* source = string->characters16();
result = convertUTF16ToUTF8(&source, source + string->length(), &destination, destination + bufferSize - 1, true);
}
*destination++ = '\0';
char* p = buffer;
const UChar* d = string->deprecatedCharacters();
ConversionResult result = convertUTF16ToUTF8(&d, d + string->length(), &p, p + bufferSize - 1, true);
*p++ = '\0';
if (result != conversionOK && result != targetExhausted)
return 0;
return destination - buffer;
return p - buffer;
}
bool JSStringIsEqual(JSStringRef a, JSStringRef b)
{
return OpaqueJSString::equal(a, b);
unsigned len = a->length();
return len == b->length() && 0 == memcmp(a->deprecatedCharacters(), b->deprecatedCharacters(), len * sizeof(UChar));
}
bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b)
......
......@@ -40,28 +40,26 @@ JSStringRef JSStringCreateWithCFString(CFStringRef string)
// We cannot use CFIndex here since CFStringGetLength can return values larger than
// it can hold. (<rdar://problem/6806478>)
size_t length = CFStringGetLength(string);
if (!length)
return OpaqueJSString::create(reinterpret_cast<const LChar*>(""), 0).leakRef();
if (length) {
Vector<LChar, 1024> lcharBuffer(length);
CFIndex usedBufferLength;
CFIndex convertedSize = CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingISOLatin1, 0, false, lcharBuffer.data(), length, &usedBufferLength);
if (static_cast<size_t>(convertedSize) == length && static_cast<size_t>(usedBufferLength) == length)
return OpaqueJSString::create(lcharBuffer.data(), length).leakRef();
Vector<LChar, 1024> lcharBuffer(length);
CFIndex usedBufferLength;
CFIndex convertedSize = CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingISOLatin1, 0, false, lcharBuffer.data(), length, &usedBufferLength);
if (static_cast<size_t>(convertedSize) == length && static_cast<size_t>(usedBufferLength) == length)
return OpaqueJSString::create(lcharBuffer.data(), length).leakRef();
auto buffer = std::make_unique<UniChar[]>(length);
CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get());
static_assert(sizeof(UniChar) == sizeof(UChar), "UniChar and UChar must be same size");
return OpaqueJSString::create(reinterpret_cast<UChar*>(buffer.get()), length).leakRef();
auto buffer = std::make_unique<UniChar[]>(length);
CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get());
COMPILE_ASSERT(sizeof(UniChar) == sizeof(UChar), unichar_and_uchar_must_be_same_size);
return OpaqueJSString::create(reinterpret_cast<UChar*>(buffer.get()), length).leakRef();
}
return OpaqueJSString::create(reinterpret_cast<const LChar*>(""), 0).leakRef();
}
CFStringRef JSStringCopyCFString(CFAllocatorRef allocator, JSStringRef string)
CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string)
{
if (!string->length())
return CFSTR("");
if (string->is8Bit())
return CFStringCreateWithBytes(allocator, reinterpret_cast<const UInt8*>(string->characters8()), string->length(), kCFStringEncodingISOLatin1, false);
return CFStringCreateWithCharacters(allocator, reinterpret_cast<const UniChar*>(string->characters16()), string->length());
return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(string->deprecatedCharacters()), string->length());
}
......@@ -36,15 +36,7 @@ PassRefPtr<OpaqueJSString> OpaqueJSString::create(const String& string)
{
if (!string.isNull())
return adoptRef(new OpaqueJSString(string));
return nullptr;
}
OpaqueJSString::~OpaqueJSString()
{
if (UChar* characters = m_characters) {
// m_characters is put in a local here to avoid an extra atomic load.
fastFree(static_cast<void*>(characters));
}
return 0;
}
String OpaqueJSString::string() const
......@@ -69,43 +61,3 @@ Identifier OpaqueJSString::identifier(VM* vm) const
return Identifier(vm, m_string.characters16(), m_string.length());
}
const UChar* OpaqueJSString::characters()
{
if (!this)
return nullptr;
// m_characters is put in a local here to avoid an extra atomic load.
UChar* characters = m_characters;
if (characters)
return characters;
unsigned length = m_string.length();
UChar* newCharacters = static_cast<UChar*>(fastMalloc(length * sizeof(UChar)));
if (m_string.is8Bit()) {
for (size_t i = 0; i < length; ++i)
newCharacters[i] = m_string.characters8()[i];
} else
memcpy(newCharacters, m_string.characters16(), length * sizeof(UChar));
if (!m_characters.compare_exchange_strong(characters, newCharacters)) {
fastFree(newCharacters);
return characters;
}
return newCharacters;
}
bool OpaqueJSString::equal(const OpaqueJSString* a, const OpaqueJSString* b)
{
if (a == b)
return true;
if (!a || !b)
return false;
return a->m_string == b->m_string;
}
......@@ -26,7 +26,6 @@
#ifndef OpaqueJSString_h
#define OpaqueJSString_h
#include <atomic>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/text/WTFString.h>
......@@ -36,7 +35,8 @@ namespace JSC {
}
struct OpaqueJSString : public ThreadSafeRefCounted<OpaqueJSString> {
static PassRefPtr<OpaqueJSString> create()
static PassRefPtr<OpaqueJSString> create() // null
{
return adoptRef(new OpaqueJSString);
}
......@@ -52,20 +52,14 @@ struct OpaqueJSString : public ThreadSafeRefCounted<OpaqueJSString> {
}
JS_EXPORT_PRIVATE static PassRefPtr<OpaqueJSString> create(const String&);
JS_EXPORT_PRIVATE ~OpaqueJSString();
bool is8Bit() { return this ? m_string.is8Bit() : false; }
const LChar* characters8() { return this ? m_string.characters8() : nullptr; }
const UChar* characters16() { return this ? m_string.characters16() : nullptr; }
const UChar* characters() { return deprecatedCharacters(); } // FIXME: Delete this.
const UChar* deprecatedCharacters() { return this ? m_string.deprecatedCharacters() : nullptr; }
unsigned length() { return this ? m_string.length() : 0; }
const UChar* characters();
JS_EXPORT_PRIVATE String string() const;
JSC::Identifier identifier(JSC::VM*) const;
static bool equal(const OpaqueJSString*, const OpaqueJSString*);
private:
friend class WTF::ThreadSafeRefCounted<OpaqueJSString>;
......@@ -75,26 +69,20 @@ private:
OpaqueJSString(const String& string)
: m_string(string.isolatedCopy())
, m_characters(nullptr)
{
}
OpaqueJSString(const LChar* characters, unsigned length)
: m_string(characters, length)
, m_characters(nullptr)
{
}
OpaqueJSString(const UChar* characters, unsigned length)
: m_string(characters, length)
, m_characters(nullptr)
{
}
String m_string;
// This will be initialized on demand when characters() is called.
std::atomic<UChar*> m_characters;
};
#endif
2014-01-17 Commit Queue <commit-queue@webkit.org>
Unreviewed, rolling out r162185, r162186, and r162187.
http://trac.webkit.org/changeset/162185
http://trac.webkit.org/changeset/162186
http://trac.webkit.org/changeset/162187
https://bugs.webkit.org/show_bug.cgi?id=127164
Broke JSStringCreateWithCharactersNoCopy, as evidenced by a
JSC API test (Requested by ap on #webkit).
* API/JSStringRef.cpp:
(JSStringGetCharactersPtr):
(JSStringGetUTF8CString):
(JSStringIsEqual):
* API/JSStringRefCF.cpp:
(JSStringCreateWithCFString):
(JSStringCopyCFString):
* API/OpaqueJSString.cpp:
(OpaqueJSString::create):
(OpaqueJSString::identifier):
* API/OpaqueJSString.h:
(OpaqueJSString::create):
(OpaqueJSString::characters):
(OpaqueJSString::deprecatedCharacters):
(OpaqueJSString::OpaqueJSString):
2014-01-16 Anders Carlsson <andersca@apple.com>
Export OpaqueJSString destructor.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment