WebCoreJSClientData.h [plain text]
#ifndef WebCoreJSClientData_h
#define WebCoreJSClientData_h
#include "DOMWrapperWorld.h"
#include "DOMObjectHashTableMap.h"
#include "WebCoreTypedArrayController.h"
#include <wtf/HashSet.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class WebCoreJSClientData : public JSC::VM::ClientData {
WTF_MAKE_NONCOPYABLE(WebCoreJSClientData); WTF_MAKE_FAST_ALLOCATED;
friend class VMWorldIterator;
friend void initNormalWorldClientData(JSC::VM*);
public:
WebCoreJSClientData()
{
}
virtual ~WebCoreJSClientData()
{
ASSERT(m_worldSet.contains(m_normalWorld.get()));
ASSERT(m_worldSet.size() == 1);
ASSERT(m_normalWorld->hasOneRef());
m_normalWorld.clear();
ASSERT(m_worldSet.isEmpty());
}
DOMWrapperWorld& normalWorld() { return *m_normalWorld; }
void getAllWorlds(Vector<Ref<DOMWrapperWorld>>& worlds)
{
ASSERT(worlds.isEmpty());
worlds.reserveInitialCapacity(m_worldSet.size());
for (auto it = m_worldSet.begin(), end = m_worldSet.end(); it != end; ++it)
worlds.uncheckedAppend(*(*it));
}
void rememberWorld(DOMWrapperWorld& world)
{
ASSERT(!m_worldSet.contains(&world));
m_worldSet.add(&world);
}
void forgetWorld(DOMWrapperWorld& world)
{
ASSERT(m_worldSet.contains(&world));
m_worldSet.remove(&world);
}
DOMObjectHashTableMap hashTableMap;
private:
HashSet<DOMWrapperWorld*> m_worldSet;
RefPtr<DOMWrapperWorld> m_normalWorld;
};
inline void initNormalWorldClientData(JSC::VM* vm)
{
WebCoreJSClientData* webCoreJSClientData = new WebCoreJSClientData;
vm->clientData = webCoreJSClientData; webCoreJSClientData->m_normalWorld = DOMWrapperWorld::create(*vm, true);
vm->m_typedArrayController = adoptRef(new WebCoreTypedArrayController());
}
}
#endif // WebCoreJSClientData_h