]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - API/JSStringRefCF.cpp
JavaScriptCore-1218.tar.gz
[apple/javascriptcore.git] / API / JSStringRefCF.cpp
index 0877a13e60b2786680b6d9cd8537c591e0b2ef58..64d2d62512f7b376f6b858c7f6765452926f68db 100644 (file)
@@ -30,8 +30,7 @@
 #include "InitializeThreading.h"
 #include "JSStringRef.h"
 #include "OpaqueJSString.h"
-#include <runtime/UString.h>
-#include <runtime/JSValue.h>
+#include <runtime/JSCJSValue.h>
 #include <wtf/OwnArrayPtr.h>
 
 JSStringRef JSStringCreateWithCFString(CFStringRef string)
@@ -42,13 +41,19 @@ JSStringRef JSStringCreateWithCFString(CFStringRef string)
     // 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);
         return OpaqueJSString::create(reinterpret_cast<UChar*>(buffer.get()), length).leakRef();
-    } else {
-        return OpaqueJSString::create(0, 0).leakRef();
     }
+    
+    return OpaqueJSString::create(reinterpret_cast<const LChar*>(""), 0).leakRef();
 }
 
 CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string)