also propagate updateContents() calls to parent frame
[kdelibs.git] / kjs / property_map.h
blobddd9be72444c9cb69c0c97b1199faf8dad0fccb9
1 // -*- c-basic-offset: 2 -*-
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>
30 namespace KJS {
32 class PropertyNameArray;
33 class JSValue;
35 class SavedProperty;
37 struct PropertyMapHashTable;
39 /**
40 * Saved Properties
42 class SavedProperties {
43 friend class PropertyMap;
44 public:
45 SavedProperties();
46 ~SavedProperties();
48 private:
49 int _count;
50 OwnArrayPtr<SavedProperty> _properties;
53 /**
54 * A hashtable entry for the @ref PropertyMap.
56 struct PropertyMapHashTableEntry
58 PropertyMapHashTableEntry() : key(0) { }
59 UString::Rep *key;
60 JSValue *value;
61 int attributes;
62 int index;
65 /**
66 * Javascript Property Map.
68 class KJS_EXPORT PropertyMap {
69 friend class JSObject;
70 public:
71 PropertyMap();
72 ~PropertyMap();
74 void clear();
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);
82 void mark() const;
83 void getEnumerablePropertyNames(PropertyNameArray&) const;
84 void getSparseArrayPropertyNames(PropertyNameArray&) const;
86 void save(SavedProperties &) const;
87 void restore(const SavedProperties &p);
89 bool isEmpty() const;
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;
99 private:
100 static bool keysMatch(const UString::Rep *, const UString::Rep *);
101 void expand();
102 void rehash();
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;
113 union {
114 JSValue* singleEntryValue;
115 Table* table;
116 } m_u;
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() :
130 m_singleEntryKey(0),
131 m_getterSetterFlag(false),
132 m_usingTable(false),
133 m_objLocalInjected(false)
135 } // namespace
137 #endif // _KJS_PROPERTY_MAP_H_