]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
93a37866 | 2 | * Copyright (C) 2006, 2008, 2012 Apple Inc. All rights reserved. |
9dae56ea A |
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" | |
9dae56ea | 26 | #include <wtf/HashSet.h> |
f9bf01c6 | 27 | #include <wtf/OwnArrayPtr.h> |
9dae56ea A |
28 | #include <wtf/Vector.h> |
29 | ||
30 | namespace JSC { | |
f9bf01c6 A |
31 | |
32 | class Structure; | |
33 | class StructureChain; | |
9dae56ea | 34 | |
f9bf01c6 | 35 | // FIXME: Rename to PropertyNameArray. |
9dae56ea A |
36 | class PropertyNameArrayData : public RefCounted<PropertyNameArrayData> { |
37 | public: | |
38 | typedef Vector<Identifier, 20> PropertyNameVector; | |
9dae56ea A |
39 | |
40 | static PassRefPtr<PropertyNameArrayData> create() { return adoptRef(new PropertyNameArrayData); } | |
41 | ||
9dae56ea A |
42 | PropertyNameVector& propertyNameVector() { return m_propertyNameVector; } |
43 | ||
9dae56ea A |
44 | private: |
45 | PropertyNameArrayData() | |
9dae56ea A |
46 | { |
47 | } | |
48 | ||
49 | PropertyNameVector m_propertyNameVector; | |
9dae56ea A |
50 | }; |
51 | ||
f9bf01c6 | 52 | // FIXME: Rename to PropertyNameArrayBuilder. |
9dae56ea A |
53 | class PropertyNameArray { |
54 | public: | |
93a37866 | 55 | PropertyNameArray(VM* vm) |
9dae56ea | 56 | : m_data(PropertyNameArrayData::create()) |
93a37866 A |
57 | , m_vm(vm) |
58 | , m_numCacheableSlots(0) | |
59 | , m_baseObject(0) | |
9dae56ea A |
60 | { |
61 | } | |
62 | ||
63 | PropertyNameArray(ExecState* exec) | |
64 | : m_data(PropertyNameArrayData::create()) | |
93a37866 A |
65 | , m_vm(&exec->vm()) |
66 | , m_numCacheableSlots(0) | |
67 | , m_baseObject(0) | |
9dae56ea A |
68 | { |
69 | } | |
70 | ||
93a37866 | 71 | VM* vm() { return m_vm; } |
9dae56ea | 72 | |
14957cd0 | 73 | void add(const Identifier& identifier) { add(identifier.impl()); } |
6fe7ccc8 | 74 | JS_EXPORT_PRIVATE void add(StringImpl*); |
93a37866 | 75 | void addKnownUnique(StringImpl* identifier) { m_data->propertyNameVector().append(Identifier(m_vm, identifier)); } |
9dae56ea | 76 | |
9dae56ea A |
77 | Identifier& operator[](unsigned i) { return m_data->propertyNameVector()[i]; } |
78 | const Identifier& operator[](unsigned i) const { return m_data->propertyNameVector()[i]; } | |
79 | ||
9dae56ea A |
80 | void setData(PassRefPtr<PropertyNameArrayData> data) { m_data = data; } |
81 | PropertyNameArrayData* data() { return m_data.get(); } | |
9dae56ea A |
82 | PassRefPtr<PropertyNameArrayData> releaseData() { return m_data.release(); } |
83 | ||
f9bf01c6 A |
84 | // FIXME: Remove these functions. |
85 | typedef PropertyNameArrayData::PropertyNameVector::const_iterator const_iterator; | |
86 | size_t size() const { return m_data->propertyNameVector().size(); } | |
87 | const_iterator begin() const { return m_data->propertyNameVector().begin(); } | |
88 | const_iterator end() const { return m_data->propertyNameVector().end(); } | |
9dae56ea | 89 | |
93a37866 A |
90 | size_t numCacheableSlots() const { return m_numCacheableSlots; } |
91 | void setNumCacheableSlotsForObject(JSObject* object, size_t numCacheableSlots) | |
92 | { | |
93 | if (object != m_baseObject) | |
94 | return; | |
95 | m_numCacheableSlots = numCacheableSlots; | |
96 | } | |
97 | void setBaseObject(JSObject* object) | |
98 | { | |
99 | if (m_baseObject) | |
100 | return; | |
101 | m_baseObject = object; | |
102 | } | |
103 | ||
9dae56ea | 104 | private: |
14957cd0 | 105 | typedef HashSet<StringImpl*, PtrHash<StringImpl*> > IdentifierSet; |
9dae56ea A |
106 | |
107 | RefPtr<PropertyNameArrayData> m_data; | |
108 | IdentifierSet m_set; | |
93a37866 A |
109 | VM* m_vm; |
110 | size_t m_numCacheableSlots; | |
111 | JSObject* m_baseObject; | |
9dae56ea A |
112 | }; |
113 | ||
114 | } // namespace JSC | |
115 | ||
116 | #endif // PropertyNameArray_h |