CacheableIdentifier.h [plain text]
#pragma once
#include "JSCJSValue.h"
namespace WTF {
class PrintStream;
class UniquedStringImpl;
}
using WTF::PrintStream;
using WTF::UniquedStringImpl;
namespace JSC {
class CodeBlock;
class Identifier;
class JSCell;
class SlotVisitor;
class CacheableIdentifier {
public:
CacheableIdentifier() = default;
static inline CacheableIdentifier createFromCell(JSCell* identifier);
static inline CacheableIdentifier createFromIdentifierOwnedByCodeBlock(CodeBlock*, const Identifier&);
static inline CacheableIdentifier createFromIdentifierOwnedByCodeBlock(CodeBlock*, UniquedStringImpl*);
static inline CacheableIdentifier createFromImmortalIdentifier(UniquedStringImpl*);
static constexpr CacheableIdentifier createFromRawBits(uintptr_t rawBits) { return CacheableIdentifier(rawBits); }
CacheableIdentifier(const CacheableIdentifier&) = default;
CacheableIdentifier(CacheableIdentifier&&) = default;
CacheableIdentifier(std::nullptr_t)
: m_bits(0)
{ }
bool isUid() const { return m_bits & s_uidTag; }
bool isCell() const { return !isUid(); }
inline bool isSymbolCell() const;
inline bool isStringCell() const;
bool isSymbol() const { return m_bits && uid()->isSymbol(); }
inline JSCell* cell() const;
UniquedStringImpl* uid() const;
explicit operator bool() const { return m_bits; }
unsigned hash() const { return uid()->symbolAwareHash(); }
CacheableIdentifier& operator=(const CacheableIdentifier&) = default;
CacheableIdentifier& operator=(CacheableIdentifier&&) = default;
bool operator==(const CacheableIdentifier& other) const;
bool operator!=(const CacheableIdentifier& other) const;
bool operator==(const Identifier& other) const;
static inline bool isCacheableIdentifierCell(JSCell*);
static inline bool isCacheableIdentifierCell(JSValue);
uintptr_t rawBits() const { return m_bits; }
inline void visitAggregate(SlotVisitor&) const;
JS_EXPORT_PRIVATE void dump(PrintStream&) const;
private:
explicit inline CacheableIdentifier(UniquedStringImpl*);
explicit inline CacheableIdentifier(JSCell* identifier);
explicit constexpr CacheableIdentifier(uintptr_t rawBits)
: m_bits(rawBits)
{ }
inline void setCellBits(JSCell*);
inline void setUidBits(UniquedStringImpl*);
static constexpr uintptr_t s_uidTag = 1;
uintptr_t m_bits { 0 };
};
}