Changeset 102065 in webkit for trunk/Source/JavaScriptCore/API


Ignore:
Timestamp:
Dec 5, 2011, 4:17:34 PM (14 years ago)
Author:
Darin Adler
Message:

Convert JSClassRef to use HashMap<OwnPtr>
https://bugs.webkit.org/show_bug.cgi?id=73780

Reviewed by Andreas Kling.

  • API/JSCallbackObjectFunctions.h:

(JSC::JSCallbackObject::getOwnPropertyNames): Use get() on the hash map
entries because the hash map now has an OwnPtr instead of a raw pointer.

  • API/JSClassRef.cpp:

(OpaqueJSClass::OpaqueJSClass): No need to initialize m_staticValues and
m_staticFunctions since they are now OwnPtr. Use adoptPtr when allocating.
Removed the code that gets and deletes existing entries, and just use set,
which now handles deletion automatically due to it being OwnPtr.
(OpaqueJSClass::~OpaqueJSClass): Replaced code to do all the deletion
with assertion-only NDEBUG-only code.
(OpaqueJSClassContextData::OpaqueJSClassContextData): Use adoptPtr when
allocating. Use OwnPtr when adding. Removed unneeded code to set
staticValues and staticFunctions to 0. Removed unneeded destructor.
(OpaqueJSClass::staticValues): Added get call. Also removed unneeded local.
(OpaqueJSClass::staticFunctions): Ditto.
(OpaqueJSClass::prototype): Added use of adoptPtr.

  • API/JSClassRef.h: Made the static values and static functions tables

use OwnPtr for the entries. Also used OwnPtr for the pointers to the
tables themselves. Also removed ~OpaqueJSClassContextData(), letting
the compiler generate it.

