Ignore:
Timestamp:
Jul 16, 2006, 6:48:27 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Properly document and handle NULL callbacks for static properties. We throw an exception in any case other than a ReadOnly property with a NULL setProperty callback, because a NULL callback almost certainly indicates a programming error. Also throw an exception if hasProperty returns true for a property that getProperty can't get.


  • If a static setProperty callback returns 'false', to indicate that the property was not set, we no longer forward the set request up the class chain, because that's almost certainly not what the programmer expected.
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::getOwnPropertySlot): (KJS::JSCallbackObject::put): (KJS::JSCallbackObject::staticValueGetter): (KJS::JSCallbackObject::staticFunctionGetter): (KJS::JSCallbackObject::callbackGetter):
  • API/JSObjectRef.h:
  • API/minidom.js:
  • API/testapi.c: (MyObject_hasProperty):
  • API/testapi.js:
File:
1 edited

Legend:

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

    r15469 r15473  
    108108
    109109        if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
    110             if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
    111                 if (entry->getProperty) {
    112                     slot.setCustom(this, staticValueGetter);
    113                     return true;
    114                 }
     110            if (staticValues->contains(propertyName.ustring().rep())) {
     111                slot.setCustom(this, staticValueGetter);
     112                return true;
    115113            }
    116114        }
     
    149147                if (entry->attributes & kJSPropertyAttributeReadOnly)
    150148                    return;
    151                 if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
    152                     if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    153                         return;
    154                 }
     149                if (JSObjectSetPropertyCallback setProperty = entry->setProperty)
     150                    setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()));
     151                else
     152                    throwError(exec, ReferenceError, "Writable static value property defined with NULL setProperty callback.");
    155153            }
    156154        }
     
    393391                        return toJS(value);
    394392
    395     return jsUndefined();
     393    return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback.");
    396394}
    397395
     
    407405        if (__JSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
    408406            if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
    409                 JSObject* o = new JSCallbackFunction(exec, entry->callAsFunction, propertyName);
    410                 thisObj->putDirect(propertyName, o, entry->attributes);
    411                 return o;
    412             }
    413         }
    414     }
    415 
    416     return jsUndefined();
     407                if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
     408                    JSObject* o = new JSCallbackFunction(exec, callAsFunction, propertyName);
     409                    thisObj->putDirect(propertyName, o, entry->attributes);
     410                    return o;
     411                }
     412            }
     413        }
     414    }
     415
     416    return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback.");
    417417}
    418418
     
    430430                return toJS(value);
    431431
    432     return jsUndefined();
     432    return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");
    433433}
    434434
Note: See TracChangeset for help on using the changeset viewer.