Ignore:
Timestamp:
Jul 12, 2006, 1:12:08 AM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Implemented a vast number of renames and comment clarifications suggested during API review.


JSInternalString -> JSString
JS*Make -> JSValueMake*, JSObjectMake*
JSTypeCode -> JSType
JSValueIsInstanceOf -> JSValueIsInstanceOfConstructor (reads strangely well in client code)
JSGC*Protect -> JSValue*Protect
JS*Callback -> JSObject*Callback
JSGetPropertyListCallback -> JSObjectAddPropertiesToListCallback
JSPropertyEnumeratorGetNext -> JSPropertyEnumeratorGetNextName
JSString* ->

JSStringCreateWithUTF8CString, JSStringGetUTF8CString,
JSStringGetMaximumUTF8CStringSize JSStringIsEqualToUTF8CString,
JSStringCreateWithCFString, JSStringCopyCFString, JSStringCreateWithCharacters.


  • Changed functions taking a JSValue out arg and returning a bool indicating whether it was set to simply return a JSValue or NULL.


  • Removed JSStringGetCharacters because it's more documentation than code, and it's just a glorified memcpy built on existing API functionality.


  • Moved standard library includes into the headers that actually require them.


  • Standardized use of the phrase "Create Rule."


  • Removed JSLock from make functions that don't allocate.


  • Added exception handling to JSValueToBoolean, since we now allow callback objects to throw exceptions upon converting to boolean.


  • Renamed JSGCCollect to JSGarbageCollect.
File:
1 edited

