Ignore:
Timestamp:
Aug 15, 2008, 12:43:48 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoff Garen.

JSStringRef is created context-free, but can get linked to one via an identifier table,
breaking an implicit API contract.

Made JSStringRef point to OpaqueJSString, which is a new string object separate from UString.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSStringRefCF.cpp

    r35227 r35775  
    3030#include "APICast.h"
    3131#include "JSStringRef.h"
     32#include "OpaqueJSString.h"
    3233#include <kjs/ustring.h>
    3334#include <kjs/JSValue.h>
    34 
    35 using namespace KJS;
     35#include <wtf/OwnArrayPtr.h>
    3636
    3737JSStringRef JSStringCreateWithCFString(CFStringRef string)
    3838{
    3939    CFIndex length = CFStringGetLength(string);
    40     UString::Rep* rep;
    41     if (!length)
    42         rep = UString("").rep()->ref();
    43     else {
    44         UniChar* buffer = static_cast<UniChar*>(fastMalloc(sizeof(UniChar) * length));
    45         CFStringGetCharacters(string, CFRangeMake(0, length), buffer);
     40    if (length) {
     41        OwnArrayPtr<UniChar> buffer(new UniChar[length]);
     42        CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get());
    4643        COMPILE_ASSERT(sizeof(UniChar) == sizeof(UChar), unichar_and_uchar_must_be_same_size);
    47         rep = UString(reinterpret_cast<UChar*>(buffer), length, false).rep()->ref();
     44        return OpaqueJSString::create(buffer.get(), length).releaseRef();
     45    } else {
     46        return OpaqueJSString::create(0, 0).releaseRef();
    4847    }
    49     return toRef(rep);
    50 }
     48    }
    5149
    5250CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string)
    5351{
    54     UString::Rep* rep = toJS(string);
    55     return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(rep->data()), rep->size());
     52    return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(string->characters()), string->length());
    5653}
Note: See TracChangeset for help on using the changeset viewer.