Title: [133672] trunk/Source/_javascript_Core
Revision
133672
Author
msab...@apple.com
Date
2012-11-06 14:16:36 -0800 (Tue, 06 Nov 2012)

Log Message

JSStringCreateWithCFString() Should create an 8 bit String if possible
https://bugs.webkit.org/show_bug.cgi?id=101104

Reviewed by Darin Adler.

Try converting the CFString to an 8 bit string using CFStringGetBytes(...,
kCFStringEncodingISOLatin1, ...) and return the 8 bit string if successful.
If not proceed with 16 bit conversion.

* API/JSStringRefCF.cpp:
(JSStringCreateWithCFString):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSStringRefCF.cpp (133671 => 133672)


--- trunk/Source/_javascript_Core/API/JSStringRefCF.cpp	2012-11-06 22:12:14 UTC (rev 133671)
+++ trunk/Source/_javascript_Core/API/JSStringRefCF.cpp	2012-11-06 22:16:36 UTC (rev 133672)
@@ -41,6 +41,12 @@
     // it can hold.  (<rdar://problem/6806478>)
     size_t length = CFStringGetLength(string);
     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();
+
         OwnArrayPtr<UniChar> buffer = adoptArrayPtr(new UniChar[length]);
         CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get());
         COMPILE_ASSERT(sizeof(UniChar) == sizeof(UChar), unichar_and_uchar_must_be_same_size);

Modified: trunk/Source/_javascript_Core/ChangeLog (133671 => 133672)


--- trunk/Source/_javascript_Core/ChangeLog	2012-11-06 22:12:14 UTC (rev 133671)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-11-06 22:16:36 UTC (rev 133672)
@@ -1,3 +1,17 @@
+2012-11-06  Michael Saboff  <msab...@apple.com>
+
+        JSStringCreateWithCFString() Should create an 8 bit String if possible
+        https://bugs.webkit.org/show_bug.cgi?id=101104
+
+        Reviewed by Darin Adler.
+
+        Try converting the CFString to an 8 bit string using CFStringGetBytes(...,
+        kCFStringEncodingISOLatin1, ...) and return the 8 bit string if successful.
+        If not proceed with 16 bit conversion.
+
+        * API/JSStringRefCF.cpp:
+        (JSStringCreateWithCFString):
+
 2012-11-06  Oliver Hunt  <oli...@apple.com>
 
         Reduce direct m_symbolTable usage in CodeBlock
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to