#ifndef DOMWrapperWorld_h
#define DOMWrapperWorld_h
#include "Document.h"
#include "JSDOMGlobalObject.h"
#include "JSDOMWrapper.h"
#include <runtime/WeakGCMap.h>
namespace WebCore {
class ScriptController;
class StringImpl;
typedef JSC::WeakGCMap<void*, DOMObject*> DOMObjectWrapperMap;
typedef JSC::WeakGCMap<StringImpl*, JSC::JSString*> JSStringCache;
class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
public:
static PassRefPtr<DOMWrapperWorld> create(JSC::JSGlobalData* globalData, bool isNormal = false)
{
return adoptRef(new DOMWrapperWorld(globalData, isNormal));
}
~DOMWrapperWorld();
void registerWorld();
void unregisterWorld();
void didCreateWrapperCache(Document* document) { m_documentsWithWrapperCaches.add(document); }
void didDestroyWrapperCache(Document* document) { m_documentsWithWrapperCaches.remove(document); }
void didCreateWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.add(scriptController); }
void didDestroyWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.remove(scriptController); }
DOMObjectWrapperMap m_wrappers;
JSStringCache m_stringCache;
bool isNormal() const { return m_isNormal; }
protected:
DOMWrapperWorld(JSC::JSGlobalData*, bool isNormal);
private:
JSC::JSGlobalData* m_globalData;
HashSet<Document*> m_documentsWithWrapperCaches;
HashSet<ScriptController*> m_scriptControllersWithWindowShells;
bool m_isNormal;
bool m_isRegistered;
};
DOMWrapperWorld* normalWorld(JSC::JSGlobalData&);
DOMWrapperWorld* mainThreadNormalWorld();
inline DOMWrapperWorld* debuggerWorld() { return mainThreadNormalWorld(); }
inline DOMWrapperWorld* pluginWorld() { return mainThreadNormalWorld(); }
inline DOMWrapperWorld* currentWorld(JSC::ExecState* exec)
{
return static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->world();
}
inline Document::JSWrapperCache* Document::getWrapperCache(DOMWrapperWorld* world)
{
if (world->isNormal()) {
if (Document::JSWrapperCache* wrapperCache = m_normalWorldWrapperCache)
return wrapperCache;
ASSERT(!m_wrapperCacheMap.contains(world));
} else if (Document::JSWrapperCache* wrapperCache = m_wrapperCacheMap.get(world))
return wrapperCache;
return createWrapperCache(world);
}
}
#endif // DOMWrapperWorld_h