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/JSObjectRef.cpp

    r35478 r35775  
    3737#include "JSGlobalObject.h"
    3838#include "JSObject.h"
     39#include "JSRetainPtr.h"
    3940#include "JSString.h"
    4041#include "JSValueRef.h"
     
    8687    exec->globalData().heap->registerThread();
    8788
    88     Identifier nameID = name ? Identifier(exec, toJS(name)) : Identifier(exec, "anonymous");
     89    Identifier nameID = name ? name->identifier(exec) : Identifier(exec, "anonymous");
    8990   
    9091    return toRef(new (exec) JSCallbackFunction(exec, callAsFunction, nameID));
     
    110111    exec->globalData().heap->registerThread();
    111112
    112     UString::Rep* bodyRep = toJS(body);
    113     UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
    114    
    115     Identifier nameID = name ? Identifier(exec, toJS(name)) : Identifier(exec, "anonymous");
     113    Identifier nameID = name ? name->identifier(exec) : Identifier(exec, "anonymous");
    116114   
    117115    ArgList args;
    118116    for (unsigned i = 0; i < parameterCount; i++)
    119         args.append(jsString(exec, UString(toJS(parameterNames[i]))));
    120     args.append(jsString(exec, UString(bodyRep)));
    121 
    122     JSObject* result = constructFunction(exec, args, nameID, UString(sourceURLRep), startingLineNumber);
     117        args.append(jsString(exec, UString(parameterNames[i]->ustring())));
     118    args.append(jsString(exec, body->ustring()));
     119
     120    JSObject* result = constructFunction(exec, args, nameID, sourceURL->ustring(), startingLineNumber);
    123121    if (exec->hadException()) {
    124122        if (exception)
     
    150148
    151149    JSObject* jsObject = toJS(object);
    152     UString::Rep* nameRep = toJS(propertyName);
    153    
    154     return jsObject->hasProperty(exec, Identifier(exec, nameRep));
     150   
     151    return jsObject->hasProperty(exec, propertyName->identifier(exec));
    155152}
    156153
     
    161158
    162159    JSObject* jsObject = toJS(object);
    163     UString::Rep* nameRep = toJS(propertyName);
    164 
    165     JSValue* jsValue = jsObject->get(exec, Identifier(exec, nameRep));
     160
     161    JSValue* jsValue = jsObject->get(exec, propertyName->identifier(exec));
    166162    if (exec->hadException()) {
    167163        if (exception)
     
    178174
    179175    JSObject* jsObject = toJS(object);
    180     Identifier name(exec, toJS(propertyName));
     176    Identifier name(propertyName->identifier(exec));
    181177    JSValue* jsValue = toJS(value);
    182178
     
    232228
    233229    JSObject* jsObject = toJS(object);
    234     UString::Rep* nameRep = toJS(propertyName);
    235 
    236     bool result = jsObject->deleteProperty(exec, Identifier(exec, nameRep));
     230
     231    bool result = jsObject->deleteProperty(exec,  propertyName->identifier(exec));
    237232    if (exec->hadException()) {
    238233        if (exception)
     
    338333}
    339334
    340 struct OpaqueJSPropertyNameArray
    341 {
    342     OpaqueJSPropertyNameArray(JSGlobalData* globalData) : refCount(0), array(globalData)
     335struct OpaqueJSPropertyNameArray {
     336    OpaqueJSPropertyNameArray(JSGlobalData* globalData)
     337        : refCount(0)
     338        , globalData(globalData)
    343339    {
    344340    }
    345341   
    346342    unsigned refCount;
    347     PropertyNameArray array;
     343    JSGlobalData* globalData;
     344    Vector<JSRetainPtr<JSStringRef> > array;
    348345};
    349346
     
    354351    exec->globalData().heap->registerThread();
    355352
    356     JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(&exec->globalData());
    357     jsObject->getPropertyNames(exec, propertyNames->array);
     353    JSGlobalData* globalData = &exec->globalData();
     354
     355    JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(globalData);
     356    PropertyNameArray array(globalData);
     357    jsObject->getPropertyNames(exec, array);
     358
     359    size_t size = array.size();
     360    propertyNames->array.reserveCapacity(size);
     361    for (size_t i = 0; i < size; ++i)
     362        propertyNames->array.append(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].ustring()).releaseRef()));
    358363   
    359364    return JSPropertyNameArrayRetain(propertyNames);
     
    379384JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index)
    380385{
    381     return toRef(array->array[static_cast<unsigned>(index)].ustring().rep());
     386    return array->array[static_cast<unsigned>(index)].get();
    382387}
    383388
     
    385390{
    386391    PropertyNameArray* propertyNames = toJS(array);
    387     UString::Rep* rep = toJS(propertyName);
    388392
    389393    propertyNames->globalData()->heap->registerThread();
    390394
    391     propertyNames->add(Identifier(propertyNames->globalData(), rep));
    392 }
     395    propertyNames->add(propertyName->identifier(propertyNames->globalData()));
     396}
Note: See TracChangeset for help on using the changeset viewer.