1 | /*
|
---|
2 | * Copyright (C) 2008 Apple Inc. All rights reserved.
|
---|
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 "CodeBlock.h"
|
---|
34 | #include "Machine.h"
|
---|
35 | #include "Register.h"
|
---|
36 | #include "JSFunction.h"
|
---|
37 |
|
---|
38 | namespace JSC {
|
---|
39 |
|
---|
40 | ASSERT_CLASS_FITS_IN_CELL(JSActivation);
|
---|
41 |
|
---|
42 | const ClassInfo JSActivation::info = { "JSActivation", 0, 0, 0 };
|
---|
43 |
|
---|
44 | JSActivation::JSActivation(ExecState* exec, PassRefPtr<FunctionBodyNode> functionBody, Register* registers)
|
---|
45 | : Base(exec->globalData().nullProtoStructureID, new JSActivationData(functionBody, registers))
|
---|
46 | {
|
---|
47 | }
|
---|
48 |
|
---|
49 | JSActivation::~JSActivation()
|
---|
50 | {
|
---|
51 | delete d();
|
---|
52 | }
|
---|
53 |
|
---|
54 | void JSActivation::copyRegisters()
|
---|
55 | {
|
---|
56 | int numLocals = d()->functionBody->generatedByteCode().numLocals;
|
---|
57 | if (!numLocals)
|
---|
58 | return;
|
---|
59 |
|
---|
60 | copyRegisterArray(d()->registers - numLocals, numLocals);
|
---|
61 | }
|
---|
62 |
|
---|
63 | bool JSActivation::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
|
---|
64 | {
|
---|
65 | if (symbolTableGet(propertyName, slot))
|
---|
66 | return true;
|
---|
67 |
|
---|
68 | if (JSValue** location = getDirectLocation(propertyName)) {
|
---|
69 | slot.setValueSlot(location);
|
---|
70 | return true;
|
---|
71 | }
|
---|
72 |
|
---|
73 | // Only return the built-in arguments object if it wasn't overridden above.
|
---|
74 | if (propertyName == exec->propertyNames().arguments) {
|
---|
75 | slot.setCustom(this, getArgumentsGetter());
|
---|
76 | return true;
|
---|
77 | }
|
---|
78 |
|
---|
79 | // We don't call through to JSObject because there's no way to give an
|
---|
80 | // activation object getter properties or a prototype.
|
---|
81 | ASSERT(!hasGetterSetterProperties());
|
---|
82 | ASSERT(prototype()->isNull());
|
---|
83 | return false;
|
---|
84 | }
|
---|
85 |
|
---|
86 | void JSActivation::put(ExecState*, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
|
---|
87 | {
|
---|
88 | ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
|
---|
89 |
|
---|
90 | if (symbolTablePut(propertyName, value))
|
---|
91 | return;
|
---|
92 |
|
---|
93 | // We don't call through to JSObject because __proto__ and getter/setter
|
---|
94 | // properties are non-standard extensions that other implementations do not
|
---|
95 | // expose in the activation object.
|
---|
96 | ASSERT(!hasGetterSetterProperties());
|
---|
97 | putDirect(propertyName, value, 0, true, slot);
|
---|
98 | }
|
---|
99 |
|
---|
100 | // FIXME: Make this function honor ReadOnly (const) and DontEnum
|
---|
101 | void JSActivation::putWithAttributes(ExecState*, const Identifier& propertyName, JSValue* value, unsigned attributes)
|
---|
102 | {
|
---|
103 | ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
|
---|
104 |
|
---|
105 | if (symbolTablePutWithAttributes(propertyName, value, attributes))
|
---|
106 | return;
|
---|
107 |
|
---|
108 | // We don't call through to JSObject because __proto__ and getter/setter
|
---|
109 | // properties are non-standard extensions that other implementations do not
|
---|
110 | // expose in the activation object.
|
---|
111 | ASSERT(!hasGetterSetterProperties());
|
---|
112 | PutPropertySlot slot;
|
---|
113 | putDirect(propertyName, value, attributes, true, slot);
|
---|
114 | }
|
---|
115 |
|
---|
116 | bool JSActivation::deleteProperty(ExecState* exec, const Identifier& propertyName)
|
---|
117 | {
|
---|
118 | if (propertyName == exec->propertyNames().arguments)
|
---|
119 | return false;
|
---|
120 |
|
---|
121 | return Base::deleteProperty(exec, propertyName);
|
---|
122 | }
|
---|
123 |
|
---|
124 | JSObject* JSActivation::toThisObject(ExecState* exec) const
|
---|
125 | {
|
---|
126 | return exec->globalThisValue();
|
---|
127 | }
|
---|
128 |
|
---|
129 | void JSActivation::mark()
|
---|
130 | {
|
---|
131 | Base::mark();
|
---|
132 |
|
---|
133 | if (d()->argumentsObject)
|
---|
134 | d()->argumentsObject->mark();
|
---|
135 | }
|
---|
136 |
|
---|
137 | bool JSActivation::isActivationObject() const
|
---|
138 | {
|
---|
139 | return true;
|
---|
140 | }
|
---|
141 |
|
---|
142 | bool JSActivation::isDynamicScope() const
|
---|
143 | {
|
---|
144 | return d()->functionBody->usesEval();
|
---|
145 | }
|
---|
146 |
|
---|
147 | JSValue* JSActivation::argumentsGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
|
---|
148 | {
|
---|
149 | JSActivation* thisObj = static_cast<JSActivation*>(slot.slotBase());
|
---|
150 | if (!thisObj->d()->argumentsObject)
|
---|
151 | thisObj->d()->argumentsObject = thisObj->createArgumentsObject(exec);
|
---|
152 |
|
---|
153 | return thisObj->d()->argumentsObject;
|
---|
154 | }
|
---|
155 |
|
---|
156 | // These two functions serve the purpose of isolating the common case from a
|
---|
157 | // PIC branch.
|
---|
158 |
|
---|
159 | PropertySlot::GetValueFunc JSActivation::getArgumentsGetter()
|
---|
160 | {
|
---|
161 | return argumentsGetter;
|
---|
162 | }
|
---|
163 |
|
---|
164 | JSObject* JSActivation::createArgumentsObject(ExecState* exec)
|
---|
165 | {
|
---|
166 | Register* callFrame = d()->registers - d()->functionBody->generatedByteCode().numLocals - RegisterFile::CallFrameHeaderSize;
|
---|
167 |
|
---|
168 | JSFunction* function;
|
---|
169 | Register* argv;
|
---|
170 | int argc;
|
---|
171 | exec->machine()->getArgumentsData(callFrame, function, argv, argc);
|
---|
172 |
|
---|
173 | ArgList args(argv, argc);
|
---|
174 | return new (exec) Arguments(exec, function, args, this);
|
---|
175 | }
|
---|
176 |
|
---|
177 | } // namespace JSC
|
---|