blob: c1d4c96373b93d3718d0317b1e538c88c80e8ce3 [file] [log] [blame]
weinig@apple.com3412bb42008-09-01 21:22:54 +00001/*
oliver@apple.com5fca29f2009-08-11 04:35:02 +00002 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
weinig@apple.com3412bb42008-09-01 21:22:54 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
darin@apple.coma9778f92008-11-16 04:40:06 +000026#ifndef Structure_h
27#define Structure_h
weinig@apple.com3412bb42008-09-01 21:22:54 +000028
barraclough@apple.comdfe18a52011-10-15 01:25:53 +000029#include "ClassInfo.h"
oliver@apple.comed66e772011-04-05 01:33:58 +000030#include "JSCell.h"
mjs@apple.com4fab8112008-09-10 08:42:43 +000031#include "JSType.h"
weinig@apple.com22294302008-09-09 06:55:39 +000032#include "JSValue.h"
weinig@apple.comc13fb9f2008-10-31 00:12:50 +000033#include "PropertyMapHashTable.h"
barraclough@apple.com38d3c752012-05-12 00:39:43 +000034#include "PropertyName.h"
ggaren@apple.coma850b062009-10-09 18:14:08 +000035#include "PropertyNameArray.h"
ggaren@apple.com5236be22009-10-17 05:52:20 +000036#include "Protect.h"
darin@apple.coma9778f92008-11-16 04:40:06 +000037#include "StructureTransitionTable.h"
hausmann@webkit.orgf580f322009-09-09 14:56:12 +000038#include "JSTypeInfo.h"
cwzwarich@webkit.org0b51a732008-11-05 23:21:32 +000039#include "UString.h"
ggaren@apple.comf03cbce2011-04-10 02:32:07 +000040#include "Weak.h"
levin@chromium.orgca509e82011-04-25 21:48:58 +000041#include <wtf/PassOwnPtr.h>
weinig@apple.com3412bb42008-09-01 21:22:54 +000042#include <wtf/PassRefPtr.h>
43#include <wtf/RefCounted.h>
weinig@apple.com3412bb42008-09-01 21:22:54 +000044
weinig@apple.comc13fb9f2008-10-31 00:12:50 +000045
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000046namespace JSC {
weinig@apple.com3412bb42008-09-01 21:22:54 +000047
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000048 class LLIntOffsetsExtractor;
weinig@apple.com503d9992008-09-15 07:27:14 +000049 class PropertyNameArray;
weinig@apple.com18b17a62008-09-20 04:35:33 +000050 class PropertyNameArrayData;
oliver@apple.com59144212011-04-04 18:41:15 +000051 class StructureChain;
ggaren@apple.com6e1f8c12011-06-16 22:01:43 +000052 class SlotVisitor;
msaboff@apple.com8bbd1b12012-04-25 00:58:17 +000053 class JSString;
weinig@apple.com3412bb42008-09-01 21:22:54 +000054
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +000055 class Structure : public JSCell {
weinig@apple.com3412bb42008-09-01 21:22:54 +000056 public:
oliver@apple.comd32bf7a2009-09-10 20:01:57 +000057 friend class StructureTransitionTable;
commit-queue@webkit.org6c25c522011-08-09 20:46:17 +000058
59 typedef JSCell Base;
60
oliver@apple.com8c798d22011-09-11 21:11:11 +000061 static Structure* create(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype, const TypeInfo& typeInfo, const ClassInfo* classInfo)
weinig@apple.com3412bb42008-09-01 21:22:54 +000062 {
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +000063 ASSERT(globalData.structureStructure);
oliver@apple.com23ce68f2011-04-25 21:21:28 +000064 ASSERT(classInfo);
ggaren@apple.com215589e2011-12-19 17:45:13 +000065 Structure* structure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData, globalObject, prototype, typeInfo, classInfo);
commit-queue@webkit.org403bfdf2011-08-26 22:32:53 +000066 structure->finishCreation(globalData);
67 return structure;
weinig@apple.com3412bb42008-09-01 21:22:54 +000068 }
weinig@apple.com22294302008-09-09 06:55:39 +000069
commit-queue@webkit.org403bfdf2011-08-26 22:32:53 +000070 protected:
71 void finishCreation(JSGlobalData& globalData)
72 {
73 Base::finishCreation(globalData);
74 ASSERT(m_prototype);
75 ASSERT(m_prototype.isObject() || m_prototype.isNull());
76 }
77
78 void finishCreation(JSGlobalData& globalData, CreatingEarlyCellTag)
79 {
80 Base::finishCreation(globalData, this, CreatingEarlyCell);
81 ASSERT(m_prototype);
82 ASSERT(m_prototype.isNull());
83 ASSERT(!globalData.structureStructure);
84 }
85
86 public:
weinig@apple.com7b219672008-10-16 05:31:41 +000087 static void dumpStatistics();
weinig@apple.com7b219672008-10-16 05:31:41 +000088
barraclough@apple.com38d3c752012-05-12 00:39:43 +000089 JS_EXPORT_PRIVATE static Structure* addPropertyTransition(JSGlobalData&, Structure*, PropertyName, unsigned attributes, JSCell* specificValue, size_t& offset);
90 JS_EXPORT_PRIVATE static Structure* addPropertyTransitionToExistingStructure(Structure*, PropertyName, unsigned attributes, JSCell* specificValue, size_t& offset);
91 static Structure* removePropertyTransition(JSGlobalData&, Structure*, PropertyName, size_t& offset);
morrita@google.comf0dd2d92012-01-13 07:23:44 +000092 JS_EXPORT_PRIVATE static Structure* changePrototypeTransition(JSGlobalData&, Structure*, JSValue prototype);
barraclough@apple.com38d3c752012-05-12 00:39:43 +000093 JS_EXPORT_PRIVATE static Structure* despecifyFunctionTransition(JSGlobalData&, Structure*, PropertyName);
94 static Structure* attributeChangeTransition(JSGlobalData&, Structure*, PropertyName, unsigned attributes);
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +000095 static Structure* toCacheableDictionaryTransition(JSGlobalData&, Structure*);
96 static Structure* toUncacheableDictionaryTransition(JSGlobalData&, Structure*);
97 static Structure* sealTransition(JSGlobalData&, Structure*);
98 static Structure* freezeTransition(JSGlobalData&, Structure*);
99 static Structure* preventExtensionsTransition(JSGlobalData&, Structure*);
barraclough@apple.comdd993102011-03-04 22:34:48 +0000100
oliver@apple.comaf134a72011-04-13 18:48:22 +0000101 bool isSealed(JSGlobalData&);
102 bool isFrozen(JSGlobalData&);
barraclough@apple.comdd993102011-03-04 22:34:48 +0000103 bool isExtensible() const { return !m_preventExtensions; }
ggaren@apple.com21daf642011-04-26 06:23:14 +0000104 bool didTransition() const { return m_didTransition; }
mhahnenberg@apple.com921c8232012-05-16 21:21:44 +0000105 bool shouldGrowPropertyStorage() { return propertyStorageCapacity() == propertyStorageSize(); }
106 JS_EXPORT_PRIVATE size_t suggestedNewPropertyStorageSize();
oliver@apple.combd8e7702009-11-10 02:19:04 +0000107
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000108 Structure* flattenDictionaryStructure(JSGlobalData&, JSObject*);
weinig@apple.com3412bb42008-09-01 21:22:54 +0000109
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000110 static void destroy(JSCell*);
weinig@apple.com3412bb42008-09-01 21:22:54 +0000111
weinig@apple.com5677e042008-10-20 21:27:44 +0000112 // These should be used with caution.
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000113 JS_EXPORT_PRIVATE size_t addPropertyWithoutTransition(JSGlobalData&, PropertyName, unsigned attributes, JSCell* specificValue);
114 size_t removePropertyWithoutTransition(JSGlobalData&, PropertyName);
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000115 void setPrototypeWithoutTransition(JSGlobalData& globalData, JSValue prototype) { m_prototype.set(globalData, this, prototype); }
oliver@apple.comae865892009-09-21 15:45:13 +0000116
117 bool isDictionary() const { return m_dictionaryKind != NoneDictionaryKind; }
118 bool isUncacheableDictionary() const { return m_dictionaryKind == UncachedDictionaryKind; }
weinig@apple.com3412bb42008-09-01 21:22:54 +0000119
weinig@apple.com58576b22011-09-16 21:34:20 +0000120 // Type accessors.
jberlin@webkit.org3d6b4682011-05-03 15:41:28 +0000121 const TypeInfo& typeInfo() const { ASSERT(structure()->classInfo() == &s_info); return m_typeInfo; }
weinig@apple.com58576b22011-09-16 21:34:20 +0000122 bool isObject() const { return typeInfo().isObject(); }
123
cwzwarich@webkit.orgbbdd8fb2008-09-13 04:57:35 +0000124
oliver@apple.com2346a3e2011-09-07 19:40:41 +0000125 JSGlobalObject* globalObject() const { return m_globalObject.get(); }
oliver@apple.comee1bdc82011-09-06 21:51:00 +0000126 void setGlobalObject(JSGlobalData& globalData, JSGlobalObject* globalObject) { m_globalObject.set(globalData, this, globalObject); }
127
oliver@apple.com168e5062011-01-31 20:07:21 +0000128 JSValue storedPrototype() const { return m_prototype.get(); }
ggaren@apple.comdc067b62009-05-01 22:43:39 +0000129 JSValue prototypeForLookup(ExecState*) const;
fpizlo@apple.comfd598b92012-06-08 01:31:21 +0000130 JSValue prototypeForLookup(JSGlobalObject*) const;
131 JSValue prototypeForLookup(CodeBlock*) const;
ggaren@apple.comc8bc3c82009-02-25 23:44:07 +0000132 StructureChain* prototypeChain(ExecState*) const;
mhahnenberg@apple.com982c9ea2011-09-23 19:40:09 +0000133 static void visitChildren(JSCell*, SlotVisitor&);
oliver@apple.come3c5d0e2008-09-14 08:18:49 +0000134
jberlin@webkit.org3d6b4682011-05-03 15:41:28 +0000135 Structure* previousID() const { ASSERT(structure()->classInfo() == &s_info); return m_previous.get(); }
fpizlo@apple.com74d43ae2011-09-17 23:33:01 +0000136 bool transitivelyTransitionedFrom(Structure* structureToFind);
oliver@apple.come3c5d0e2008-09-14 08:18:49 +0000137
weinig@apple.com7aa171a2008-10-07 20:49:36 +0000138 void growPropertyStorageCapacity();
jberlin@webkit.org3d6b4682011-05-03 15:41:28 +0000139 unsigned propertyStorageCapacity() const { ASSERT(structure()->classInfo() == &s_info); return m_propertyStorageCapacity; }
oliver@apple.com8c798d22011-09-11 21:11:11 +0000140 unsigned propertyStorageSize() const { ASSERT(structure()->classInfo() == &s_info); return (m_propertyTable ? m_propertyTable->propertyStorageSize() : static_cast<unsigned>(m_offset + 1)); }
mjs@apple.com93553702009-05-09 08:35:57 +0000141 bool isUsingInlineStorage() const;
weinig@apple.coma3b7bbb2008-10-30 02:44:46 +0000142
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000143 size_t get(JSGlobalData&, PropertyName);
barraclough@apple.com5d959c72011-08-07 03:44:45 +0000144 size_t get(JSGlobalData&, const UString& name);
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000145 JS_EXPORT_PRIVATE size_t get(JSGlobalData&, PropertyName, unsigned& attributes, JSCell*& specificValue);
barraclough@apple.com07173242009-05-23 01:48:32 +0000146
weinig@apple.com35ba29b2008-10-07 23:49:59 +0000147 bool hasGetterSetterProperties() const { return m_hasGetterSetterProperties; }
barraclough@apple.com2668db92012-02-22 23:46:48 +0000148 bool hasReadOnlyOrGetterSetterPropertiesExcludingProto() const { return m_hasReadOnlyOrGetterSetterPropertiesExcludingProto; }
barraclough@apple.com4f5c0c02012-02-20 21:14:48 +0000149 void setHasGetterSetterProperties(bool is__proto__)
150 {
151 m_hasGetterSetterProperties = true;
152 if (!is__proto__)
barraclough@apple.com2668db92012-02-22 23:46:48 +0000153 m_hasReadOnlyOrGetterSetterPropertiesExcludingProto = true;
barraclough@apple.com7f154b82012-02-21 06:17:40 +0000154 }
155 void setContainsReadOnlyProperties()
156 {
barraclough@apple.com2668db92012-02-22 23:46:48 +0000157 m_hasReadOnlyOrGetterSetterPropertiesExcludingProto = true;
barraclough@apple.com4f5c0c02012-02-20 21:14:48 +0000158 }
weinig@apple.com35ba29b2008-10-07 23:49:59 +0000159
oliver@apple.com0a4803c2009-10-29 01:25:02 +0000160 bool hasNonEnumerableProperties() const { return m_hasNonEnumerableProperties; }
oliver@apple.com0a4803c2009-10-29 01:25:02 +0000161
barraclough@apple.com96cad9f2011-03-01 03:53:09 +0000162 bool isEmpty() const { return m_propertyTable ? m_propertyTable->isEmpty() : m_offset == noOffset; }
weinig@apple.coma3b7bbb2008-10-30 02:44:46 +0000163
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000164 JS_EXPORT_PRIVATE void despecifyDictionaryFunction(JSGlobalData&, PropertyName);
ggaren@apple.comd0d58f42010-01-07 22:07:36 +0000165 void disableSpecificFunctionTracking() { m_specificFunctionThrashCount = maxSpecificFunctionThrashCount; }
barraclough@apple.com07173242009-05-23 01:48:32 +0000166
oliver@apple.com8d857052011-02-15 23:54:06 +0000167 void setEnumerationCache(JSGlobalData&, JSPropertyNameIterator* enumerationCache); // Defined in JSPropertyNameIterator.h.
ggaren@apple.com978e3e812010-02-12 02:51:35 +0000168 JSPropertyNameIterator* enumerationCache(); // Defined in JSPropertyNameIterator.h.
mhahnenberg@apple.com2358ae12011-11-04 01:32:18 +0000169 void getPropertyNamesFromStructure(JSGlobalData&, PropertyNameArray&, EnumerationMode);
mrowe@apple.com30d5b452010-01-30 05:30:33 +0000170
msaboff@apple.com8bbd1b12012-04-25 00:58:17 +0000171 JSString* objectToStringValue() { return m_objectToStringValue.get(); }
172
173 void setObjectToStringValue(JSGlobalData& globalData, const JSCell* owner, JSString* value)
174 {
175 m_objectToStringValue.set(globalData, owner, value);
176 }
177
barraclough@apple.comdfe18a52011-10-15 01:25:53 +0000178 bool staticFunctionsReified()
179 {
180 return m_staticFunctionReified;
181 }
182
183 void setStaticFunctionsReified()
184 {
185 m_staticFunctionReified = true;
186 }
187
barraclough@apple.coma5540da2011-02-19 21:55:44 +0000188 const ClassInfo* classInfo() const { return m_classInfo; }
189
barraclough@apple.com66184e22011-03-13 21:16:29 +0000190 static ptrdiff_t prototypeOffset()
191 {
192 return OBJECT_OFFSETOF(Structure, m_prototype);
193 }
194
195 static ptrdiff_t typeInfoFlagsOffset()
196 {
197 return OBJECT_OFFSETOF(Structure, m_typeInfo) + TypeInfo::flagsOffset();
198 }
199
200 static ptrdiff_t typeInfoTypeOffset()
201 {
202 return OBJECT_OFFSETOF(Structure, m_typeInfo) + TypeInfo::typeOffset();
203 }
204
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000205 static Structure* createStructure(JSGlobalData& globalData)
oliver@apple.combb8da912011-04-14 03:28:23 +0000206 {
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000207 ASSERT(!globalData.structureStructure);
ggaren@apple.com215589e2011-12-19 17:45:13 +0000208 Structure* structure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData);
commit-queue@webkit.org403bfdf2011-08-26 22:32:53 +0000209 structure->finishCreation(globalData, CreatingEarlyCell);
210 return structure;
oliver@apple.combb8da912011-04-14 03:28:23 +0000211 }
oliver@apple.com41037162011-05-14 22:10:01 +0000212
213 static JS_EXPORTDATA const ClassInfo s_info;
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000214
215 private:
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000216 friend class LLIntOffsetsExtractor;
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000217
morrita@google.comf0dd2d92012-01-13 07:23:44 +0000218 JS_EXPORT_PRIVATE Structure(JSGlobalData&, JSGlobalObject*, JSValue prototype, const TypeInfo&, const ClassInfo*);
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000219 Structure(JSGlobalData&);
220 Structure(JSGlobalData&, const Structure*);
221
222 static Structure* create(JSGlobalData& globalData, const Structure* structure)
223 {
224 ASSERT(globalData.structureStructure);
ggaren@apple.com215589e2011-12-19 17:45:13 +0000225 Structure* newStructure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData, structure);
commit-queue@webkit.org403bfdf2011-08-26 22:32:53 +0000226 newStructure->finishCreation(globalData);
227 return newStructure;
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000228 }
oliver@apple.com23ce68f2011-04-25 21:21:28 +0000229
oliver@apple.comae865892009-09-21 15:45:13 +0000230 typedef enum {
231 NoneDictionaryKind = 0,
232 CachedDictionaryKind = 1,
233 UncachedDictionaryKind = 2
234 } DictionaryKind;
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000235 static Structure* toDictionaryTransition(JSGlobalData&, Structure*, DictionaryKind);
weinig@apple.coma3b7bbb2008-10-30 02:44:46 +0000236
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000237 size_t putSpecificValue(JSGlobalData&, PropertyName, unsigned attributes, JSCell* specificValue);
238 size_t remove(PropertyName);
weinig@apple.comc13fb9f2008-10-31 00:12:50 +0000239
barraclough@apple.com96cad9f2011-03-01 03:53:09 +0000240 void createPropertyMap(unsigned keyCount = 0);
weinig@apple.comc13fb9f2008-10-31 00:12:50 +0000241 void checkConsistency();
242
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000243 bool despecifyFunction(JSGlobalData&, PropertyName);
oliver@apple.comaf134a72011-04-13 18:48:22 +0000244 void despecifyAllFunctions(JSGlobalData&);
barraclough@apple.com07173242009-05-23 01:48:32 +0000245
levin@chromium.orgca509e82011-04-25 21:48:58 +0000246 PassOwnPtr<PropertyTable> copyPropertyTable(JSGlobalData&, Structure* owner);
fpizlo@apple.com65c4b0d2011-10-27 22:19:14 +0000247 PassOwnPtr<PropertyTable> copyPropertyTableForPinning(JSGlobalData&, Structure* owner);
morrita@google.comf0dd2d92012-01-13 07:23:44 +0000248 JS_EXPORT_PRIVATE void materializePropertyMap(JSGlobalData&);
oliver@apple.comaf134a72011-04-13 18:48:22 +0000249 void materializePropertyMapIfNecessary(JSGlobalData& globalData)
weinig@apple.com8a866592008-11-14 23:36:06 +0000250 {
jberlin@webkit.org3d6b4682011-05-03 15:41:28 +0000251 ASSERT(structure()->classInfo() == &s_info);
barraclough@apple.com96cad9f2011-03-01 03:53:09 +0000252 if (!m_propertyTable && m_previous)
oliver@apple.comaf134a72011-04-13 18:48:22 +0000253 materializePropertyMap(globalData);
weinig@apple.com8a866592008-11-14 23:36:06 +0000254 }
fpizlo@apple.com65c4b0d2011-10-27 22:19:14 +0000255 void materializePropertyMapIfNecessaryForPinning(JSGlobalData& globalData)
256 {
257 ASSERT(structure()->classInfo() == &s_info);
258 if (!m_propertyTable)
259 materializePropertyMap(globalData);
260 }
weinig@apple.comc13fb9f2008-10-31 00:12:50 +0000261
zherczeg@webkit.org39150612011-10-03 06:49:50 +0000262 int transitionCount() const
alice.liu@apple.com04456af2009-01-05 00:18:53 +0000263 {
264 // Since the number of transitions is always the same as m_offset, we keep the size of Structure down by not storing both.
265 return m_offset == noOffset ? 0 : m_offset + 1;
266 }
barraclough@apple.com39724b82010-02-15 22:37:43 +0000267
ggaren@apple.comc8bc3c82009-02-25 23:44:07 +0000268 bool isValid(ExecState*, StructureChain* cachedPrototypeChain) const;
fpizlo@apple.com4f0f1d02011-10-07 00:47:21 +0000269
270 void pin();
alice.liu@apple.com04456af2009-01-05 00:18:53 +0000271
fpizlo@apple.com01347912011-09-29 20:45:52 +0000272 static const int s_maxTransitionLength = 64;
alice.liu@apple.com04456af2009-01-05 00:18:53 +0000273
fpizlo@apple.com01347912011-09-29 20:45:52 +0000274 static const int noOffset = -1;
weinig@apple.com3412bb42008-09-01 21:22:54 +0000275
ggaren@apple.comd0d58f42010-01-07 22:07:36 +0000276 static const unsigned maxSpecificFunctionThrashCount = 3;
277
mjs@apple.com52b67602008-09-22 03:15:52 +0000278 TypeInfo m_typeInfo;
oliver@apple.comee1bdc82011-09-06 21:51:00 +0000279
280 WriteBarrier<JSGlobalObject> m_globalObject;
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000281 WriteBarrier<Unknown> m_prototype;
282 mutable WriteBarrier<StructureChain> m_cachedPrototypeChain;
weinig@apple.com3412bb42008-09-01 21:22:54 +0000283
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000284 WriteBarrier<Structure> m_previous;
barraclough@apple.comee2085b2010-08-11 00:16:38 +0000285 RefPtr<StringImpl> m_nameInPrevious;
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000286 WriteBarrier<JSCell> m_specificValueInPrevious;
weinig@apple.com3412bb42008-09-01 21:22:54 +0000287
barraclough@apple.coma5540da2011-02-19 21:55:44 +0000288 const ClassInfo* m_classInfo;
289
barraclough@apple.com07be2aa2011-02-22 21:49:59 +0000290 StructureTransitionTable m_transitionTable;
weinig@apple.com22294302008-09-09 06:55:39 +0000291
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000292 WriteBarrier<JSPropertyNameIterator> m_enumerationCache;
weinig@apple.com503d9992008-09-15 07:27:14 +0000293
barraclough@apple.com96cad9f2011-03-01 03:53:09 +0000294 OwnPtr<PropertyTable> m_propertyTable;
weinig@apple.comc13fb9f2008-10-31 00:12:50 +0000295
oliver@apple.com0a4803c2009-10-29 01:25:02 +0000296 uint32_t m_propertyStorageCapacity;
oliver@apple.com6c9bdeb2010-02-03 01:13:47 +0000297
msaboff@apple.com8bbd1b12012-04-25 00:58:17 +0000298 WriteBarrier<JSString> m_objectToStringValue;
299
oliver@apple.com6c9bdeb2010-02-03 01:13:47 +0000300 // m_offset does not account for anonymous slots
fpizlo@apple.com01347912011-09-29 20:45:52 +0000301 int m_offset;
weinig@apple.comed15b6d2008-10-29 22:27:31 +0000302
oliver@apple.comae865892009-09-21 15:45:13 +0000303 unsigned m_dictionaryKind : 2;
weinig@apple.com8a866592008-11-14 23:36:06 +0000304 bool m_isPinnedPropertyTable : 1;
weinig@apple.comed15b6d2008-10-29 22:27:31 +0000305 bool m_hasGetterSetterProperties : 1;
barraclough@apple.com2668db92012-02-22 23:46:48 +0000306 bool m_hasReadOnlyOrGetterSetterPropertiesExcludingProto : 1;
oliver@apple.com0a4803c2009-10-29 01:25:02 +0000307 bool m_hasNonEnumerableProperties : 1;
oliver@apple.com5a6d64a2009-06-05 01:27:42 +0000308 unsigned m_attributesInPrevious : 7;
ggaren@apple.comd0d58f42010-01-07 22:07:36 +0000309 unsigned m_specificFunctionThrashCount : 2;
barraclough@apple.comdd993102011-03-04 22:34:48 +0000310 unsigned m_preventExtensions : 1;
ggaren@apple.com21daf642011-04-26 06:23:14 +0000311 unsigned m_didTransition : 1;
barraclough@apple.comdfe18a52011-10-15 01:25:53 +0000312 unsigned m_staticFunctionReified;
weinig@apple.com3412bb42008-09-01 21:22:54 +0000313 };
314
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000315 inline size_t Structure::get(JSGlobalData& globalData, PropertyName propertyName)
weinig@apple.comc13fb9f2008-10-31 00:12:50 +0000316 {
jberlin@webkit.org3d6b4682011-05-03 15:41:28 +0000317 ASSERT(structure()->classInfo() == &s_info);
oliver@apple.comaf134a72011-04-13 18:48:22 +0000318 materializePropertyMapIfNecessary(globalData);
weinig@apple.comc13fb9f2008-10-31 00:12:50 +0000319 if (!m_propertyTable)
barraclough@apple.com96cad9f2011-03-01 03:53:09 +0000320 return notFound;
weinig@apple.comc13fb9f2008-10-31 00:12:50 +0000321
barraclough@apple.com6c9b2642012-05-22 00:37:09 +0000322 PropertyMapEntry* entry = m_propertyTable->find(propertyName.uid()).first;
barraclough@apple.com96cad9f2011-03-01 03:53:09 +0000323 return entry ? entry->offset : notFound;
weinig@apple.comc13fb9f2008-10-31 00:12:50 +0000324 }
oliver@apple.com1368a402009-08-20 23:05:03 +0000325
barraclough@apple.com5d959c72011-08-07 03:44:45 +0000326 inline size_t Structure::get(JSGlobalData& globalData, const UString& name)
327 {
328 ASSERT(structure()->classInfo() == &s_info);
329 materializePropertyMapIfNecessary(globalData);
330 if (!m_propertyTable)
331 return notFound;
332
333 PropertyMapEntry* entry = m_propertyTable->findWithString(name.impl()).first;
barraclough@apple.com5d959c72011-08-07 03:44:45 +0000334 return entry ? entry->offset : notFound;
335 }
mhahnenberg@apple.com6fb47cf2011-10-10 22:32:00 +0000336
fpizlo@apple.com016fd682012-05-25 20:19:55 +0000337 inline JSValue JSValue::structureOrUndefined() const
338 {
339 if (isCell())
340 return JSValue(asCell()->structure());
341 return jsUndefined();
342 }
343
oliver@apple.comed66e772011-04-05 01:33:58 +0000344 inline bool JSCell::isObject() const
345 {
weinig@apple.com58576b22011-09-16 21:34:20 +0000346 return m_structure->isObject();
oliver@apple.comed66e772011-04-05 01:33:58 +0000347 }
348
349 inline bool JSCell::isString() const
350 {
351 return m_structure->typeInfo().type() == StringType;
352 }
353
weinig@apple.com64d86ab2011-09-11 21:45:40 +0000354 inline bool JSCell::isGetterSetter() const
355 {
356 return m_structure->typeInfo().type() == GetterSetterType;
357 }
358
weinig@apple.comade1c672011-09-11 22:29:24 +0000359 inline bool JSCell::isAPIValueWrapper() const
360 {
weinig@apple.com93f336e2011-09-17 02:57:36 +0000361 return m_structure->typeInfo().type() == APIValueWrapperType;
weinig@apple.comade1c672011-09-11 22:29:24 +0000362 }
363
ggaren@apple.com1caf69d2011-09-20 01:21:51 +0000364 inline void JSCell::setStructure(JSGlobalData& globalData, Structure* structure)
365 {
366 ASSERT(structure->typeInfo().overridesVisitChildren() == this->structure()->typeInfo().overridesVisitChildren());
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000367 ASSERT(structure->classInfo() == m_structure->classInfo());
ggaren@apple.com1caf69d2011-09-20 01:21:51 +0000368 m_structure.set(globalData, this, structure);
369 }
370
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000371 inline const ClassInfo* JSCell::validatedClassInfo() const
oliver@apple.comed66e772011-04-05 01:33:58 +0000372 {
oliver@apple.com41037162011-05-14 22:10:01 +0000373#if ENABLE(GC_VALIDATION)
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000374 ASSERT(m_structure.unvalidatedGet()->classInfo() == m_classInfo);
oliver@apple.com41037162011-05-14 22:10:01 +0000375#else
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000376 ASSERT(m_structure->classInfo() == m_classInfo);
oliver@apple.com41037162011-05-14 22:10:01 +0000377#endif
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000378 return m_classInfo;
oliver@apple.comed66e772011-04-05 01:33:58 +0000379 }
380
oliver@apple.comed66e772011-04-05 01:33:58 +0000381 ALWAYS_INLINE void MarkStack::internalAppend(JSCell* cell)
382 {
383 ASSERT(!m_isCheckingForDefaultMarkViolation);
ggaren@apple.com3a7b4792011-10-17 20:43:43 +0000384#if ENABLE(GC_VALIDATION)
385 validate(cell);
386#endif
oliver@apple.com77473382011-10-27 00:19:31 +0000387 if (Heap::testAndSetMarked(cell) || !cell->structure())
oliver@apple.comed66e772011-04-05 01:33:58 +0000388 return;
msaboff@apple.com9d9eab62012-06-06 23:11:09 +0000389
390 m_visitCount++;
fpizlo@apple.com511aa4b2011-12-06 22:12:56 +0000391
msaboff@apple.com9d9eab62012-06-06 23:11:09 +0000392 MARK_LOG_CHILD(*this, cell);
393
fpizlo@apple.com511aa4b2011-12-06 22:12:56 +0000394 // Should never attempt to mark something that is zapped.
395 ASSERT(!cell->isZapped());
396
ggaren@apple.com3a7b4792011-10-17 20:43:43 +0000397 m_stack.append(cell);
oliver@apple.comed66e772011-04-05 01:33:58 +0000398 }
399
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000400 inline StructureTransitionTable::Hash::Key StructureTransitionTable::keyForWeakGCMapFinalizer(void*, Structure* structure)
401 {
alexis.menard@openbossa.orgc86e1122011-05-03 17:34:15 +0000402 // Newer versions of the STL have an std::make_pair function that takes rvalue references.
403 // When either of the parameters are bitfields, the C++ compiler will try to bind them as lvalues, which is invalid. To work around this, use unary "+" to make the parameter an rvalue.
404 // See https://bugs.webkit.org/show_bug.cgi?id=59261 for more details.
405 return Hash::Key(structure->m_nameInPrevious.get(), +structure->m_attributesInPrevious);
oliver@apple.comb2fa0dc2011-04-15 23:55:42 +0000406 }
407
fpizlo@apple.com74d43ae2011-09-17 23:33:01 +0000408 inline bool Structure::transitivelyTransitionedFrom(Structure* structureToFind)
409 {
410 for (Structure* current = this; current; current = current->previousID()) {
411 if (current == structureToFind)
412 return true;
413 }
414 return false;
415 }
416
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000417 inline JSCell::JSCell(JSGlobalData& globalData, Structure* structure)
418 : m_classInfo(structure->classInfo())
419 , m_structure(globalData, this, structure)
420 {
421 }
422
423 inline void JSCell::finishCreation(JSGlobalData& globalData, Structure* structure, CreatingEarlyCellTag)
424 {
425#if ENABLE(GC_VALIDATION)
426 ASSERT(globalData.isInitializingObject());
msaboff@apple.com18292eb2012-03-16 16:26:26 +0000427 globalData.setInitializingObjectClass(0);
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000428 if (structure)
429#endif
430 m_structure.setEarlyValue(globalData, this, structure);
431 m_classInfo = structure->classInfo();
432 // Very first set of allocations won't have a real structure.
433 ASSERT(m_structure || !globalData.structureStructure);
434 }
435
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +0000436} // namespace JSC
weinig@apple.com3412bb42008-09-01 21:22:54 +0000437
darin@apple.coma9778f92008-11-16 04:40:06 +0000438#endif // Structure_h