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 "ExecState.h"
|
---|
25 | #include "StructureID.h"
|
---|
26 | #include "identifier.h"
|
---|
27 | #include <wtf/HashSet.h>
|
---|
28 | #include <wtf/Vector.h>
|
---|
29 |
|
---|
30 | namespace JSC {
|
---|
31 |
|
---|
32 | class PropertyNameArrayData : public RefCounted<PropertyNameArrayData> {
|
---|
33 | public:
|
---|
34 | typedef Vector<Identifier, 20> PropertyNameVector;
|
---|
35 | typedef PropertyNameVector::const_iterator const_iterator;
|
---|
36 |
|
---|
37 | static PassRefPtr<PropertyNameArrayData> create() { return adoptRef(new PropertyNameArrayData); }
|
---|
38 |
|
---|
39 | const_iterator begin() const { return m_propertyNameVector.begin(); }
|
---|
40 | const_iterator end() const { return m_propertyNameVector.end(); }
|
---|
41 |
|
---|
42 | PropertyNameVector& propertyNameVector() { return m_propertyNameVector; }
|
---|
43 |
|
---|
44 | void setCachedStructureID(PassRefPtr<StructureID> structureID) { m_cachedStructureID = structureID; }
|
---|
45 | StructureID* cachedStructureID() const { return m_cachedStructureID.get(); }
|
---|
46 |
|
---|
47 | void setCachedPrototypeChain(PassRefPtr<StructureIDChain> cachedPrototypeChain) { m_cachedPrototypeChain = cachedPrototypeChain; }
|
---|
48 | StructureIDChain* cachedPrototypeChain() { return m_cachedPrototypeChain.get(); }
|
---|
49 |
|
---|
50 | private:
|
---|
51 | PropertyNameArrayData()
|
---|
52 | {
|
---|
53 | }
|
---|
54 |
|
---|
55 | PropertyNameVector m_propertyNameVector;
|
---|
56 | RefPtr<StructureID> m_cachedStructureID;
|
---|
57 | RefPtr<StructureIDChain> m_cachedPrototypeChain;
|
---|
58 | };
|
---|
59 |
|
---|
60 | class PropertyNameArray {
|
---|
61 | public:
|
---|
62 | typedef PropertyNameArrayData::const_iterator const_iterator;
|
---|
63 |
|
---|
64 | PropertyNameArray(JSGlobalData* globalData)
|
---|
65 | : m_data(PropertyNameArrayData::create())
|
---|
66 | , m_globalData(globalData)
|
---|
67 | {
|
---|
68 | }
|
---|
69 |
|
---|
70 | PropertyNameArray(ExecState* exec)
|
---|
71 | : m_data(PropertyNameArrayData::create())
|
---|
72 | , m_globalData(&exec->globalData())
|
---|
73 | {
|
---|
74 | }
|
---|
75 |
|
---|
76 | JSGlobalData* globalData() { return m_globalData; }
|
---|
77 |
|
---|
78 | void add(const Identifier& identifier) { add(identifier.ustring().rep()); }
|
---|
79 | void add(UString::Rep*);
|
---|
80 | void addKnownUnique(UString::Rep* identifier) { m_data->propertyNameVector().append(Identifier(m_globalData, identifier)); }
|
---|
81 |
|
---|
82 | size_t size() const { return m_data->propertyNameVector().size(); }
|
---|
83 |
|
---|
84 | Identifier& operator[](unsigned i) { return m_data->propertyNameVector()[i]; }
|
---|
85 | const Identifier& operator[](unsigned i) const { return m_data->propertyNameVector()[i]; }
|
---|
86 |
|
---|
87 | const_iterator begin() const { return m_data->begin(); }
|
---|
88 | const_iterator end() const { return m_data->end(); }
|
---|
89 |
|
---|
90 | void setData(PassRefPtr<PropertyNameArrayData> data) { m_data = data; }
|
---|
91 | PropertyNameArrayData* data() { return m_data.get(); }
|
---|
92 |
|
---|
93 | PassRefPtr<PropertyNameArrayData> releaseData() { return m_data.release(); }
|
---|
94 |
|
---|
95 | private:
|
---|
96 | typedef HashSet<UString::Rep*, PtrHash<UString::Rep*> > IdentifierSet;
|
---|
97 |
|
---|
98 | RefPtr<PropertyNameArrayData> m_data;
|
---|
99 | IdentifierSet m_set;
|
---|
100 | JSGlobalData* m_globalData;
|
---|
101 | };
|
---|
102 |
|
---|
103 | } // namespace JSC
|
---|
104 |
|
---|
105 | #endif // PropertyNameArray_h
|
---|