]>
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. | |
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 | #include "config.h" | |
30 | #include "JSActivation.h" | |
31 | ||
32 | #include "Arguments.h" | |
33 | #include "Interpreter.h" | |
34 | #include "JSFunction.h" | |
81345200 | 35 | #include "JSCInlines.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 | 45 | JSActivation* thisObject = jsCast<JSActivation*>(cell); |
81345200 | 46 | ASSERT_GC_OBJECT_INHERITS(thisObject, 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 | { |
81345200 | 61 | SymbolTableEntry entry = symbolTable()->inlineGet(propertyName.uid()); |
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 | |
81345200 | 69 | slot.setValue(this, DontEnum, registerAt(entry.getIndex()).get()); |
14957cd0 | 70 | return true; |
9dae56ea A |
71 | } |
72 | ||
93a37866 | 73 | inline bool JSActivation::symbolTableGet(PropertyName propertyName, PropertyDescriptor& descriptor) |
9dae56ea | 74 | { |
81345200 | 75 | SymbolTableEntry entry = symbolTable()->inlineGet(propertyName.uid()); |
93a37866 A |
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 | ||
81345200 A |
92 | WriteBarrierBase<Unknown>* reg; |
93 | { | |
94 | GCSafeConcurrentJITLocker locker(symbolTable()->m_lock, exec->vm().heap); | |
95 | SymbolTable::Map::iterator iter = symbolTable()->find(locker, propertyName.uid()); | |
96 | if (iter == symbolTable()->end(locker)) | |
97 | return false; | |
98 | ASSERT(!iter->value.isNull()); | |
99 | if (iter->value.isReadOnly()) { | |
100 | if (shouldThrow) | |
101 | throwTypeError(exec, StrictModeReadonlyPropertyWriteError); | |
102 | return true; | |
103 | } | |
104 | // Defend against the inspector asking for a var after it has been optimized out. | |
105 | if (isTornOff() && !isValid(iter->value)) | |
106 | return false; | |
107 | if (VariableWatchpointSet* set = iter->value.watchpointSet()) | |
108 | set->invalidate(); // Don't mess around - if we had found this statically, we would have invcalidated it. | |
109 | reg = ®isterAt(iter->value.getIndex()); | |
6fe7ccc8 | 110 | } |
81345200 | 111 | reg->set(vm, this, value); |
14957cd0 A |
112 | return true; |
113 | } | |
114 | ||
93a37866 | 115 | void JSActivation::getOwnNonIndexPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) |
14957cd0 | 116 | { |
6fe7ccc8 | 117 | JSActivation* thisObject = jsCast<JSActivation*>(object); |
93a37866 | 118 | |
81345200 A |
119 | CallFrame* callFrame = CallFrame::create(reinterpret_cast<Register*>(thisObject->m_registers)); |
120 | if (mode == IncludeDontEnumProperties && !thisObject->isTornOff() && (callFrame->codeBlock()->usesArguments() || callFrame->codeBlock()->usesEval())) | |
93a37866 A |
121 | propertyNames.add(exec->propertyNames().arguments); |
122 | ||
81345200 A |
123 | { |
124 | ConcurrentJITLocker locker(thisObject->symbolTable()->m_lock); | |
125 | SymbolTable::Map::iterator end = thisObject->symbolTable()->end(locker); | |
126 | for (SymbolTable::Map::iterator it = thisObject->symbolTable()->begin(locker); it != end; ++it) { | |
127 | if (it->value.getAttributes() & DontEnum && mode != IncludeDontEnumProperties) | |
128 | continue; | |
129 | if (!thisObject->isValid(it->value)) | |
130 | continue; | |
131 | propertyNames.add(Identifier(exec, it->key.get())); | |
132 | } | |
9dae56ea | 133 | } |
93a37866 A |
134 | // Skip the JSVariableObject implementation of getOwnNonIndexPropertyNames |
135 | JSObject::getOwnNonIndexPropertyNames(thisObject, exec, propertyNames, mode); | |
14957cd0 A |
136 | } |
137 | ||
93a37866 | 138 | inline bool JSActivation::symbolTablePutWithAttributes(VM& vm, PropertyName propertyName, JSValue value, unsigned attributes) |
14957cd0 A |
139 | { |
140 | ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); | |
141 | ||
81345200 A |
142 | WriteBarrierBase<Unknown>* reg; |
143 | { | |
144 | ConcurrentJITLocker locker(symbolTable()->m_lock); | |
145 | SymbolTable::Map::iterator iter = symbolTable()->find(locker, propertyName.uid()); | |
146 | if (iter == symbolTable()->end(locker)) | |
147 | return false; | |
148 | SymbolTableEntry& entry = iter->value; | |
149 | ASSERT(!entry.isNull()); | |
150 | if (!isValid(entry)) | |
151 | return false; | |
152 | ||
153 | entry.setAttributes(attributes); | |
154 | reg = ®isterAt(entry.getIndex()); | |
155 | } | |
156 | reg->set(vm, this, value); | |
14957cd0 A |
157 | return true; |
158 | } | |
9dae56ea | 159 | |
81345200 | 160 | bool JSActivation::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot) |
14957cd0 | 161 | { |
81345200 | 162 | JSActivation* thisObject = jsCast<JSActivation*>(object); |
93a37866 | 163 | |
9dae56ea | 164 | if (propertyName == exec->propertyNames().arguments) { |
93a37866 | 165 | // Defend against the inspector asking for the arguments object after it has been optimized out. |
81345200 A |
166 | CallFrame* callFrame = CallFrame::create(reinterpret_cast<Register*>(thisObject->m_registers)); |
167 | if (!thisObject->isTornOff() && (callFrame->codeBlock()->usesArguments() || callFrame->codeBlock()->usesEval())) { | |
168 | slot.setCustom(thisObject, DontEnum, argumentsGetter); | |
93a37866 A |
169 | return true; |
170 | } | |
9dae56ea A |
171 | } |
172 | ||
6fe7ccc8 | 173 | if (thisObject->symbolTableGet(propertyName, slot)) |
14957cd0 A |
174 | return true; |
175 | ||
81345200 A |
176 | unsigned attributes; |
177 | if (JSValue value = thisObject->getDirect(exec->vm(), propertyName, attributes)) { | |
178 | slot.setValue(thisObject, attributes, value); | |
14957cd0 A |
179 | return true; |
180 | } | |
181 | ||
9dae56ea A |
182 | // We don't call through to JSObject because there's no way to give an |
183 | // activation object getter properties or a prototype. | |
6fe7ccc8 A |
184 | ASSERT(!thisObject->hasGetterSetterProperties()); |
185 | ASSERT(thisObject->prototype().isNull()); | |
9dae56ea A |
186 | return false; |
187 | } | |
188 | ||
93a37866 | 189 | void JSActivation::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot) |
9dae56ea | 190 | { |
6fe7ccc8 A |
191 | JSActivation* thisObject = jsCast<JSActivation*>(cell); |
192 | ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject)); | |
9dae56ea | 193 | |
6fe7ccc8 | 194 | if (thisObject->symbolTablePut(exec, propertyName, value, slot.isStrictMode())) |
9dae56ea A |
195 | return; |
196 | ||
197 | // We don't call through to JSObject because __proto__ and getter/setter | |
198 | // properties are non-standard extensions that other implementations do not | |
199 | // expose in the activation object. | |
6fe7ccc8 | 200 | ASSERT(!thisObject->hasGetterSetterProperties()); |
93a37866 | 201 | thisObject->putOwnDataProperty(exec->vm(), propertyName, value, slot); |
9dae56ea A |
202 | } |
203 | ||
93a37866 | 204 | bool JSActivation::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName) |
9dae56ea A |
205 | { |
206 | if (propertyName == exec->propertyNames().arguments) | |
207 | return false; | |
208 | ||
6fe7ccc8 | 209 | return Base::deleteProperty(cell, exec, propertyName); |
9dae56ea A |
210 | } |
211 | ||
81345200 | 212 | JSValue JSActivation::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode) |
9dae56ea | 213 | { |
81345200 A |
214 | if (ecmaMode == StrictMode) |
215 | return jsUndefined(); | |
9dae56ea A |
216 | return exec->globalThisValue(); |
217 | } | |
218 | ||
81345200 | 219 | EncodedJSValue JSActivation::argumentsGetter(ExecState*, JSObject* slotBase, EncodedJSValue, PropertyName) |
9dae56ea | 220 | { |
93a37866 | 221 | JSActivation* activation = jsCast<JSActivation*>(slotBase); |
14957cd0 | 222 | CallFrame* callFrame = CallFrame::create(reinterpret_cast<Register*>(activation->m_registers)); |
81345200 A |
223 | ASSERT(!activation->isTornOff() && (callFrame->codeBlock()->usesArguments() || callFrame->codeBlock()->usesEval())); |
224 | if (activation->isTornOff() || !(callFrame->codeBlock()->usesArguments() || callFrame->codeBlock()->usesEval())) | |
225 | return JSValue::encode(jsUndefined()); | |
226 | ||
227 | VirtualRegister argumentsRegister = callFrame->codeBlock()->argumentsRegister(); | |
228 | if (JSValue arguments = callFrame->uncheckedR(argumentsRegister.offset()).jsValue()) | |
229 | return JSValue::encode(arguments); | |
230 | int realArgumentsRegister = unmodifiedArgumentsRegister(argumentsRegister).offset(); | |
14957cd0 | 231 | |
93a37866 | 232 | JSValue arguments = JSValue(Arguments::create(callFrame->vm(), callFrame)); |
81345200 | 233 | callFrame->uncheckedR(argumentsRegister.offset()) = arguments; |
14957cd0 A |
234 | callFrame->uncheckedR(realArgumentsRegister) = arguments; |
235 | ||
81345200 A |
236 | ASSERT(callFrame->uncheckedR(realArgumentsRegister).jsValue().inherits(Arguments::info())); |
237 | return JSValue::encode(callFrame->uncheckedR(realArgumentsRegister).jsValue()); | |
9dae56ea A |
238 | } |
239 | ||
240 | } // namespace JSC |