1/* 2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) 3 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Samuel Weinig <sam@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 28namespace JSC { 29 class VM; 30} 31 32namespace WebCore { 33 34// Map from static HashTable instances to per-GlobalData ones. 35class DOMObjectHashTableMap { 36public: 37 static DOMObjectHashTableMap& mapFor(JSC::VM&); 38 39 ~DOMObjectHashTableMap() 40 { 41 for (HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.begin(); iter != m_map.end(); ++iter) 42 iter->value.deleteTable(); 43 } 44 45 const JSC::HashTable& get(const JSC::HashTable& staticTable) 46 { 47 HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.find(&staticTable); 48 if (iter != m_map.end()) 49 return iter->value; 50 return m_map.set(&staticTable, staticTable.copy()).iterator->value; 51 } 52 53private: 54 HashMap<const JSC::HashTable*, JSC::HashTable> m_map; 55}; 56 57} // namespace WebCore 58 59#endif // DOMObjectHashTableMap_h 60