#ifndef ScopedArguments_h
#define ScopedArguments_h
#include "GenericArguments.h"
#include "JSLexicalEnvironment.h"
namespace JSC {
class ScopedArguments : public GenericArguments<ScopedArguments> {
private:
ScopedArguments(VM&, Structure*, unsigned totalLength);
void finishCreation(VM&, JSFunction* callee, ScopedArgumentsTable*, JSLexicalEnvironment*);
public:
static ScopedArguments* createUninitialized(VM&, Structure*, JSFunction* callee, ScopedArgumentsTable*, JSLexicalEnvironment*, unsigned totalLength);
static ScopedArguments* create(VM&, Structure*, JSFunction* callee, ScopedArgumentsTable*, JSLexicalEnvironment*, unsigned totalLength);
static ScopedArguments* createByCopying(ExecState*, ScopedArgumentsTable*, JSLexicalEnvironment*);
static ScopedArguments* createByCopyingFrom(VM&, Structure*, Register* argumentsStart, unsigned totalLength, JSFunction* callee, ScopedArgumentsTable*, JSLexicalEnvironment*);
static void visitChildren(JSCell*, SlotVisitor&);
uint32_t internalLength() const
{
return m_totalLength;
}
uint32_t length(ExecState* exec) const
{
if (UNLIKELY(m_overrodeThings))
return get(exec, exec->propertyNames().length).toUInt32(exec);
return internalLength();
}
bool canAccessIndexQuickly(uint32_t i) const
{
if (i >= m_totalLength)
return false;
unsigned namedLength = m_table->length();
if (i < namedLength)
return !!m_table->get(i);
return !!overflowStorage()[i - namedLength].get();
}
bool canAccessArgumentIndexQuicklyInDFG(uint32_t i) const
{
return canAccessIndexQuickly(i);
}
JSValue getIndexQuickly(uint32_t i) const
{
ASSERT_WITH_SECURITY_IMPLICATION(canAccessIndexQuickly(i));
unsigned namedLength = m_table->length();
if (i < namedLength)
return m_scope->variableAt(m_table->get(i)).get();
return overflowStorage()[i - namedLength].get();
}
void setIndexQuickly(VM& vm, uint32_t i, JSValue value)
{
ASSERT_WITH_SECURITY_IMPLICATION(canAccessIndexQuickly(i));
unsigned namedLength = m_table->length();
if (i < namedLength)
m_scope->variableAt(m_table->get(i)).set(vm, this, value);
else
overflowStorage()[i - namedLength].set(vm, this, value);
}
WriteBarrier<JSFunction>& callee()
{
return m_callee;
}
bool overrodeThings() const { return m_overrodeThings; }
void overrideThings(VM&);
void overrideThingsIfNecessary(VM&);
void overrideArgument(VM&, uint32_t index);
void copyToArguments(ExecState*, VirtualRegister firstElementDest, unsigned offset, unsigned length);
DECLARE_INFO;
static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
static ptrdiff_t offsetOfOverrodeThings() { return OBJECT_OFFSETOF(ScopedArguments, m_overrodeThings); }
static ptrdiff_t offsetOfTotalLength() { return OBJECT_OFFSETOF(ScopedArguments, m_totalLength); }
static ptrdiff_t offsetOfTable() { return OBJECT_OFFSETOF(ScopedArguments, m_table); }
static ptrdiff_t offsetOfScope() { return OBJECT_OFFSETOF(ScopedArguments, m_scope); }
static size_t overflowStorageOffset()
{
return WTF::roundUpToMultipleOf<sizeof(WriteBarrier<Unknown>)>(sizeof(ScopedArguments));
}
static size_t allocationSize(unsigned overflowArgumentsLength)
{
return overflowStorageOffset() + sizeof(WriteBarrier<Unknown>) * overflowArgumentsLength;
}
private:
WriteBarrier<Unknown>* overflowStorage() const
{
return bitwise_cast<WriteBarrier<Unknown>*>(
bitwise_cast<char*>(this) + overflowStorageOffset());
}
bool m_overrodeThings; unsigned m_totalLength; WriteBarrier<JSFunction> m_callee;
WriteBarrier<ScopedArgumentsTable> m_table;
WriteBarrier<JSLexicalEnvironment> m_scope;
};
}
#endif // ScopedArguments_h