1 /* 2 * Copyright (C) 1999-2001 Harri Porten (porten (at) kde.org) 3 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Samuel Weinig <sam (at) webkit.org> 5 * Copyright (C) 2009 Google, Inc. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 #ifndef DOMObjectHashTableMap_h 23 #define DOMObjectHashTableMap_h 24 25 #include <runtime/Lookup.h> 26 #include <wtf/HashMap.h> 27 28 namespace JSC { 29 class JSGlobalData; 30 } 31 32 namespace WebCore { 33 34 // Map from static HashTable instances to per-GlobalData ones. 35 class DOMObjectHashTableMap { 36 public: 37 static DOMObjectHashTableMap& mapFor(JSC::JSGlobalData&); 38 39 ~DOMObjectHashTableMap() 40 { 41 HashMap<const JSC::HashTable*, JSC::HashTable>::iterator mapEnd = m_map.end(); 42 for (HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.begin(); iter != m_map.end(); ++iter) 43 iter->second.deleteTable(); 44 } 45 46 const JSC::HashTable* get(const JSC::HashTable* staticTable) 47 { 48 HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.find(staticTable); 49 if (iter != m_map.end()) 50 return &iter->second; 51 return &m_map.set(staticTable, JSC::HashTable(*staticTable)).first->second; 52 } 53 54 private: 55 HashMap<const JSC::HashTable*, JSC::HashTable> m_map; 56 }; 57 58 } // namespace WebCore 59 60 #endif // DOMObjectHashTableMap_h 61