#pragma once
#include "JSType.h"
namespace JSC {
class LLIntOffsetsExtractor;
static const unsigned MasqueradesAsUndefined = 1; static const unsigned ImplementsDefaultHasInstance = 1 << 1;
static const unsigned OverridesGetCallData = 1 << 2; static const unsigned OverridesGetOwnPropertySlot = 1 << 3;
static const unsigned OverridesToThis = 1 << 4; static const unsigned HasStaticPropertyTable = 1 << 5;
static const unsigned TypeInfoMayBePrototype = 1 << 7;
static const unsigned ImplementsHasInstance = 1 << 8;
static const unsigned OverridesGetPropertyNames = 1 << 9;
static const unsigned ProhibitsPropertyCaching = 1 << 10;
static const unsigned GetOwnPropertySlotIsImpure = 1 << 11;
static const unsigned NewImpurePropertyFiresWatchpoints = 1 << 12;
static const unsigned IsImmutablePrototypeExoticObject = 1 << 13;
static const unsigned GetOwnPropertySlotIsImpureForPropertyAbsence = 1 << 14;
static const unsigned InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero = 1 << 15;
static const unsigned StructureIsImmortal = 1 << 16;
class TypeInfo {
public:
typedef uint8_t InlineTypeFlags;
typedef uint16_t OutOfLineTypeFlags;
TypeInfo(JSType type, unsigned flags = 0)
: TypeInfo(type, flags & 0xff, flags >> 8)
{
ASSERT(!(flags >> 24));
}
TypeInfo(JSType type, InlineTypeFlags inlineTypeFlags, OutOfLineTypeFlags outOfLineTypeFlags)
: m_type(type)
, m_flags(inlineTypeFlags)
, m_flags2(outOfLineTypeFlags)
{
}
JSType type() const { return static_cast<JSType>(m_type); }
bool isObject() const { return isObject(type()); }
static bool isObject(JSType type) { return type >= ObjectType; }
bool isFinalObject() const { return type() == FinalObjectType; }
bool isNumberObject() const { return type() == NumberObjectType; }
unsigned flags() const { return (static_cast<unsigned>(m_flags2) << 8) | static_cast<unsigned>(m_flags); }
bool masqueradesAsUndefined() const { return isSetOnFlags1(MasqueradesAsUndefined); }
bool implementsHasInstance() const { return isSetOnFlags2(ImplementsHasInstance); }
bool implementsDefaultHasInstance() const { return isSetOnFlags1(ImplementsDefaultHasInstance); }
bool overridesGetCallData() const { return isSetOnFlags1(OverridesGetCallData); }
bool overridesGetOwnPropertySlot() const { return overridesGetOwnPropertySlot(inlineTypeFlags()); }
static bool overridesGetOwnPropertySlot(InlineTypeFlags flags) { return flags & OverridesGetOwnPropertySlot; }
static bool hasStaticPropertyTable(InlineTypeFlags flags) { return flags & HasStaticPropertyTable; }
static bool mayBePrototype(InlineTypeFlags flags) { return flags & TypeInfoMayBePrototype; }
bool overridesToThis() const { return isSetOnFlags1(OverridesToThis); }
bool structureIsImmortal() const { return isSetOnFlags2(StructureIsImmortal); }
bool overridesGetPropertyNames() const { return isSetOnFlags2(OverridesGetPropertyNames); }
bool prohibitsPropertyCaching() const { return isSetOnFlags2(ProhibitsPropertyCaching); }
bool getOwnPropertySlotIsImpure() const { return isSetOnFlags2(GetOwnPropertySlotIsImpure); }
bool getOwnPropertySlotIsImpureForPropertyAbsence() const { return isSetOnFlags2(GetOwnPropertySlotIsImpureForPropertyAbsence); }
bool newImpurePropertyFiresWatchpoints() const { return isSetOnFlags2(NewImpurePropertyFiresWatchpoints); }
bool isImmutablePrototypeExoticObject() const { return isSetOnFlags2(IsImmutablePrototypeExoticObject); }
bool interceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero() const { return isSetOnFlags2(InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero); }
static bool isArgumentsType(JSType type)
{
return type == DirectArgumentsType
|| type == ScopedArgumentsType
|| type == ClonedArgumentsType;
}
static ptrdiff_t flagsOffset()
{
return OBJECT_OFFSETOF(TypeInfo, m_flags);
}
static ptrdiff_t typeOffset()
{
return OBJECT_OFFSETOF(TypeInfo, m_type);
}
static InlineTypeFlags mergeInlineTypeFlags(InlineTypeFlags structureFlags, InlineTypeFlags oldCellFlags)
{
return structureFlags | (oldCellFlags & static_cast<InlineTypeFlags>(TypeInfoMayBePrototype));
}
InlineTypeFlags inlineTypeFlags() const { return m_flags; }
OutOfLineTypeFlags outOfLineTypeFlags() const { return m_flags2; }
private:
friend class LLIntOffsetsExtractor;
bool isSetOnFlags1(unsigned flag) const { ASSERT(flag <= (1 << 7)); return m_flags & flag; }
bool isSetOnFlags2(unsigned flag) const { ASSERT(flag >= (1 << 8)); return m_flags2 & (flag >> 8); }
uint8_t m_type;
uint8_t m_flags;
uint16_t m_flags2;
};
}