#pragma once
#include "JSExportMacros.h"
#include <cstddef>
#include <wtf/HashTraits.h>
#include <wtf/Noncopyable.h>
#include <wtf/VectorTraits.h>
namespace JSC {
class WeakImpl;
class WeakHandleOwner;
JS_EXPORT_PRIVATE void weakClearSlowCase(WeakImpl*&);
template<typename T> class Weak {
WTF_MAKE_NONCOPYABLE(Weak);
public:
Weak()
: m_impl(0)
{
}
Weak(std::nullptr_t)
: m_impl(0)
{
}
inline Weak(T*, WeakHandleOwner* = 0, void* context = 0);
enum HashTableDeletedValueTag { HashTableDeletedValue };
inline bool isHashTableDeletedValue() const;
inline Weak(HashTableDeletedValueTag);
inline Weak(Weak&&);
~Weak()
{
clear();
}
inline void swap(Weak&);
inline Weak& operator=(Weak&&);
inline bool operator!() const;
inline T* operator->() const;
inline T& operator*() const;
inline T* get() const;
inline bool was(T*) const;
inline explicit operator bool() const;
inline WeakImpl* leakImpl() WARN_UNUSED_RETURN;
void clear()
{
if (!m_impl)
return;
weakClearSlowCase(m_impl);
}
private:
static inline WeakImpl* hashTableDeletedValue();
WeakImpl* m_impl;
};
}
namespace WTF {
template<typename T> struct VectorTraits<JSC::Weak<T>> : SimpleClassVectorTraits {
static const bool canCompareWithMemcmp = false;
};
template<typename T> struct HashTraits<JSC::Weak<T>> : SimpleClassHashTraits<JSC::Weak<T>> {
typedef JSC::Weak<T> StorageType;
typedef std::nullptr_t EmptyValueType;
static EmptyValueType emptyValue() { return nullptr; }
typedef T* PeekType;
static PeekType peek(const StorageType& value) { return value.get(); }
static PeekType peek(EmptyValueType) { return PeekType(); }
};
}