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