Ignore:
Timestamp:
Jul 15, 2006, 6:28:25 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.

  • Moved the arguments passed to JSClassCreate into a single structure, called JSClassDefinition. This will enable easier structure migration/versioning in the future, if necessary.


  • Added support for class names.


  • kJSClassDefinitionNull replaces kJSObjectCallbacksNone.


  • JSClass is becoming a fairly complex struct, so I migrated all of its implementation other than reference counting to the sruct.


  • Also moved JSClass* functions in the API to JSObjectRef.cpp, since they're declared in JSObjectRef.h


  • Also added some more informative explanation to the class structure doc.
File:
1 edited

Legend:

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

    r15384 r15462  
    3131using namespace KJS;
    3232
    33 const JSObjectCallbacks kJSObjectCallbacksNone = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
     33const JSClassDefinition kJSClassDefinitionNull = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    3434
    35 JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass)
     35__JSClass::__JSClass(JSClassDefinition* definition)
     36    : refCount(0)
     37    , className(definition->className)
     38    , parentClass(definition->parentClass)
     39    , staticValues(0)
     40    , staticFunctions(0)
     41    , initialize(definition->initialize)
     42    , finalize(definition->finalize)
     43    , hasProperty(definition->hasProperty)
     44    , getProperty(definition->getProperty)
     45    , setProperty(definition->setProperty)
     46    , deleteProperty(definition->deleteProperty)
     47    , addPropertiesToList(definition->addPropertiesToList)
     48    , callAsFunction(definition->callAsFunction)
     49    , callAsConstructor(definition->callAsConstructor)
     50    , hasInstance(definition->hasInstance)
     51    , convertToType(definition->convertToType)
    3652{
    37     JSClassRef jsClass = new __JSClass;
    38     if (staticValues) {
    39         jsClass->staticValues = new __JSClass::StaticValuesTable();
    40         while (staticValues->name) {
    41             jsClass->staticValues->add(Identifier(staticValues->name).ustring().rep(),
    42                                        new StaticValueEntry(staticValues->getProperty, staticValues->setProperty, staticValues->attributes));
    43             ++staticValues;
     53    if (JSStaticValue* staticValue = definition->staticValues) {
     54        staticValues = new StaticValuesTable();
     55        while (staticValue->name) {
     56            staticValues->add(Identifier(staticValue->name).ustring().rep(),
     57                              new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes));
     58            ++staticValue;
    4459        }
    4560    }
    4661   
    47     if (staticFunctions) {
    48         jsClass->staticFunctions = new __JSClass::StaticFunctionsTable();
    49         while (staticFunctions->name) {
    50             jsClass->staticFunctions->add(Identifier(staticFunctions->name).ustring().rep(),
    51                                           new StaticFunctionEntry(staticFunctions->callAsFunction, staticFunctions->attributes));
    52             ++staticFunctions;
     62    if (JSStaticFunction* staticFunction = definition->staticFunctions) {
     63        staticFunctions = new StaticFunctionsTable();
     64        while (staticFunction->name) {
     65            staticFunctions->add(Identifier(staticFunction->name).ustring().rep(),
     66                                 new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes));
     67            ++staticFunction;
    5368        }
    5469    }
    55    
    56     if (callbacks)
    57         jsClass->callbacks = *callbacks;
    58     else
    59         jsClass->callbacks = kJSObjectCallbacksNone;
    60    
    61     jsClass->parent = parentClass;
    62    
    63     return JSClassRetain(jsClass);
    6470}
    6571
    66 JSClassRef JSClassRetain(JSClassRef jsClass)
     72__JSClass::~__JSClass()
    6773{
    68     ++jsClass->refCount;
    69     return jsClass;
    70 }
     74    if (staticValues) {
     75        deleteAllValues(*staticValues);
     76        delete staticValues;
     77    }
    7178
    72 void JSClassRelease(JSClassRef jsClass)
    73 {
    74     if (--jsClass->refCount == 0) {
    75         if (jsClass->staticValues) {
    76             deleteAllValues(*jsClass->staticValues);
    77             delete jsClass->staticValues;
    78         }
    79 
    80         if (jsClass->staticFunctions) {
    81             deleteAllValues(*jsClass->staticFunctions);
    82             delete jsClass->staticFunctions;
    83         }
    84 
    85         delete jsClass;
     79    if (staticFunctions) {
     80        deleteAllValues(*staticFunctions);
     81        delete staticFunctions;
    8682    }
    8783}
Note: See TracChangeset for help on using the changeset viewer.