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