Location:
trunk/Source/JavaScriptCore/API
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r100006 r102065  
    440440            for (iterator it = staticValues->begin(); it != end; ++it) {
    441441                StringImpl* name = it->first.get();
    442                 StaticValueEntry* entry = it->second;
     442                StaticValueEntry* entry = it->second.get();
    443443                if (entry->getProperty && (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties)))
    444444                    propertyNames.add(Identifier(exec, name));
     
    451451            for (iterator it = staticFunctions->begin(); it != end; ++it) {
    452452                StringImpl* name = it->first.get();
    453                 StaticFunctionEntry* entry = it->second;
     453                StaticFunctionEntry* entry = it->second.get();
    454454                if (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties))
    455455                    propertyNames.add(Identifier(exec, name));
  • trunk/Source/JavaScriptCore/API/JSClassRef.cpp

    r101945 r102065  
    7272    , convertToType(definition->convertToType)
    7373    , m_className(tryCreateStringFromUTF8(definition->className))
    74     , m_staticValues(0)
    75     , m_staticFunctions(0)
    7674{
    7775    initializeThreading();
    7876
    7977    if (const JSStaticValue* staticValue = definition->staticValues) {
    80         m_staticValues = new OpaqueJSClassStaticValuesTable();
     78        m_staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable);
    8179        while (staticValue->name) {
    8280            UString valueName = tryCreateStringFromUTF8(staticValue->name);
    8381            if (!valueName.isNull()) {
    8482                // Use a local variable here to sidestep an RVCT compiler bug.
    85                 StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes);
    86                 StringImpl* impl = valueName.impl();
    87                 StaticValueEntry* existingEntry = m_staticValues->get(impl);
    88                 m_staticValues->set(impl, entry);
    89                 delete existingEntry;
     83                OwnPtr<StaticValueEntry> entry = adoptPtr(new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes));
     84                m_staticValues->set(valueName.impl(), entry.release());
    9085            }
    9186            ++staticValue;
     
    9489
    9590    if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
    96         m_staticFunctions = new OpaqueJSClassStaticFunctionsTable();
     91        m_staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
    9792        while (staticFunction->name) {
    9893            UString functionName = tryCreateStringFromUTF8(staticFunction->name);
    9994            if (!functionName.isNull()) {
    10095                // Use a local variable here to sidestep an RVCT compiler bug.
    101                 StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes);
    102                 StringImpl* impl = functionName.impl();
    103                 StaticFunctionEntry* existingEntry = m_staticFunctions->get(impl);
    104                 m_staticFunctions->set(impl, entry);
    105                 delete existingEntry;
     96                OwnPtr<StaticFunctionEntry> entry = adoptPtr(new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes));
     97                m_staticFunctions->set(functionName.impl(), entry.release());
    10698            }
    10799            ++staticFunction;
     
    118110    ASSERT(!m_className.length() || !m_className.impl()->isIdentifier());
    119111
     112#ifndef NDEBUG
    120113    if (m_staticValues) {
    121114        OpaqueJSClassStaticValuesTable::const_iterator end = m_staticValues->end();
    122         for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it) {
    123             ASSERT(!it->first->isIdentifier());
    124             delete it->second;
    125         }
    126         delete m_staticValues;
     115        for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it)
     116            ASSERT(!it->first->isIdentifier());
    127117    }
    128118
    129119    if (m_staticFunctions) {
    130120        OpaqueJSClassStaticFunctionsTable::const_iterator end = m_staticFunctions->end();
    131         for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it) {
    132             ASSERT(!it->first->isIdentifier());
    133             delete it->second;
    134         }
    135         delete m_staticFunctions;
    136     }
     121        for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it)
     122            ASSERT(!it->first->isIdentifier());
     123    }
     124#endif
    137125   
    138126    if (prototypeClass)
     
    163151{
    164152    if (jsClass->m_staticValues) {
    165         staticValues = new OpaqueJSClassStaticValuesTable;
     153        staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable);
    166154        OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end();
    167155        for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) {
    168156            ASSERT(!it->first->isIdentifier());
    169157            // Use a local variable here to sidestep an RVCT compiler bug.
    170             StaticValueEntry* entry = new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes);
    171             staticValues->add(StringImpl::create(it->first->characters(), it->first->length()), entry);
    172         }
    173     } else
    174         staticValues = 0;
     158            OwnPtr<StaticValueEntry> entry = adoptPtr(new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes));
     159            staticValues->add(StringImpl::create(it->first->characters(), it->first->length()), entry.release());
     160        }
     161    }
    175162
    176163    if (jsClass->m_staticFunctions) {
    177         staticFunctions = new OpaqueJSClassStaticFunctionsTable;
     164        staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
    178165        OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end();
    179166        for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) {
    180167            ASSERT(!it->first->isIdentifier());
    181168            // Use a local variable here to sidestep an RVCT compiler bug.
    182             StaticFunctionEntry* entry = new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes);
    183             staticFunctions->add(StringImpl::create(it->first->characters(), it->first->length()), entry);
    184         }
    185            
    186     } else
    187         staticFunctions = 0;
    188 }
    189 
    190 OpaqueJSClassContextData::~OpaqueJSClassContextData()
    191 {
    192     if (staticValues) {
    193         deleteAllValues(*staticValues);
    194         delete staticValues;
    195     }
    196 
    197     if (staticFunctions) {
    198         deleteAllValues(*staticFunctions);
    199         delete staticFunctions;
     169            OwnPtr<StaticFunctionEntry> entry = adoptPtr(new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes));
     170            staticFunctions->add(StringImpl::create(it->first->characters(), it->first->length()), entry.release());
     171        }
    200172    }
    201173}
     
    217189OpaqueJSClassStaticValuesTable* OpaqueJSClass::staticValues(JSC::ExecState* exec)
    218190{
    219     OpaqueJSClassContextData& jsClassData = contextData(exec);
    220     return jsClassData.staticValues;
     191    return contextData(exec).staticValues.get();
    221192}
    222193
    223194OpaqueJSClassStaticFunctionsTable* OpaqueJSClass::staticFunctions(JSC::ExecState* exec)
    224195{
    225     OpaqueJSClassContextData& jsClassData = contextData(exec);
    226     return jsClassData.staticFunctions;
     196    return contextData(exec).staticFunctions.get();
    227197}
    228198
     
    249219            prototypeClass = OpaqueJSClass::create(&kJSClassDefinitionEmpty).leakRef();
    250220        if (!prototypeClass->m_staticFunctions)
    251             prototypeClass->m_staticFunctions = new OpaqueJSClassStaticFunctionsTable;
     221            prototypeClass->m_staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
    252222        const Identifier& toString = exec->propertyNames().toString;
    253223        const Identifier& valueOf = exec->propertyNames().valueOf;
    254         prototypeClass->m_staticFunctions->add(StringImpl::create(toString.characters(), toString.length()), new StaticFunctionEntry(&JSCallbackFunction::toStringCallback, 0));
    255         prototypeClass->m_staticFunctions->add(StringImpl::create(valueOf.characters(), valueOf.length()), new StaticFunctionEntry(&JSCallbackFunction::valueOfCallback, 0));
     224        prototypeClass->m_staticFunctions->add(StringImpl::create(toString.characters(), toString.length()), adoptPtr(new StaticFunctionEntry(&JSCallbackFunction::toStringCallback, 0)));
     225        prototypeClass->m_staticFunctions->add(StringImpl::create(valueOf.characters(), valueOf.length()), adoptPtr(new StaticFunctionEntry(&JSCallbackFunction::valueOfCallback, 0)));
    256226    }
    257227
  • trunk/Source/JavaScriptCore/API/JSClassRef.h

    r83385 r102065  
    6060};
    6161
    62 typedef HashMap<RefPtr<StringImpl>, StaticValueEntry*> OpaqueJSClassStaticValuesTable;
    63 typedef HashMap<RefPtr<StringImpl>, StaticFunctionEntry*> OpaqueJSClassStaticFunctionsTable;
     62typedef HashMap<RefPtr<StringImpl>, OwnPtr<StaticValueEntry> > OpaqueJSClassStaticValuesTable;
     63typedef HashMap<RefPtr<StringImpl>, OwnPtr<StaticFunctionEntry> > OpaqueJSClassStaticFunctionsTable;
    6464
    6565struct OpaqueJSClass;
     
    7171public:
    7272    OpaqueJSClassContextData(JSC::JSGlobalData&, OpaqueJSClass*);
    73     ~OpaqueJSClassContextData();
    7473
    7574    // It is necessary to keep OpaqueJSClass alive because of the following rare scenario:
     
    8180    RefPtr<OpaqueJSClass> m_class;
    8281
    83     OpaqueJSClassStaticValuesTable* staticValues;
    84     OpaqueJSClassStaticFunctionsTable* staticFunctions;
     82    OwnPtr<OpaqueJSClassStaticValuesTable> staticValues;
     83    OwnPtr<OpaqueJSClassStaticFunctionsTable> staticFunctions;
    8584    JSC::Weak<JSC::JSObject> cachedPrototype;
    8685};
     
    122121    // UStrings in these data members should not be put into any IdentifierTable.
    123122    JSC::UString m_className;
    124     OpaqueJSClassStaticValuesTable* m_staticValues;
    125     OpaqueJSClassStaticFunctionsTable* m_staticFunctions;
     123    OwnPtr<OpaqueJSClassStaticValuesTable> m_staticValues;
     124    OwnPtr<OpaqueJSClassStaticFunctionsTable> m_staticFunctions;
    126125};
    127126
Note: See TracChangeset for help on using the changeset viewer.