]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/JSActivation.cpp
2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
30 #include "JSActivation.h"
32 #include "Arguments.h"
33 #include "Interpreter.h"
34 #include "JSFunction.h"
38 ASSERT_CLASS_FITS_IN_CELL(JSActivation
);
40 const ClassInfo
JSActivation::info
= { "JSActivation", 0, 0, 0 };
42 JSActivation::JSActivation(CallFrame
* callFrame
, NonNullPassRefPtr
<FunctionExecutable
> functionExecutable
)
43 : Base(callFrame
->globalData().activationStructure
, new JSActivationData(functionExecutable
, callFrame
->registers()))
47 JSActivation::~JSActivation()
52 void JSActivation::markChildren(MarkStack
& markStack
)
54 Base::markChildren(markStack
);
56 Register
* registerArray
= d()->registerArray
.get();
60 size_t numParametersMinusThis
= d()->functionExecutable
->parameterCount();
62 size_t count
= numParametersMinusThis
;
63 markStack
.appendValues(registerArray
, count
);
65 size_t numVars
= d()->functionExecutable
->variableCount();
67 // Skip the call frame, which sits between the parameters and vars.
68 markStack
.appendValues(registerArray
+ count
+ RegisterFile::CallFrameHeaderSize
, numVars
, MayContainNullValues
);
71 bool JSActivation::getOwnPropertySlot(ExecState
* exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
73 if (symbolTableGet(propertyName
, slot
))
76 if (JSValue
* location
= getDirectLocation(propertyName
)) {
77 slot
.setValueSlot(location
);
81 // Only return the built-in arguments object if it wasn't overridden above.
82 if (propertyName
== exec
->propertyNames().arguments
) {
83 slot
.setCustom(this, getArgumentsGetter());
87 // We don't call through to JSObject because there's no way to give an
88 // activation object getter properties or a prototype.
89 ASSERT(!hasGetterSetterProperties());
90 ASSERT(prototype().isNull());
94 void JSActivation::put(ExecState
*, const Identifier
& propertyName
, JSValue value
, PutPropertySlot
& slot
)
96 ASSERT(!Heap::heap(value
) || Heap::heap(value
) == Heap::heap(this));
98 if (symbolTablePut(propertyName
, value
))
101 // We don't call through to JSObject because __proto__ and getter/setter
102 // properties are non-standard extensions that other implementations do not
103 // expose in the activation object.
104 ASSERT(!hasGetterSetterProperties());
105 putDirect(propertyName
, value
, 0, true, slot
);
108 // FIXME: Make this function honor ReadOnly (const) and DontEnum
109 void JSActivation::putWithAttributes(ExecState
* exec
, const Identifier
& propertyName
, JSValue value
, unsigned attributes
)
111 ASSERT(!Heap::heap(value
) || Heap::heap(value
) == Heap::heap(this));
113 if (symbolTablePutWithAttributes(propertyName
, value
, attributes
))
116 // We don't call through to JSObject because __proto__ and getter/setter
117 // properties are non-standard extensions that other implementations do not
118 // expose in the activation object.
119 ASSERT(!hasGetterSetterProperties());
120 PutPropertySlot slot
;
121 JSObject::putWithAttributes(exec
, propertyName
, value
, attributes
, true, slot
);
124 bool JSActivation::deleteProperty(ExecState
* exec
, const Identifier
& propertyName
)
126 if (propertyName
== exec
->propertyNames().arguments
)
129 return Base::deleteProperty(exec
, propertyName
);
132 JSObject
* JSActivation::toThisObject(ExecState
* exec
) const
134 return exec
->globalThisValue();
137 bool JSActivation::isDynamicScope() const
139 return d()->functionExecutable
->usesEval();
142 JSValue
JSActivation::argumentsGetter(ExecState
* exec
, const Identifier
&, const PropertySlot
& slot
)
144 JSActivation
* activation
= asActivation(slot
.slotBase());
146 if (activation
->d()->functionExecutable
->usesArguments()) {
148 activation
->symbolTableGet(exec
->propertyNames().arguments
, slot
);
149 return slot
.getValue(exec
, exec
->propertyNames().arguments
);
152 CallFrame
* callFrame
= CallFrame::create(activation
->d()->registers
);
153 Arguments
* arguments
= callFrame
->optionalCalleeArguments();
155 arguments
= new (callFrame
) Arguments(callFrame
);
156 arguments
->copyRegisters();
157 callFrame
->setCalleeArguments(arguments
);
159 ASSERT(arguments
->inherits(&Arguments::info
));
164 // These two functions serve the purpose of isolating the common case from a
167 PropertySlot::GetValueFunc
JSActivation::getArgumentsGetter()
169 return argumentsGetter
;