#ifndef JSMap_h
#define JSMap_h
#include "JSDestructibleObject.h"
#include "JSObject.h"
#include "MapData.h"
namespace JSC {
class JSMapIterator;
class JSMap : public JSDestructibleObject {
public:
typedef JSDestructibleObject Base;
friend class JSMapIterator;
class Entry {
private:
WriteBarrier<Unknown> m_key;
WriteBarrier<Unknown> m_value;
public:
const WriteBarrier<Unknown>& key() const
{
return m_key;
}
const WriteBarrier<Unknown>& value() const
{
return m_value;
}
void visitChildren(SlotVisitor& visitor)
{
visitor.append(&m_key);
visitor.append(&m_value);
}
void setKey(VM& vm, const JSCell* owner, JSValue key)
{
m_key.set(vm, owner, key);
}
void setKeyWithoutWriteBarrier(JSValue key)
{
m_key.setWithoutWriteBarrier(key);
}
void setValue(VM& vm, const JSCell* owner, JSValue value)
{
m_value.set(vm, owner, value);
}
void clear()
{
m_key.clear();
m_value.clear();
}
};
typedef MapDataImpl<Entry, JSMapIterator> MapData;
DECLARE_EXPORT_INFO;
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static JSMap* create(VM& vm, Structure* structure)
{
JSMap* instance = new (NotNull, allocateCell<JSMap>(vm.heap)) JSMap(vm, structure);
instance->finishCreation(vm);
return instance;
}
static JSMap* create(ExecState* exec, Structure* structure)
{
return create(exec->vm(), structure);
}
bool has(ExecState*, JSValue);
size_t size(ExecState*);
JSValue get(ExecState*, JSValue);
JS_EXPORT_PRIVATE void set(ExecState*, JSValue key, JSValue value);
void clear(ExecState*);
bool remove(ExecState*, JSValue);
private:
JSMap(VM& vm, Structure* structure)
: Base(vm, structure)
, m_mapData(vm)
{
}
static void destroy(JSCell*);
static void visitChildren(JSCell*, SlotVisitor&);
static void copyBackingStore(JSCell*, CopyVisitor&, CopyToken);
MapData m_mapData;
};
}
#endif // !defined(JSMap_h)