Title: [102065] trunk/Source/_javascript_Core
Revision
102065
Author
da...@apple.com
Date
2011-12-05 16:17:34 -0800 (Mon, 05 Dec 2011)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h (102064 => 102065)


--- trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h	2011-12-06 00:17:13 UTC (rev 102064)
+++ trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h	2011-12-06 00:17:34 UTC (rev 102065)
@@ -439,7 +439,7 @@
             iterator end = staticValues->end();
             for (iterator it = staticValues->begin(); it != end; ++it) {
                 StringImpl* name = it->first.get();
-                StaticValueEntry* entry = it->second;
+                StaticValueEntry* entry = it->second.get();
                 if (entry->getProperty && (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties)))
                     propertyNames.add(Identifier(exec, name));
             }
@@ -450,7 +450,7 @@
             iterator end = staticFunctions->end();
             for (iterator it = staticFunctions->begin(); it != end; ++it) {
                 StringImpl* name = it->first.get();
-                StaticFunctionEntry* entry = it->second;
+                StaticFunctionEntry* entry = it->second.get();
                 if (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties))
                     propertyNames.add(Identifier(exec, name));
             }

Modified: trunk/Source/_javascript_Core/API/JSClassRef.cpp (102064 => 102065)


--- trunk/Source/_javascript_Core/API/JSClassRef.cpp	2011-12-06 00:17:13 UTC (rev 102064)
+++ trunk/Source/_javascript_Core/API/JSClassRef.cpp	2011-12-06 00:17:34 UTC (rev 102065)
@@ -71,38 +71,30 @@
     , hasInstance(definition->hasInstance)
     , convertToType(definition->convertToType)
     , m_className(tryCreateStringFromUTF8(definition->className))
-    , m_staticValues(0)
-    , m_staticFunctions(0)
 {
     initializeThreading();
 
     if (const JSStaticValue* staticValue = definition->staticValues) {
-        m_staticValues = new OpaqueJSClassStaticValuesTable();
+        m_staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable);
         while (staticValue->name) {
             UString valueName = tryCreateStringFromUTF8(staticValue->name);
             if (!valueName.isNull()) {
                 // Use a local variable here to sidestep an RVCT compiler bug.
-                StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes);
-                StringImpl* impl = valueName.impl();
-                StaticValueEntry* existingEntry = m_staticValues->get(impl);
-                m_staticValues->set(impl, entry);
-                delete existingEntry;
+                OwnPtr<StaticValueEntry> entry = adoptPtr(new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes));
+                m_staticValues->set(valueName.impl(), entry.release());
             }
             ++staticValue;
         }
     }
 
     if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
-        m_staticFunctions = new OpaqueJSClassStaticFunctionsTable();
+        m_staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
         while (staticFunction->name) {
             UString functionName = tryCreateStringFromUTF8(staticFunction->name);
             if (!functionName.isNull()) {
                 // Use a local variable here to sidestep an RVCT compiler bug.
-                StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes);
-                StringImpl* impl = functionName.impl();
-                StaticFunctionEntry* existingEntry = m_staticFunctions->get(impl);
-                m_staticFunctions->set(impl, entry);
-                delete existingEntry;
+                OwnPtr<StaticFunctionEntry> entry = adoptPtr(new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes));
+                m_staticFunctions->set(functionName.impl(), entry.release());
             }
             ++staticFunction;
         }
@@ -117,23 +109,19 @@
     // The empty string is shared across threads & is an identifier, in all other cases we should have done a deep copy in className(), below. 
     ASSERT(!m_className.length() || !m_className.impl()->isIdentifier());
 
+#ifndef NDEBUG
     if (m_staticValues) {
         OpaqueJSClassStaticValuesTable::const_iterator end = m_staticValues->end();
-        for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it) {
+        for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it)
             ASSERT(!it->first->isIdentifier());
-            delete it->second;
-        }
-        delete m_staticValues;
     }
 
     if (m_staticFunctions) {
         OpaqueJSClassStaticFunctionsTable::const_iterator end = m_staticFunctions->end();
-        for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it) {
+        for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it)
             ASSERT(!it->first->isIdentifier());
-            delete it->second;
-        }
-        delete m_staticFunctions;
     }
+#endif
     
     if (prototypeClass)
         JSClassRelease(prototypeClass);
@@ -162,42 +150,26 @@
     : m_class(jsClass)
 {
     if (jsClass->m_staticValues) {
-        staticValues = new OpaqueJSClassStaticValuesTable;
+        staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable);
         OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end();
         for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) {
             ASSERT(!it->first->isIdentifier());
             // Use a local variable here to sidestep an RVCT compiler bug.
-            StaticValueEntry* entry = new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes);
-            staticValues->add(StringImpl::create(it->first->characters(), it->first->length()), entry);
+            OwnPtr<StaticValueEntry> entry = adoptPtr(new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes));
+            staticValues->add(StringImpl::create(it->first->characters(), it->first->length()), entry.release());
         }
-    } else
-        staticValues = 0;
+    }
 
     if (jsClass->m_staticFunctions) {
-        staticFunctions = new OpaqueJSClassStaticFunctionsTable;
+        staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
         OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end();
         for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) {
             ASSERT(!it->first->isIdentifier());
             // Use a local variable here to sidestep an RVCT compiler bug.
-            StaticFunctionEntry* entry = new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes);
-            staticFunctions->add(StringImpl::create(it->first->characters(), it->first->length()), entry);
+            OwnPtr<StaticFunctionEntry> entry = adoptPtr(new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes));
+            staticFunctions->add(StringImpl::create(it->first->characters(), it->first->length()), entry.release());
         }
