1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Computer, Inc.
5 * Copyright (C) 2007 Christopher E. Hyde <C.Hyde@parableuk.force9.co.uk>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef KJS_PROPERTY_MAP_H_
25 #define KJS_PROPERTY_MAP_H_
27 #include "identifier.h"
28 #include <wtf/OwnArrayPtr.h>
32 class PropertyNameArray
;
37 struct PropertyMapHashTable
;
42 class SavedProperties
{
43 friend class PropertyMap
;
50 OwnArrayPtr
<SavedProperty
> _properties
;
54 * A hashtable entry for the @ref PropertyMap.
56 struct PropertyMapHashTableEntry
58 PropertyMapHashTableEntry() : key(0) { }
66 * Javascript Property Map.
68 class KJS_EXPORT PropertyMap
{
69 friend class JSObject
;
76 void put(const Identifier
&name
, JSValue
*value
, int attributes
, bool roCheck
= false);
77 void remove(const Identifier
&name
);
78 JSValue
*get(const Identifier
&name
) const;
79 JSValue
*get(const Identifier
&name
, unsigned &attributes
) const;
80 JSValue
**getLocation(const Identifier
&name
);
83 void getEnumerablePropertyNames(PropertyNameArray
&) const;
84 void getSparseArrayPropertyNames(PropertyNameArray
&) const;
86 void save(SavedProperties
&) const;
87 void restore(const SavedProperties
&p
);
91 bool hasGetterSetterProperties() const { return m_getterSetterFlag
; }
92 void setHasGetterSetterProperties(bool f
) { m_getterSetterFlag
= f
; }
94 // This /computes/ whether the table has getters or setters, while the above is
95 // used to cache the result. In other words, one usually does
96 // setHasGetterSetterProperties(containsGettersOrSetters()) whenver
97 // there is a reason to believe that the result has changed
98 bool containsGettersOrSetters() const;
100 static bool keysMatch(const UString::Rep
*, const UString::Rep
*);
103 void rehash(int newTableSize
);
105 void insert(UString::Rep
*, JSValue
*value
, int attributes
, int index
);
107 void checkConsistency();
109 typedef PropertyMapHashTableEntry Entry
;
110 typedef PropertyMapHashTable Table
;
112 UString::Rep
* m_singleEntryKey
;
114 JSValue
* singleEntryValue
;
119 short m_singleEntryAttributes
;
121 bool m_getterSetterFlag
: 1;
122 bool m_usingTable
: 1;
124 // We also stick some of the object's
125 // bitflags here. Kind of ugly, but saves memory...
126 bool m_objLocalInjected
: 1;
129 inline PropertyMap::PropertyMap() :
131 m_getterSetterFlag(false),
133 m_objLocalInjected(false)
137 #endif // _KJS_PROPERTY_MAP_H_