#include "config.h"
#include "JSActivation.h"
#include "Arguments.h"
#include "Interpreter.h"
#include "JSFunction.h"
namespace JSC {
ASSERT_CLASS_FITS_IN_CELL(JSActivation);
const ClassInfo JSActivation::s_info = { "JSActivation", &Base::s_info, 0, 0 };
JSActivation::JSActivation(CallFrame* callFrame, FunctionExecutable* functionExecutable)
: Base(callFrame->globalData(), callFrame->globalData().activationStructure.get(), functionExecutable->symbolTable(), callFrame->registers())
, m_numParametersMinusThis(static_cast<int>(functionExecutable->parameterCount()))
, m_numCapturedVars(functionExecutable->capturedVariableCount())
, m_requiresDynamicChecks(functionExecutable->usesEval())
, m_argumentsRegister(functionExecutable->generatedBytecode().argumentsRegister())
{
ASSERT(inherits(&s_info));
static_cast<SharedSymbolTable*>(m_symbolTable)->ref();
}
JSActivation::~JSActivation()
{
static_cast<SharedSymbolTable*>(m_symbolTable)->deref();
}
void JSActivation::visitChildren(SlotVisitor& visitor)
{
ASSERT_GC_OBJECT_INHERITS(this, &s_info);
COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
ASSERT(structure()->typeInfo().overridesVisitChildren());
Base::visitChildren(visitor);
WriteBarrier<Unknown>* registerArray = m_registerArray.get();
if (!registerArray)
return;
visitor.appendValues(registerArray, m_numParametersMinusThis);
visitor.appendValues(registerArray + m_numParametersMinusThis + RegisterFile::CallFrameHeaderSize, m_numCapturedVars);
}
inline bool JSActivation::symbolTableGet(const Identifier& propertyName, PropertySlot& slot)
{
SymbolTableEntry entry = symbolTable().inlineGet(propertyName.impl());
if (entry.isNull())
return false;
if (entry.getIndex() >= m_numCapturedVars)
return false;
slot.setValue(registerAt(entry.getIndex()).get());
return true;
}
inline bool JSActivation::symbolTablePut(JSGlobalData& globalData, const Identifier& propertyName, JSValue value)
{
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
SymbolTableEntry entry = symbolTable().inlineGet(propertyName.impl());
if (entry.isNull())
return false;
if (entry.isReadOnly())
return true;
if (entry.getIndex() >= m_numCapturedVars)
return false;
registerAt(entry.getIndex()).set(globalData, this, value);
return true;
}
void JSActivation::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
SymbolTable::const_iterator end = symbolTable().end();
for (SymbolTable::const_iterator it = symbolTable().begin(); it != end; ++it) {
if (it->second.getAttributes() & DontEnum && mode != IncludeDontEnumProperties)
continue;
if (it->second.getIndex() >= m_numCapturedVars)
continue;
propertyNames.add(Identifier(exec, it->first.get()));
}
JSObject::getOwnPropertyNames(exec, propertyNames, mode);
}
inline bool JSActivation::symbolTablePutWithAttributes(JSGlobalData& globalData, const Identifier& propertyName, JSValue value, unsigned attributes)
{
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
SymbolTable::iterator iter = symbolTable().find(propertyName.impl());
if (iter == symbolTable().end())
return false;
SymbolTableEntry& entry = iter->second;
ASSERT(!entry.isNull());
if (entry.getIndex() >= m_numCapturedVars)
return false;
entry.setAttributes(attributes);
registerAt(entry.getIndex()).set(globalData, this, value);
return true;
}
bool JSActivation::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
if (propertyName == exec->propertyNames().arguments) {
slot.setCustom(this, getArgumentsGetter());
return true;
}
if (symbolTableGet(propertyName, slot))
return true;
if (WriteBarrierBase<Unknown>* location = getDirectLocation(exec->globalData(), propertyName)) {
slot.setValue(location->get());
return true;
}
ASSERT(!hasGetterSetterProperties());
ASSERT(prototype().isNull());
return false;
}
void JSActivation::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
{
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
if (symbolTablePut(exec->globalData(), propertyName, value))
return;
ASSERT(!hasGetterSetterProperties());
putDirect(exec->globalData(), propertyName, value, 0, true, slot);
}
void JSActivation::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
{
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
if (symbolTablePutWithAttributes(exec->globalData(), propertyName, value, attributes))
return;
ASSERT(!hasGetterSetterProperties());
PutPropertySlot slot;
JSObject::putWithAttributes(exec, propertyName, value, attributes, true, slot);
}
bool JSActivation::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
if (propertyName == exec->propertyNames().arguments)
return false;
return Base::deleteProperty(exec, propertyName);
}
JSObject* JSActivation::toThisObject(ExecState* exec) const
{
return exec->globalThisValue();
}
JSValue JSActivation::toStrictThisObject(ExecState*) const
{
return jsNull();
}
bool JSActivation::isDynamicScope(bool& requiresDynamicChecks) const
{
requiresDynamicChecks = m_requiresDynamicChecks;
return false;
}
JSValue JSActivation::argumentsGetter(ExecState*, JSValue slotBase, const Identifier&)
{
JSActivation* activation = asActivation(slotBase);
CallFrame* callFrame = CallFrame::create(reinterpret_cast<Register*>(activation->m_registers));
int argumentsRegister = activation->m_argumentsRegister;
if (JSValue arguments = callFrame->uncheckedR(argumentsRegister).jsValue())
return arguments;
int realArgumentsRegister = unmodifiedArgumentsRegister(argumentsRegister);
JSValue arguments = JSValue(Arguments::create(callFrame->globalData(), callFrame));
callFrame->uncheckedR(argumentsRegister) = arguments;
callFrame->uncheckedR(realArgumentsRegister) = arguments;
ASSERT(callFrame->uncheckedR(realArgumentsRegister).jsValue().inherits(&Arguments::s_info));
return callFrame->uncheckedR(realArgumentsRegister).jsValue();
}
PropertySlot::GetValueFunc JSActivation::getArgumentsGetter()
{
return argumentsGetter;
}
}