#pragma once
#include <wtf/HashTable.h>
namespace JSC {
class FunctionExecutable;
class JSGlobalObject;
class JSObject;
class PrototypeKey {
public:
PrototypeKey() { }
PrototypeKey(JSObject* prototype, FunctionExecutable* executable, unsigned inlineCapacity, const ClassInfo* classInfo, JSGlobalObject* globalObject)
: m_prototype(prototype)
, m_executable(executable)
, m_inlineCapacity(inlineCapacity)
, m_classInfo(classInfo)
, m_globalObject(globalObject)
{
}
PrototypeKey(WTF::HashTableDeletedValueType)
: m_inlineCapacity(1)
{
}
JSObject* prototype() const { return m_prototype; }
FunctionExecutable* executable() const { return m_executable; }
unsigned inlineCapacity() const { return m_inlineCapacity; }
const ClassInfo* classInfo() const { return m_classInfo; }
JSGlobalObject* globalObject() const { return m_globalObject; }
bool operator==(const PrototypeKey& other) const
{
return m_prototype == other.m_prototype
&& m_executable == other.m_executable
&& m_inlineCapacity == other.m_inlineCapacity
&& m_classInfo == other.m_classInfo
&& m_globalObject == other.m_globalObject;
}
bool operator!=(const PrototypeKey& other) const { return !(*this == other); }
explicit operator bool() const { return *this != PrototypeKey(); }
bool isHashTableDeletedValue() const { return *this == PrototypeKey(WTF::HashTableDeletedValue); }
unsigned hash() const
{
return WTF::IntHash<uintptr_t>::hash(bitwise_cast<uintptr_t>(m_prototype) ^ bitwise_cast<uintptr_t>(m_executable) ^ bitwise_cast<uintptr_t>(m_classInfo) ^ bitwise_cast<uintptr_t>(m_globalObject)) + m_inlineCapacity;
}
private:
JSObject* m_prototype { nullptr };
FunctionExecutable* m_executable { nullptr };
unsigned m_inlineCapacity { 0 };
const ClassInfo* m_classInfo { nullptr };
JSGlobalObject* m_globalObject { nullptr };
};
struct PrototypeKeyHash {
static unsigned hash(const PrototypeKey& key) { return key.hash(); }
static bool equal(const PrototypeKey& a, const PrototypeKey& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};
}
namespace WTF {
template<typename T> struct DefaultHash;
template<> struct DefaultHash<JSC::PrototypeKey> {
typedef JSC::PrototypeKeyHash Hash;
};
template<typename T> struct HashTraits;
template<> struct HashTraits<JSC::PrototypeKey> : SimpleClassHashTraits<JSC::PrototypeKey> { };
}