#ifndef IndexingHeader_h
#define IndexingHeader_h
#include "PropertyStorage.h"
namespace JSC {
class ArrayBuffer;
class Butterfly;
class LLIntOffsetsExtractor;
class Structure;
struct ArrayStorage;
class IndexingHeader {
public:
enum { maximumLength = 0x10000000 };
static ptrdiff_t offsetOfIndexingHeader() { return -static_cast<ptrdiff_t>(sizeof(IndexingHeader)); }
static ptrdiff_t offsetOfArrayBuffer() { return OBJECT_OFFSETOF(IndexingHeader, u.typedArray.buffer); }
static ptrdiff_t offsetOfPublicLength() { return OBJECT_OFFSETOF(IndexingHeader, u.lengths.publicLength); }
static ptrdiff_t offsetOfVectorLength() { return OBJECT_OFFSETOF(IndexingHeader, u.lengths.vectorLength); }
IndexingHeader()
{
u.lengths.publicLength = 0;
u.lengths.vectorLength = 0;
}
uint32_t vectorLength() const { return u.lengths.vectorLength; }
void setVectorLength(uint32_t length)
{
RELEASE_ASSERT(length <= maximumLength);
u.lengths.vectorLength = length;
}
uint32_t publicLength() const { return u.lengths.publicLength; }
void setPublicLength(uint32_t auxWord) { u.lengths.publicLength = auxWord; }
ArrayBuffer* arrayBuffer() { return u.typedArray.buffer; }
void setArrayBuffer(ArrayBuffer* buffer) { u.typedArray.buffer = buffer; }
static IndexingHeader* from(Butterfly* butterfly)
{
return reinterpret_cast<IndexingHeader*>(butterfly) - 1;
}
static const IndexingHeader* from(const Butterfly* butterfly)
{
return reinterpret_cast<const IndexingHeader*>(butterfly) - 1;
}
static IndexingHeader* from(ArrayStorage* arrayStorage)
{
return const_cast<IndexingHeader*>(from(const_cast<const ArrayStorage*>(arrayStorage)));
}
static const IndexingHeader* from(const ArrayStorage* arrayStorage)
{
return reinterpret_cast<const IndexingHeader*>(arrayStorage) - 1;
}
static IndexingHeader* fromEndOf(PropertyStorage propertyStorage)
{
return reinterpret_cast<IndexingHeader*>(propertyStorage);
}
PropertyStorage propertyStorage()
{
return reinterpret_cast_ptr<PropertyStorage>(this);
}
ConstPropertyStorage propertyStorage() const
{
return reinterpret_cast_ptr<ConstPropertyStorage>(this);
}
ArrayStorage* arrayStorage()
{
return reinterpret_cast<ArrayStorage*>(this + 1);
}
Butterfly* butterfly()
{
return reinterpret_cast<Butterfly*>(this + 1);
}
size_t preCapacity(Structure*);
size_t indexingPayloadSizeInBytes(Structure*);
private:
friend class LLIntOffsetsExtractor;
union {
struct {
uint32_t publicLength; uint32_t vectorLength; } lengths;
struct {
ArrayBuffer* buffer;
} typedArray;
} u;
};
}
#endif // IndexingHeader_h