Legend:

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

    r15317 r15376  
    6060   
    6161    do {
    62         if (JSInitializeCallback initialize = jsClass->callbacks.initialize)
     62        if (JSObjectInitializeCallback initialize = jsClass->callbacks.initialize)
    6363            initialize(context, thisRef, toRef(exec->exceptionSlot()));
    6464    } while ((jsClass = jsClass->parent));
     
    7070   
    7171    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
    72         if (JSFinalizeCallback finalize = jsClass->callbacks.finalize)
     72        if (JSObjectFinalizeCallback finalize = jsClass->callbacks.finalize)
    7373            finalize(thisRef);
    7474   
     
    8585    JSContextRef context = toRef(exec);
    8686    JSObjectRef thisRef = toRef(this);
    87     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     87    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    8888
    8989    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    9090        // optional optimization to bypass getProperty in cases when we only need to know if the property exists
    91         if (JSHasPropertyCallback hasPropertyCallback = jsClass->callbacks.hasProperty) {
    92             if (hasPropertyCallback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
     91        if (JSObjectHasPropertyCallback hasProperty = jsClass->callbacks.hasProperty) {
     92            if (hasProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
    9393                slot.setCustom(this, callbackGetter);
    9494                return true;
    9595            }
    96         } else if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) {
    97             JSValueRef returnValue;
    98             if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot()))) {
     96        } else if (JSObjectGetPropertyCallback getProperty = jsClass->callbacks.getProperty) {
     97            if (JSValueRef value = getProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
    9998                // cache the value so we don't have to compute it again
    10099                // FIXME: This violates the PropertySlot design a little bit.
    101100                // We should either use this optimization everywhere, or nowhere.
    102                 slot.setCustom(reinterpret_cast<JSObject*>(toJS(returnValue)), cachedValueGetter);
     101                slot.setCustom(reinterpret_cast<JSObject*>(toJS(value)), cachedValueGetter);
    103102                return true;
    104103            }
     
    134133    JSContextRef context = toRef(exec);
    135134    JSObjectRef thisRef = toRef(this);
    136     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     135    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    137136    JSValueRef valueRef = toRef(value);
    138137
    139138    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    140         if (JSSetPropertyCallback setPropertyCallback = jsClass->callbacks.setProperty) {
    141             if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
     139        if (JSObjectSetPropertyCallback setProperty = jsClass->callbacks.setProperty) {
     140            if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    142141                return;
    143142        }
     
    147146                if (entry->attributes & kJSPropertyAttributeReadOnly)
    148147                    return;
    149                 if (JSSetPropertyCallback setPropertyCallback = entry->setProperty) {
    150                     if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
     148                if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
     149                    if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    151150                        return;
    152151                }
     
    163162        }
    164163    }
     164
    165165    return JSObject::put(exec, propertyName, value, attr);
    166166}
     
    175175    JSContextRef context = toRef(exec);
    176176    JSObjectRef thisRef = toRef(this);
    177     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    178    
    179     for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    180         if (JSDeletePropertyCallback deletePropertyCallback = jsClass->callbacks.deleteProperty) {
    181             if (deletePropertyCallback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     177    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     178   
     179    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
     180        if (JSObjectDeletePropertyCallback deleteProperty = jsClass->callbacks.deleteProperty) {
     181            if (deleteProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
    182182                return true;
    183183        }
     
    199199        }
    200200    }
     201
    201202    return JSObject::deleteProperty(exec, propertyName);
    202203}
     
    222223   
    223224    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    224         if (JSCallAsConstructorCallback callAsConstructorCallback = jsClass->callbacks.callAsConstructor) {
     225        if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callbacks.callAsConstructor) {
    225226            size_t argc = args.size();
    226227            JSValueRef argv[argc];
    227228            for (size_t i = 0; i < argc; i++)
    228229                argv[i] = toRef(args[i]);
    229             return toJS(callAsConstructorCallback(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot())));
     230            return toJS(callAsConstructor(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot())));
    230231        }
    231232    }
     
    251252
    252253    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    253         if (JSCallAsFunctionCallback callAsFunctionCallback = jsClass->callbacks.callAsFunction) {
     254        if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callbacks.callAsFunction) {
    254255            size_t argc = args.size();
    255256            JSValueRef argv[argc];
    256257            for (size_t i = 0; i < argc; i++)
    257258                argv[i] = toRef(args[i]);
    258             return toJS(callAsFunctionCallback(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot())));
     259            return toJS(callAsFunction(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot())));
    259260        }
    260261    }
     
    270271
    271272    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    272         if (JSGetPropertyListCallback getPropertyListCallback = jsClass->callbacks.getPropertyList)
    273             getPropertyListCallback(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot()));
     273        if (JSObjectAddPropertiesToListCallback addPropertiesToList = jsClass->callbacks.addPropertiesToList)
     274            addPropertiesToList(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot()));
    274275
    275276        if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
     
    304305    JSObjectRef thisRef = toRef(this);
    305306
    306     for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    307         if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    308             JSValueRef returnValue;
    309             if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue, toRef(exec->exceptionSlot())))
    310                 return toJS(returnValue)->getBoolean();
    311         }
    312     }
     307    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
     308        if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
     309            if (JSValueRef value = convertToType(context, thisRef, kJSTypeBoolean, toRef(exec->exceptionSlot())))
     310                return toJS(value)->getBoolean();
     311
    313312    return JSObject::toBoolean(exec);
    314313}
     
    319318    JSObjectRef thisRef = toRef(this);
    320319
    321     for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    322         if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    323             JSValueRef returnValue;
    324             if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue, toRef(exec->exceptionSlot())))
    325                 return toJS(returnValue)->getNumber();
    326         }
    327     }
     320    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
     321        if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
     322            if (JSValueRef value = convertToType(context, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
     323                return toJS(value)->getNumber();
     324
    328325    return JSObject::toNumber(exec);
    329326}
     
    334331    JSObjectRef thisRef = toRef(this);
    335332
    336     for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    337         if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    338             JSValueRef returnValue;
    339             if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue, toRef(exec->exceptionSlot())))
    340                 return toJS(returnValue)->getString();
    341         }
    342     }
     333    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
     334        if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
     335            if (JSValueRef value = convertToType(context, thisRef, kJSTypeString, toRef(exec->exceptionSlot())))
     336                return toJS(value)->getString();
     337
    343338    return JSObject::toString(exec);
    344339}
     
    359354        if (jsClass == c)
    360355            return true;
     356
    361357    return false;
    362358}
     
    375371
    376372    JSObjectRef thisRef = toRef(thisObj);
    377     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    378 
    379     for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) {
    380         JSValueRef returnValue;
    381        
     373    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     374
     375    for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent)
    382376        if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues)
    383377            if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
    384                 if (JSGetPropertyCallback getPropertyCallback = entry->getProperty)
    385                     if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot())))
    386                         return toJS(returnValue);
    387     }
     378                if (JSObjectGetPropertyCallback getProperty = entry->getProperty)
     379                    if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     380                        return toJS(value);
    388381
    389382    return jsUndefined();
     
    401394        if (__JSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
    402395            if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
    403                 JSValue* v = toJS(JSFunctionMake(toRef(exec), entry->callAsFunction));
     396                JSValue* v = toJS(JSObjectMakeFunction(toRef(exec), entry->callAsFunction));
    404397                thisObj->putDirect(propertyName, v, entry->attributes);
    405398                return v;
     
    417410
    418411    JSObjectRef thisRef = toRef(thisObj);
    419     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    420 
    421     for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) {
    422         JSValueRef returnValue;
    423 
    424         if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty)
    425             if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot())))
    426                 return toJS(returnValue);
    427     }
     412    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     413
     414    for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent)
     415        if (JSObjectGetPropertyCallback getProperty = jsClass->callbacks.getProperty)
     416            if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     417                return toJS(value);
    428418
    429419    return jsUndefined();
Note: See TracChangeset for help on using the changeset viewer.