-            
-    } else
-        staticFunctions = 0;
-}
-
-OpaqueJSClassContextData::~OpaqueJSClassContextData()
-{
-    if (staticValues) {
-        deleteAllValues(*staticValues);
-        delete staticValues;
     }
-
-    if (staticFunctions) {
-        deleteAllValues(*staticFunctions);
-        delete staticFunctions;
-    }
 }
 
 OpaqueJSClassContextData& OpaqueJSClass::contextData(ExecState* exec)
@@ -216,14 +188,12 @@
 
 OpaqueJSClassStaticValuesTable* OpaqueJSClass::staticValues(JSC::ExecState* exec)
 {
-    OpaqueJSClassContextData& jsClassData = contextData(exec);
-    return jsClassData.staticValues;
+    return contextData(exec).staticValues.get();
 }
 
 OpaqueJSClassStaticFunctionsTable* OpaqueJSClass::staticFunctions(JSC::ExecState* exec)
 {
-    OpaqueJSClassContextData& jsClassData = contextData(exec);
-    return jsClassData.staticFunctions;
+    return contextData(exec).staticFunctions.get();
 }
 
 /*!
@@ -248,11 +218,11 @@
         if (!prototypeClass)
             prototypeClass = OpaqueJSClass::create(&kJSClassDefinitionEmpty).leakRef();
         if (!prototypeClass->m_staticFunctions)
-            prototypeClass->m_staticFunctions = new OpaqueJSClassStaticFunctionsTable;
+            prototypeClass->m_staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
         const Identifier& toString = exec->propertyNames().toString;
         const Identifier& valueOf = exec->propertyNames().valueOf;
-        prototypeClass->m_staticFunctions->add(StringImpl::create(toString.characters(), toString.length()), new StaticFunctionEntry(&JSCallbackFunction::toStringCallback, 0));
-        prototypeClass->m_staticFunctions->add(StringImpl::create(valueOf.characters(), valueOf.length()), new StaticFunctionEntry(&JSCallbackFunction::valueOfCallback, 0));
+        prototypeClass->m_staticFunctions->add(StringImpl::create(toString.characters(), toString.length()), adoptPtr(new StaticFunctionEntry(&JSCallbackFunction::toStringCallback, 0)));
+        prototypeClass->m_staticFunctions->add(StringImpl::create(valueOf.characters(), valueOf.length()), adoptPtr(new StaticFunctionEntry(&JSCallbackFunction::valueOfCallback, 0)));
     }
 
     if (!prototypeClass)

Modified: trunk/Source/_javascript_Core/API/JSClassRef.h (102064 => 102065)


--- trunk/Source/_javascript_Core/API/JSClassRef.h	2011-12-06 00:17:13 UTC (rev 102064)
+++ trunk/Source/_javascript_Core/API/JSClassRef.h	2011-12-06 00:17:34 UTC (rev 102065)
@@ -59,8 +59,8 @@
     JSPropertyAttributes attributes;
 };
 
-typedef HashMap<RefPtr<StringImpl>, StaticValueEntry*> OpaqueJSClassStaticValuesTable;
-typedef HashMap<RefPtr<StringImpl>, StaticFunctionEntry*> OpaqueJSClassStaticFunctionsTable;
+typedef HashMap<RefPtr<StringImpl>, OwnPtr<StaticValueEntry> > OpaqueJSClassStaticValuesTable;
+typedef HashMap<RefPtr<StringImpl>, OwnPtr<StaticFunctionEntry> > OpaqueJSClassStaticFunctionsTable;
 
 struct OpaqueJSClass;
 
@@ -70,7 +70,6 @@
     WTF_MAKE_NONCOPYABLE(OpaqueJSClassContextData); WTF_MAKE_FAST_ALLOCATED;
 public:
     OpaqueJSClassContextData(JSC::JSGlobalData&, OpaqueJSClass*);
-    ~OpaqueJSClassContextData();
 
     // It is necessary to keep OpaqueJSClass alive because of the following rare scenario:
     // 1. A class is created and used, so its context data is stored in JSGlobalData hash map.
@@ -80,8 +79,8 @@
     // 4. When it is used, the old context data is found in JSGlobalData and used.
     RefPtr<OpaqueJSClass> m_class;
 
-    OpaqueJSClassStaticValuesTable* staticValues;
-    OpaqueJSClassStaticFunctionsTable* staticFunctions;
+    OwnPtr<OpaqueJSClassStaticValuesTable> staticValues;
+    OwnPtr<OpaqueJSClassStaticFunctionsTable> staticFunctions;
     JSC::Weak<JSC::JSObject> cachedPrototype;
 };
 
@@ -121,8 +120,8 @@
 
     // UStrings in these data members should not be put into any IdentifierTable.
     JSC::UString m_className;
-    OpaqueJSClassStaticValuesTable* m_staticValues;
-    OpaqueJSClassStaticFunctionsTable* m_staticFunctions;
+    OwnPtr<OpaqueJSClassStaticValuesTable> m_staticValues;
+    OwnPtr<OpaqueJSClassStaticFunctionsTable> m_staticFunctions;
 };
 
 #endif // JSClassRef_h

Modified: trunk/Source/_javascript_Core/ChangeLog (102064 => 102065)


--- trunk/Source/_javascript_Core/ChangeLog	2011-12-06 00:17:13 UTC (rev 102064)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-12-06 00:17:34 UTC (rev 102065)
@@ -1,3 +1,33 @@
+2011-12-05  Darin Adler  <da...@apple.com>
+
+        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.
+
 2011-12-05  Oliver Hunt  <oli...@apple.com>
 
         Land uncommitted bit of float array support
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to