]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/JSActivation.h
JavaScriptCore-7600.1.4.11.8.tar.gz
[apple/javascriptcore.git] / runtime / JSActivation.h
CommitLineData
9dae56ea 1/*
81345200 2 * Copyright (C) 2008, 2009, 2013 Apple Inc. All rights reserved.
9dae56ea
A
3 *
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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
81345200 13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
9dae56ea
A
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef JSActivation_h
30#define JSActivation_h
31
32#include "CodeBlock.h"
93a37866 33#include "CopiedSpaceInlines.h"
9dae56ea 34#include "JSVariableObject.h"
9dae56ea 35#include "Nodes.h"
93a37866 36#include "SymbolTable.h"
9dae56ea
A
37
38namespace JSC {
39
81345200 40class Register;
9dae56ea 41
81345200
A
42class JSActivation : public JSVariableObject {
43private:
44 JSActivation(VM&, CallFrame*, Register*, SymbolTable*);
6fe7ccc8 45
81345200
A
46public:
47 typedef JSVariableObject Base;
6fe7ccc8 48
81345200 49 static JSActivation* create(VM& vm, CallFrame* callFrame, Register* registers, CodeBlock* codeBlock)
93a37866 50 {
81345200
A
51 SymbolTable* symbolTable = codeBlock->symbolTable();
52 ASSERT(codeBlock->codeType() == FunctionCode);
53 JSActivation* activation = new (
54 NotNull,
55 allocateCell<JSActivation>(
56 vm.heap,
57 allocationSize(symbolTable)
58 )
59 ) JSActivation(vm, callFrame, registers, symbolTable);
60 activation->finishCreation(vm);
61 return activation;
93a37866 62 }
81345200
A
63
64 static JSActivation* create(VM& vm, CallFrame* callFrame, CodeBlock* codeBlock)
6fe7ccc8 65 {
81345200 66 return create(vm, callFrame, callFrame->registers() + codeBlock->framePointerOffsetToGetActivationRegisters(), codeBlock);
93a37866 67 }
6fe7ccc8 68
81345200 69 static void visitChildren(JSCell*, SlotVisitor&);
6fe7ccc8 70
81345200
A
71 static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
72 static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
6fe7ccc8 73
81345200 74 static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
6fe7ccc8 75
81345200 76 static bool deleteProperty(JSCell*, ExecState*, PropertyName);
93a37866 77
81345200 78 static JSValue toThis(JSCell*, ExecState*, ECMAMode);
93a37866 79
81345200
A
80 void tearOff(VM&);
81
82 DECLARE_INFO;
83
84 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto) { return Structure::create(vm, globalObject, proto, TypeInfo(ActivationObjectType, StructureFlags), info()); }
85
86 WriteBarrierBase<Unknown>& registerAt(int) const;
87 bool isValidIndex(int) const;
88 bool isValid(const SymbolTableEntry&) const;
89 bool isTornOff();
90 int registersOffset();
91 static int registersOffset(SymbolTable*);
92
93protected:
94 static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | Base::StructureFlags;
95
96private:
97 bool symbolTableGet(PropertyName, PropertySlot&);
98 bool symbolTableGet(PropertyName, PropertyDescriptor&);
99 bool symbolTableGet(PropertyName, PropertySlot&, bool& slotIsWriteable);
100 bool symbolTablePut(ExecState*, PropertyName, JSValue, bool shouldThrow);
101 bool symbolTablePutWithAttributes(VM&, PropertyName, JSValue, unsigned attributes);
102
103 static EncodedJSValue argumentsGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName);
104
105 static size_t allocationSize(SymbolTable*);
106 static size_t storageOffset();
107
108 WriteBarrier<Unknown>* storage(); // captureCount() number of registers.
109};
110
111extern int activationCount;
112extern int allTheThingsCount;
113
114inline JSActivation::JSActivation(VM& vm, CallFrame* callFrame, Register* registers, SymbolTable* symbolTable)
115 : Base(
116 vm,
117 callFrame->lexicalGlobalObject()->activationStructure(),
118 registers,
119 callFrame->scope(),
120 symbolTable)
121{
122 WriteBarrier<Unknown>* storage = this->storage();
123 size_t captureCount = symbolTable->captureCount();
124 for (size_t i = 0; i < captureCount; ++i)
125 new (NotNull, &storage[i]) WriteBarrier<Unknown>;
126}
127
128JSActivation* asActivation(JSValue);
129
130inline JSActivation* asActivation(JSValue value)
131{
132 ASSERT(asObject(value)->inherits(JSActivation::info()));
133 return jsCast<JSActivation*>(asObject(value));
134}
135
136ALWAYS_INLINE JSActivation* Register::activation() const
137{
138 return asActivation(jsValue());
139}
140
141inline int JSActivation::registersOffset(SymbolTable* symbolTable)
142{
143 return storageOffset() + ((symbolTable->captureCount() - symbolTable->captureStart() - 1) * sizeof(WriteBarrier<Unknown>));
144}
145
146inline void JSActivation::tearOff(VM& vm)
147{
148 ASSERT(!isTornOff());
149
150 WriteBarrierBase<Unknown>* dst = reinterpret_cast_ptr<WriteBarrierBase<Unknown>*>(
151 reinterpret_cast<char*>(this) + registersOffset(symbolTable()));
152 WriteBarrierBase<Unknown>* src = m_registers;
153
154 int captureEnd = symbolTable()->captureEnd();
155 for (int i = symbolTable()->captureStart(); i > captureEnd; --i)
156 dst[i].set(vm, this, src[i].get());
157
158 m_registers = dst;
159 ASSERT(isTornOff());
160}
161
162inline bool JSActivation::isTornOff()
163{
164 return m_registers == reinterpret_cast_ptr<WriteBarrierBase<Unknown>*>(
165 reinterpret_cast<char*>(this) + registersOffset(symbolTable()));
166}
167
168inline size_t JSActivation::storageOffset()
169{
170 return WTF::roundUpToMultipleOf<sizeof(WriteBarrier<Unknown>)>(sizeof(JSActivation));
171}
172
173inline WriteBarrier<Unknown>* JSActivation::storage()
174{
175 return reinterpret_cast_ptr<WriteBarrier<Unknown>*>(
176 reinterpret_cast<char*>(this) + storageOffset());
177}
178
179inline size_t JSActivation::allocationSize(SymbolTable* symbolTable)
180{
181 size_t objectSizeInBytes = WTF::roundUpToMultipleOf<sizeof(WriteBarrier<Unknown>)>(sizeof(JSActivation));
182 size_t storageSizeInBytes = symbolTable->captureCount() * sizeof(WriteBarrier<Unknown>);
183 return objectSizeInBytes + storageSizeInBytes;
184}
185
186inline bool JSActivation::isValidIndex(int index) const
187{
188 if (index > symbolTable()->captureStart())
189 return false;
190 if (index <= symbolTable()->captureEnd())
191 return false;
192 return true;
193}
194
195inline bool JSActivation::isValid(const SymbolTableEntry& entry) const
196{
197 return isValidIndex(entry.getIndex());
198}
199
200inline WriteBarrierBase<Unknown>& JSActivation::registerAt(int index) const
201{
202 ASSERT(isValidIndex(index));
203 return Base::registerAt(index);
204}
6fe7ccc8 205
9dae56ea
A
206} // namespace JSC
207
208#endif // JSActivation_h