Changeset 102065 in webkit
- Timestamp:
- Dec 5, 2011, 4:17:34 PM (15 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
-
API/JSCallbackObjectFunctions.h (modified) (2 diffs)
-
API/JSClassRef.cpp (modified) (6 diffs)
-
API/JSClassRef.h (modified) (4 diffs)
-
ChangeLog (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
r100006 r102065 440 440 for (iterator it = staticValues->begin(); it != end; ++it) { 441 441 StringImpl* name = it->first.get(); 442 StaticValueEntry* entry = it->second ;442 StaticValueEntry* entry = it->second.get(); 443 443 if (entry->getProperty && (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties))) 444 444 propertyNames.add(Identifier(exec, name)); … … 451 451 for (iterator it = staticFunctions->begin(); it != end; ++it) { 452 452 StringImpl* name = it->first.get(); 453 StaticFunctionEntry* entry = it->second ;453 StaticFunctionEntry* entry = it->second.get(); 454 454 if (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties)) 455 455 propertyNames.add(Identifier(exec, name)); -
trunk/Source/JavaScriptCore/API/JSClassRef.cpp
r101945 r102065 72 72 , convertToType(definition->convertToType) 73 73 , m_className(tryCreateStringFromUTF8(definition->className)) 74 , m_staticValues(0)75 , m_staticFunctions(0)76 74 { 77 75 initializeThreading(); 78 76 79 77 if (const JSStaticValue* staticValue = definition->staticValues) { 80 m_staticValues = new OpaqueJSClassStaticValuesTable();78 m_staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable); 81 79 while (staticValue->name) { 82 80 UString valueName = tryCreateStringFromUTF8(staticValue->name); 83 81 if (!valueName.isNull()) { 84 82 // 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()); 90 85 } 91 86 ++staticValue; … … 94 89 95 90 if (const JSStaticFunction* staticFunction = definition->staticFunctions) { 96 m_staticFunctions = new OpaqueJSClassStaticFunctionsTable();91 m_staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable); 97 92 while (staticFunction->name) { 98 93 UString functionName = tryCreateStringFromUTF8(staticFunction->name); 99 94 if (!functionName.isNull()) { 100 95 // 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()); 106 98 } 107 99 ++staticFunction; … … 118 110 ASSERT(!m_className.length() || !m_className.impl()->isIdentifier()); 119 111 112 #ifndef NDEBUG 120 113 if (m_staticValues) { 121 114 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()); 127 117 } 128 118 129 119 if (m_staticFunctions) { 130 120 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 137 125 138 126 if (prototypeClass) … … 163 151 { 164 152 if (jsClass->m_staticValues) { 165 staticValues = new OpaqueJSClassStaticValuesTable;153 staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable); 166 154 OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end(); 167 155 for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) { 168 156 ASSERT(!it->first->isIdentifier()); 169 157 // 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 } 175 162 176 163 if (jsClass->m_staticFunctions) { 177 staticFunctions = new OpaqueJSClassStaticFunctionsTable;164 staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable); 178 165 OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end(); 179 166 for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) { 180 167 ASSERT(!it->first->isIdentifier()); 181 168 // 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 } 200 172 } 201 173 } … … 217 189 OpaqueJSClassStaticValuesTable* OpaqueJSClass::staticValues(JSC::ExecState* exec) 218 190 { 219 OpaqueJSClassContextData& jsClassData = contextData(exec); 220 return jsClassData.staticValues; 191 return contextData(exec).staticValues.get(); 221 192 } 222 193 223 194 OpaqueJSClassStaticFunctionsTable* OpaqueJSClass::staticFunctions(JSC::ExecState* exec) 224 195 { 225 OpaqueJSClassContextData& jsClassData = contextData(exec); 226 return jsClassData.staticFunctions; 196 return contextData(exec).staticFunctions.get(); 227 197 } 228 198 … … 249 219 prototypeClass = OpaqueJSClass::create(&kJSClassDefinitionEmpty).leakRef(); 250 220 if (!prototypeClass->m_staticFunctions) 251 prototypeClass->m_staticFunctions = new OpaqueJSClassStaticFunctionsTable;221 prototypeClass->m_staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable); 252 222 const Identifier& toString = exec->propertyNames().toString; 253 223 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))); 256 226 } 257 227 -
trunk/Source/JavaScriptCore/API/JSClassRef.h
r83385 r102065 60 60 }; 61 61 62 typedef HashMap<RefPtr<StringImpl>, StaticValueEntry*> OpaqueJSClassStaticValuesTable;63 typedef HashMap<RefPtr<StringImpl>, StaticFunctionEntry*> OpaqueJSClassStaticFunctionsTable;62 typedef HashMap<RefPtr<StringImpl>, OwnPtr<StaticValueEntry> > OpaqueJSClassStaticValuesTable; 63 typedef HashMap<RefPtr<StringImpl>, OwnPtr<StaticFunctionEntry> > OpaqueJSClassStaticFunctionsTable; 64 64 65 65 struct OpaqueJSClass; … … 71 71 public: 72 72 OpaqueJSClassContextData(JSC::JSGlobalData&, OpaqueJSClass*); 73 ~OpaqueJSClassContextData();74 73 75 74 // It is necessary to keep OpaqueJSClass alive because of the following rare scenario: … … 81 80 RefPtr<OpaqueJSClass> m_class; 82 81 83 O paqueJSClassStaticValuesTable*staticValues;84 O paqueJSClassStaticFunctionsTable*staticFunctions;82 OwnPtr<OpaqueJSClassStaticValuesTable> staticValues; 83 OwnPtr<OpaqueJSClassStaticFunctionsTable> staticFunctions; 85 84 JSC::Weak<JSC::JSObject> cachedPrototype; 86 85 }; … … 122 121 // UStrings in these data members should not be put into any IdentifierTable. 123 122 JSC::UString m_className; 124 O paqueJSClassStaticValuesTable*m_staticValues;125 O paqueJSClassStaticFunctionsTable*m_staticFunctions;123 OwnPtr<OpaqueJSClassStaticValuesTable> m_staticValues; 124 OwnPtr<OpaqueJSClassStaticFunctionsTable> m_staticFunctions; 126 125 }; 127 126 -
trunk/Source/JavaScriptCore/ChangeLog
r102061 r102065 1 2011-12-05 Darin Adler <darin@apple.com> 2 3 Convert JSClassRef to use HashMap<OwnPtr> 4 https://bugs.webkit.org/show_bug.cgi?id=73780 5 6 Reviewed by Andreas Kling. 7 8 * API/JSCallbackObjectFunctions.h: 9 (JSC::JSCallbackObject::getOwnPropertyNames): Use get() on the hash map 10 entries because the hash map now has an OwnPtr instead of a raw pointer. 11 12 * API/JSClassRef.cpp: 13 (OpaqueJSClass::OpaqueJSClass): No need to initialize m_staticValues and 14 m_staticFunctions since they are now OwnPtr. Use adoptPtr when allocating. 15 Removed the code that gets and deletes existing entries, and just use set, 16 which now handles deletion automatically due to it being OwnPtr. 17 (OpaqueJSClass::~OpaqueJSClass): Replaced code to do all the deletion 18 with assertion-only NDEBUG-only code. 19 (OpaqueJSClassContextData::OpaqueJSClassContextData): Use adoptPtr when 20 allocating. Use OwnPtr when adding. Removed unneeded code to set 21 staticValues and staticFunctions to 0. Removed unneeded destructor. 22 (OpaqueJSClass::staticValues): Added get call. Also removed unneeded local. 23 (OpaqueJSClass::staticFunctions): Ditto. 24 (OpaqueJSClass::prototype): Added use of adoptPtr. 25 26 * API/JSClassRef.h: Made the static values and static functions tables 27 use OwnPtr for the entries. Also used OwnPtr for the pointers to the 28 tables themselves. Also removed ~OpaqueJSClassContextData(), letting 29 the compiler generate it. 30 1 31 2011-12-05 Oliver Hunt <oliver@apple.com> 2 32
Note:
See TracChangeset
for help on using the changeset viewer.