]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
f9bf01c6 | 2 | * Copyright (C) 2008, 2009 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. | |
13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
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 | #include "config.h" | |
30 | #include "JSActivation.h" | |
31 | ||
32 | #include "Arguments.h" | |
33 | #include "Interpreter.h" | |
34 | #include "JSFunction.h" | |
93a37866 | 35 | #include "Operations.h" |
9dae56ea | 36 | |
6fe7ccc8 A |
37 | using namespace std; |
38 | ||
9dae56ea A |
39 | namespace JSC { |
40 | ||
6fe7ccc8 | 41 | const ClassInfo JSActivation::s_info = { "JSActivation", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSActivation) }; |
14957cd0 | 42 | |
6fe7ccc8 | 43 | void JSActivation::visitChildren(JSCell* cell, SlotVisitor& visitor) |
9dae56ea | 44 | { |
6fe7ccc8 A |
45 | JSActivation* thisObject = jsCast<JSActivation*>(cell); |
46 | ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info); | |
14957cd0 | 47 | COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag); |
6fe7ccc8 A |
48 | ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren()); |
49 | Base::visitChildren(thisObject, visitor); | |
9dae56ea | 50 | |
93a37866 A |
51 | // No need to mark our registers if they're still in the JSStack. |
52 | if (!thisObject->isTornOff()) | |
9dae56ea A |
53 | return; |
54 | ||
93a37866 A |
55 | for (int i = 0; i < thisObject->symbolTable()->captureCount(); ++i) |
56 | visitor.append(&thisObject->storage()[i]); | |
14957cd0 | 57 | } |
9dae56ea | 58 | |
93a37866 | 59 | inline bool JSActivation::symbolTableGet(PropertyName propertyName, PropertySlot& slot) |
14957cd0 | 60 | { |
93a37866 | 61 | SymbolTableEntry entry = symbolTable()->inlineGet(propertyName.publicName()); |
14957cd0 A |
62 | if (entry.isNull()) |
63 | return false; | |
93a37866 A |
64 | |
65 | // Defend against the inspector asking for a var after it has been optimized out. | |
66 | if (isTornOff() && !isValid(entry)) | |
14957cd0 | 67 | return false; |
9dae56ea | 68 | |
14957cd0 A |
69 | slot.setValue(registerAt(entry.getIndex()).get()); |
70 | return true; | |
9dae56ea A |
71 | } |
72 | ||
93a37866 | 73 | inline bool JSActivation::symbolTableGet(PropertyName propertyName, PropertyDescriptor& descriptor) |
9dae56ea | 74 | { |
93a37866 A |
75 | SymbolTableEntry entry = symbolTable()->inlineGet(propertyName.publicName()); |
76 | if (entry.isNull()) | |
77 | return false; | |
78 | ||
79 | // Defend against the inspector asking for a var after it has been optimized out. | |
80 | if (isTornOff() && !isValid(entry)) | |
81 | return false; | |
82 | ||
83 | descriptor.setDescriptor(registerAt(entry.getIndex()).get(), entry.getAttributes()); | |
84 | return true; | |
85 | } | |
86 | ||
87 | inline bool JSActivation::symbolTablePut(ExecState* exec, PropertyName propertyName, JSValue value, bool shouldThrow) | |
88 | { | |
89 | VM& vm = exec->vm(); | |
14957cd0 A |
90 | ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); |
91 | ||
93a37866 | 92 | SymbolTableEntry entry = symbolTable()->inlineGet(propertyName.publicName()); |
14957cd0 A |
93 | if (entry.isNull()) |
94 | return false; | |
6fe7ccc8 A |
95 | if (entry.isReadOnly()) { |
96 | if (shouldThrow) | |
97 | throwTypeError(exec, StrictModeReadonlyPropertyWriteError); | |
9dae56ea | 98 | return true; |
6fe7ccc8 | 99 | } |
93a37866 A |
100 | |
101 | // Defend against the inspector asking for a var after it has been optimized out. | |
102 | if (isTornOff() && !isValid(entry)) | |
14957cd0 | 103 | return false; |
9dae56ea | 104 | |
93a37866 | 105 | registerAt(entry.getIndex()).set(vm, this, value); |
14957cd0 A |
106 | return true; |
107 | } | |
108 | ||
93a37866 | 109 | void JSActivation::getOwnNonIndexPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) |
14957cd0 | 110 | { |
6fe7ccc8 | 111 | JSActivation* thisObject = jsCast<JSActivation*>(object); |
93a37866 A |
112 | |
113 | if (mode == IncludeDontEnumProperties && !thisObject->isTornOff()) | |
114 | propertyNames.add(exec->propertyNames().arguments); | |
115 | ||
116 | SymbolTable::const_iterator end = thisObject->symbolTable()->end(); | |
117 | for (SymbolTable::const_iterator it = thisObject->symbolTable()->begin(); it != end; ++it) { | |
118 | if (it->value.getAttributes() & DontEnum && mode != IncludeDontEnumProperties) | |
14957cd0 | 119 | continue; |
93a37866 | 120 | if (!thisObject->isValid(it->value)) |
14957cd0 | 121 | continue; |
93a37866 | 122 | propertyNames.add(Identifier(exec, it->key.get())); |
9dae56ea | 123 | } |
93a37866 A |
124 | // Skip the JSVariableObject implementation of getOwnNonIndexPropertyNames |
125 | JSObject::getOwnNonIndexPropertyNames(thisObject, exec, propertyNames, mode); | |
14957cd0 A |
126 | } |
127 | ||
93a37866 | 128 | inline bool JSActivation::symbolTablePutWithAttributes(VM& vm, PropertyName propertyName, JSValue value, unsigned attributes) |
14957cd0 A |
129 | { |
130 | ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); | |
131 | ||
93a37866 A |
132 | SymbolTable::iterator iter = symbolTable()->find(propertyName.publicName()); |
133 | if (iter == symbolTable()->end()) | |
14957cd0 | 134 | return false; |
93a37866 | 135 | SymbolTableEntry& entry = iter->value; |
14957cd0 | 136 | ASSERT(!entry.isNull()); |
93a37866 | 137 | if (!isValid(entry)) |
14957cd0 A |
138 | return false; |
139 | ||
140 | entry.setAttributes(attributes); | |
93a37866 | 141 | registerAt(entry.getIndex()).set(vm, this, value); |
14957cd0 A |
142 | return true; |
143 | } | |
9dae56ea | 144 | |
93a37866 | 145 | bool JSActivation::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot) |
14957cd0 | 146 | { |
6fe7ccc8 | 147 | JSActivation* thisObject = jsCast<JSActivation*>(cell); |
93a37866 | 148 | |
9dae56ea | 149 | if (propertyName == exec->propertyNames().arguments) { |
93a37866 A |
150 | // Defend against the inspector asking for the arguments object after it has been optimized out. |
151 | if (!thisObject->isTornOff()) { | |
152 | slot.setCustom(thisObject, thisObject->getArgumentsGetter()); | |
153 | return true; | |
154 | } | |
9dae56ea A |
155 | } |
156 | ||
6fe7ccc8 | 157 | if (thisObject->symbolTableGet(propertyName, slot)) |
14957cd0 A |
158 | return true; |
159 | ||
93a37866 A |
160 | if (JSValue value = thisObject->getDirect(exec->vm(), propertyName)) { |
161 | slot.setValue(value); | |
14957cd0 A |
162 | return true; |
163 | } | |
164 | ||
9dae56ea A |
165 | // We don't call through to JSObject because there's no way to give an |
166 | // activation object getter properties or a prototype. | |
6fe7ccc8 A |
167 | ASSERT(!thisObject->hasGetterSetterProperties()); |
168 | ASSERT(thisObject->prototype().isNull()); | |
9dae56ea A |
169 | return false; |
170 | } | |
171 | ||
93a37866 A |
172 | bool JSActivation::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor) |
173 | { | |
174 | JSActivation* thisObject = jsCast<JSActivation*>(object); | |
175 | ||
176 | if (propertyName == exec->propertyNames().arguments) { | |
177 | // Defend against the inspector asking for the arguments object after it has been optimized out. | |
178 | if (!thisObject->isTornOff()) { | |
179 | PropertySlot slot; | |
180 | JSActivation::getOwnPropertySlot(thisObject, exec, propertyName, slot); | |
181 | descriptor.setDescriptor(slot.getValue(exec, propertyName), DontEnum); | |
182 | return true; | |
183 | } | |
184 | } | |
185 | ||
186 | if (thisObject->symbolTableGet(propertyName, descriptor)) | |
187 | return true; | |
188 | ||
189 | return Base::getOwnPropertyDescriptor(object, exec, propertyName, descriptor); | |
190 | } | |
191 | ||
192 | void JSActivation::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot) | |
9dae56ea | 193 | { |
6fe7ccc8 A |
194 | JSActivation* thisObject = jsCast<JSActivation*>(cell); |
195 | ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject)); | |
9dae56ea | 196 | |
6fe7ccc8 | 197 | if (thisObject->symbolTablePut(exec, propertyName, value, slot.isStrictMode())) |
9dae56ea A |
198 | return; |
199 | ||
200 | // We don't call through to JSObject because __proto__ and getter/setter | |
201 | // properties are non-standard extensions that other implementations do not | |
202 | // expose in the activation object. | |
6fe7ccc8 | 203 | ASSERT(!thisObject->hasGetterSetterProperties()); |
93a37866 | 204 | thisObject->putOwnDataProperty(exec->vm(), propertyName, value, slot); |
9dae56ea A |
205 | } |
206 | ||
207 | // FIXME: Make this function honor ReadOnly (const) and DontEnum | |
93a37866 | 208 | void JSActivation::putDirectVirtual(JSObject* object, ExecState* exec, PropertyName propertyName, JSValue value, unsigned attributes) |
9dae56ea | 209 | { |
6fe7ccc8 A |
210 | JSActivation* thisObject = jsCast<JSActivation*>(object); |
211 | ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject)); | |
9dae56ea | 212 | |
93a37866 | 213 | if (thisObject->symbolTablePutWithAttributes(exec->vm(), propertyName, value, attributes)) |
9dae56ea A |
214 | return; |
215 | ||
216 | // We don't call through to JSObject because __proto__ and getter/setter | |
217 | // properties are non-standard extensions that other implementations do not | |
218 | // expose in the activation object. | |
6fe7ccc8 A |
219 | ASSERT(!thisObject->hasGetterSetterProperties()); |
220 | JSObject::putDirectVirtual(thisObject, exec, propertyName, value, attributes); | |
9dae56ea A |
221 | } |
222 | ||
93a37866 | 223 | bool JSActivation::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName) |
9dae56ea A |
224 | { |
225 | if (propertyName == exec->propertyNames().arguments) | |
226 | return false; | |
227 | ||
6fe7ccc8 | 228 | return Base::deleteProperty(cell, exec, propertyName); |
9dae56ea A |
229 | } |
230 | ||
6fe7ccc8 | 231 | JSObject* JSActivation::toThisObject(JSCell*, ExecState* exec) |
9dae56ea A |
232 | { |
233 | return exec->globalThisValue(); | |
234 | } | |
235 | ||
93a37866 | 236 | JSValue JSActivation::argumentsGetter(ExecState*, JSValue slotBase, PropertyName) |
9dae56ea | 237 | { |
93a37866 A |
238 | JSActivation* activation = jsCast<JSActivation*>(slotBase); |
239 | if (activation->isTornOff()) | |
240 | return jsUndefined(); | |
241 | ||
14957cd0 | 242 | CallFrame* callFrame = CallFrame::create(reinterpret_cast<Register*>(activation->m_registers)); |
93a37866 | 243 | int argumentsRegister = callFrame->codeBlock()->argumentsRegister(); |
14957cd0 A |
244 | if (JSValue arguments = callFrame->uncheckedR(argumentsRegister).jsValue()) |
245 | return arguments; | |
246 | int realArgumentsRegister = unmodifiedArgumentsRegister(argumentsRegister); | |
247 | ||
93a37866 | 248 | JSValue arguments = JSValue(Arguments::create(callFrame->vm(), callFrame)); |
14957cd0 A |
249 | callFrame->uncheckedR(argumentsRegister) = arguments; |
250 | callFrame->uncheckedR(realArgumentsRegister) = arguments; | |
251 | ||
252 | ASSERT(callFrame->uncheckedR(realArgumentsRegister).jsValue().inherits(&Arguments::s_info)); | |
253 | return callFrame->uncheckedR(realArgumentsRegister).jsValue(); | |
9dae56ea A |
254 | } |
255 | ||
256 | // These two functions serve the purpose of isolating the common case from a | |
257 | // PIC branch. | |
258 | ||
259 | PropertySlot::GetValueFunc JSActivation::getArgumentsGetter() | |
260 | { | |
261 | return argumentsGetter; | |
262 | } | |
263 | ||
264 | } // namespace JSC |