Ignore:
Timestamp:
Jul 10, 2006, 5:26:25 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Darin.


Added exception out parameter to API object callbacks, removed semi-bogus
JSContext(.*)Exception functions.


To make these calls syntactically simple, I added an exceptionSlot()
method to the ExecState class, which provides a JSValue slot in which to
store a JSValue* exception.

  • API/APICast.h: (toRef):
  • API/JSCallbackConstructor.cpp: (KJS::JSCallbackConstructor::construct):
  • API/JSCallbackFunction.cpp: (KJS::JSCallbackFunction::callAsFunction):
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::init): (KJS::JSCallbackObject::getOwnPropertySlot): (KJS::JSCallbackObject::put): (KJS::JSCallbackObject::deleteProperty): (KJS::JSCallbackObject::construct): (KJS::JSCallbackObject::callAsFunction): (KJS::JSCallbackObject::getPropertyList): (KJS::JSCallbackObject::toBoolean): (KJS::JSCallbackObject::toNumber): (KJS::JSCallbackObject::toString): (KJS::JSCallbackObject::staticValueGetter): (KJS::JSCallbackObject::callbackGetter):
  • API/JSContextRef.cpp: (JSCheckSyntax):
  • API/JSContextRef.h:
  • API/JSNode.c: (JSNodePrototype_appendChild): (JSNodePrototype_removeChild): (JSNodePrototype_replaceChild): (JSNode_getNodeType): (JSNode_getChildNodes): (JSNode_getFirstChild): (JSNode_construct):
  • API/JSNode.h:
  • API/JSNodeList.c: (JSNodeListPrototype_item): (JSNodeList_length): (JSNodeList_getProperty):
  • API/JSObjectRef.h:
  • API/minidom.c: (print):
  • API/testapi.c: (MyObject_initialize): (MyObject_hasProperty): (MyObject_getProperty): (MyObject_setProperty): (MyObject_deleteProperty): (MyObject_getPropertyList): (MyObject_callAsFunction): (MyObject_callAsConstructor): (MyObject_convertToType): (print_callAsFunction): (myConstructor_callAsConstructor): (main):
  • JavaScriptCore.exp:
  • kjs/ExecState.h: (KJS::ExecState::exceptionHandle):
File:
1 edited

Legend:

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

    r15310 r15317  
    5252void JSCallbackObject::init(JSContextRef context, JSClassRef jsClass)
    5353{
     54    ExecState* exec = toJS(context);
     55   
    5456    m_privateData = 0;
    5557    m_class = JSClassRetain(jsClass);
     
    5961    do {
    6062        if (JSInitializeCallback initialize = jsClass->callbacks.initialize)
    61             initialize(context, thisRef);
     63            initialize(context, thisRef, toRef(exec->exceptionSlot()));
    6264    } while ((jsClass = jsClass->parent));
    6365}
     
    8486    JSObjectRef thisRef = toRef(this);
    8587    JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    86    
     88
    8789    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    8890        // optional optimization to bypass getProperty in cases when we only need to know if the property exists
    8991        if (JSHasPropertyCallback hasPropertyCallback = jsClass->callbacks.hasProperty) {
    90             if (hasPropertyCallback(context, thisRef, propertyNameRef)) {
     92            if (hasPropertyCallback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
    9193                slot.setCustom(this, callbackGetter);
    9294                return true;
     
    9496        } else if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) {
    9597            JSValueRef returnValue;
    96             if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue)) {
     98            if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot()))) {
    9799                // cache the value so we don't have to compute it again
    98100                // FIXME: This violates the PropertySlot design a little bit.
     
    137139    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    138140        if (JSSetPropertyCallback setPropertyCallback = jsClass->callbacks.setProperty) {
    139             if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef))
     141            if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    140142                return;
    141143        }
     
    146148                    return;
    147149                if (JSSetPropertyCallback setPropertyCallback = entry->setProperty) {
    148                     if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef))
     150                    if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    149151                        return;
    150152                }
     
    177179    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    178180        if (JSDeletePropertyCallback deletePropertyCallback = jsClass->callbacks.deleteProperty) {
    179             if (deletePropertyCallback(context, thisRef, propertyNameRef))
     181            if (deletePropertyCallback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
    180182                return true;
    181183        }
     
    225227            for (size_t i = 0; i < argc; i++)
    226228                argv[i] = toRef(args[i]);
    227             return toJS(callAsConstructorCallback(execRef, thisRef, argc, argv));
     229            return toJS(callAsConstructorCallback(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot())));
    228230        }
    229231    }
     
    254256            for (size_t i = 0; i < argc; i++)
    255257                argv[i] = toRef(args[i]);
    256             return toJS(callAsFunctionCallback(execRef, thisRef, thisObjRef, argc, argv));
     258            return toJS(callAsFunctionCallback(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot())));
    257259        }
    258260    }
     
    269271    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    270272        if (JSGetPropertyListCallback getPropertyListCallback = jsClass->callbacks.getPropertyList)
    271             getPropertyListCallback(context, thisRef, toRef(&propertyList));
     273            getPropertyListCallback(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot()));
    272274
    273275        if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
     
    305307        if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    306308            JSValueRef returnValue;
    307             if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue))
     309            if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue, toRef(exec->exceptionSlot())))
    308310                return toJS(returnValue)->getBoolean();
    309311        }
     
    320322        if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    321323            JSValueRef returnValue;
    322             if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue))
     324            if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue, toRef(exec->exceptionSlot())))
    323325                return toJS(returnValue)->getNumber();
    324326        }
     
    335337        if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    336338            JSValueRef returnValue;
    337             if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue))
     339            if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue, toRef(exec->exceptionSlot())))
    338340                return toJS(returnValue)->getString();
    339341        }
     
    381383            if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
    382384                if (JSGetPropertyCallback getPropertyCallback = entry->getProperty)
    383                     if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue))
     385                    if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot())))
    384386                        return toJS(returnValue);
    385387    }
     
    421423
    422424        if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty)
    423             if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue))
     425            if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot())))
    424426                return toJS(returnValue);
    425427    }
Note: See TracChangeset for help on using the changeset viewer.