1 /* 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 * 19 */ 20 21 #ifndef PropertyNameArray_h 22 #define PropertyNameArray_h 23 24 #include "CallFrame.h" 25 #include "Identifier.h" 26 #include <wtf/HashSet.h> 27 #include <wtf/OwnArrayPtr.h> 28 #include <wtf/Vector.h> 29 30 namespace JSC { 31 32 class Structure; 33 class StructureChain; 34 35 // FIXME: Rename to PropertyNameArray. 36 class PropertyNameArrayData : public RefCounted<PropertyNameArrayData> { 37 public: 38 typedef Vector<Identifier, 20> PropertyNameVector; 39 40 static PassRefPtr<PropertyNameArrayData> create() { return adoptRef(new PropertyNameArrayData); } 41 42 PropertyNameVector& propertyNameVector() { return m_propertyNameVector; } 43 44 private: 45 PropertyNameArrayData() 46 { 47 } 48 49 PropertyNameVector m_propertyNameVector; 50 }; 51 52 // FIXME: Rename to PropertyNameArrayBuilder. 53 class PropertyNameArray { 54 public: 55 PropertyNameArray(JSGlobalData* globalData) 56 : m_data(PropertyNameArrayData::create()) 57 , m_globalData(globalData) 58 , m_shouldCache(true) 59 { 60 } 61 62 PropertyNameArray(ExecState* exec) 63 : m_data(PropertyNameArrayData::create()) 64 , m_globalData(&exec->globalData()) 65 , m_shouldCache(true) 66 { 67 } 68 69 JSGlobalData* globalData() { return m_globalData; } 70 71 void add(const Identifier& identifier) { add(identifier.impl()); } 72 void add(StringImpl*); 73 void addKnownUnique(StringImpl* identifier) { m_data->propertyNameVector().append(Identifier(m_globalData, identifier)); } 74 75 Identifier& operator[](unsigned i) { return m_data->propertyNameVector()[i]; } 76 const Identifier& operator[](unsigned i) const { return m_data->propertyNameVector()[i]; } 77 78 void setData(PassRefPtr<PropertyNameArrayData> data) { m_data = data; } 79 PropertyNameArrayData* data() { return m_data.get(); } 80 PassRefPtr<PropertyNameArrayData> releaseData() { return m_data.release(); } 81 82 // FIXME: Remove these functions. 83 typedef PropertyNameArrayData::PropertyNameVector::const_iterator const_iterator; 84 size_t size() const { return m_data->propertyNameVector().size(); } 85 const_iterator begin() const { return m_data->propertyNameVector().begin(); } 86 const_iterator end() const { return m_data->propertyNameVector().end(); } 87 88 private: 89 typedef HashSet<StringImpl*, PtrHash<StringImpl*> > IdentifierSet; 90 91 RefPtr<PropertyNameArrayData> m_data; 92 IdentifierSet m_set; 93 JSGlobalData* m_globalData; 94 bool m_shouldCache; 95 }; 96 97 } // namespace JSC 98 99 #endif // PropertyNameArray_h 100