1 // -*- mode: c++; c-basic-offset: 4 -*-
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef KJS_PROPERTY_MAP_H_
23 #define KJS_PROPERTY_MAP_H_
25 #include "identifier.h"
27 #include <wtf/OwnArrayPtr.h>
33 class PropertyNameArray
;
35 struct PropertyMapEntry
;
36 struct PropertyMapHashTable
;
38 class SavedProperty
: Noncopyable
{
40 // Since we use this in arrays, we allocate it uninitialized
41 // and then explicitly initialize. This means we can allocate
42 // the array without initializing every saved property in the
43 // array twice. To accomplish this, the class uses data members
44 // with types that don't have constructors.
46 void init(UString::Rep
* name
, JSValue
*, unsigned attributes
);
49 UString::Rep
* name() const;
50 JSValue
* value() const;
51 unsigned attributes() const;
56 unsigned m_attributes
;
59 struct SavedProperties
{
64 OwnArrayPtr
<SavedProperty
> properties
;
67 class PropertyMap
: Noncopyable
{
74 void put(const Identifier
&, JSValue
*, unsigned attributes
, bool checkReadOnly
= false);
75 void remove(const Identifier
&);
76 JSValue
* get(const Identifier
&) const;
77 JSValue
* get(const Identifier
&, unsigned& attributes
) const;
78 JSValue
** getLocation(const Identifier
& name
);
81 void getEnumerablePropertyNames(PropertyNameArray
&) const;
83 void save(SavedProperties
&) const;
84 void restore(const SavedProperties
&);
86 bool hasGetterSetterProperties() const { return m_getterSetterFlag
; }
87 void setHasGetterSetterProperties(bool f
) { m_getterSetterFlag
= f
; }
89 bool containsGettersOrSetters() const;
92 typedef PropertyMapEntry Entry
;
93 typedef PropertyMapHashTable Table
;
95 static bool keysMatch(const UString::Rep
*, const UString::Rep
*);
98 void rehash(unsigned newTableSize
);
101 void insert(const Entry
&);
103 void checkConsistency();
105 UString::Rep
* m_singleEntryKey
;
107 JSValue
* singleEntryValue
;
111 short m_singleEntryAttributes
;
112 bool m_getterSetterFlag
: 1;
113 bool m_usingTable
: 1;
116 inline PropertyMap::PropertyMap()
117 : m_singleEntryKey(0)
118 , m_getterSetterFlag(false)
119 , m_usingTable(false)
124 inline SavedProperty::SavedProperty()
133 inline void SavedProperty::init(UString::Rep
* name
, JSValue
* value
, unsigned attributes
)
140 ASSERT(!m_attributes
);
144 m_attributes
= attributes
;
149 inline SavedProperty::~SavedProperty()
155 gcUnprotect(m_value
);
158 inline UString::Rep
* SavedProperty::name() const
166 inline JSValue
* SavedProperty::value() const
174 inline unsigned SavedProperty::attributes() const
184 #endif // _KJS_PROPERTY_MAP_H_