JSEnvironmentRecord.h [plain text]
#ifndef JSEnvironmentRecord_h
#define JSEnvironmentRecord_h
#include "JSObject.h"
#include "JSSymbolTableObject.h"
#include "Register.h"
#include "SymbolTable.h"
namespace JSC {
class LLIntOffsetsExtractor;
class Register;
class JSEnvironmentRecord : public JSSymbolTableObject {
friend class JIT;
friend class LLIntOffsetsExtractor;
public:
typedef JSSymbolTableObject Base;
static const unsigned StructureFlags = Base::StructureFlags;
WriteBarrierBase<Unknown>* variables()
{
return bitwise_cast<WriteBarrierBase<Unknown>*>(bitwise_cast<char*>(this) + offsetOfVariables());
}
bool isValidScopeOffset(ScopeOffset offset)
{
return !!offset && offset.offset() < symbolTable()->scopeSize();
}
WriteBarrierBase<Unknown>& variableAt(ScopeOffset offset)
{
ASSERT(isValidScopeOffset(offset));
return variables()[offset.offset()];
}
static size_t offsetOfVariables()
{
return WTF::roundUpToMultipleOf<sizeof(WriteBarrier<Unknown>)>(sizeof(JSEnvironmentRecord));
}
static ptrdiff_t offsetOfVariable(ScopeOffset offset)
{
return offsetOfVariables() + offset.offset() * sizeof(WriteBarrier<Unknown>);
}
DECLARE_INFO;
static size_t allocationSizeForScopeSize(unsigned scopeSize)
{
return offsetOfVariables() + scopeSize * sizeof(WriteBarrier<Unknown>);
}
static size_t allocationSize(SymbolTable* symbolTable)
{
return allocationSizeForScopeSize(symbolTable->scopeSize());
}
protected:
JSEnvironmentRecord(
VM& vm,
Structure* structure,
JSScope* scope,
SymbolTable* symbolTable)
: Base(vm, structure, scope, symbolTable)
{
}
void finishCreationUninitialized(VM& vm)
{
Base::finishCreation(vm);
}
void finishCreation(VM& vm, JSValue value)
{
finishCreationUninitialized(vm);
ASSERT(value == jsUndefined() || value == jsTDZValue());
for (unsigned i = symbolTable()->scopeSize(); i--;) {
variableAt(ScopeOffset(i)).setStartingValue(value);
}
}
static void visitChildren(JSCell*, SlotVisitor&);
static void heapSnapshot(JSCell*, HeapSnapshotBuilder&);
};
}
#endif // JSEnvironmentRecord_h