DOMWrapperWorld.cpp [plain text]
#include "config.h"
#include "DOMWrapperWorld.h"
#include "JSDOMWindow.h"
#include "ScriptController.h"
#include "WebCoreJSClientData.h"
using namespace JSC;
namespace WebCore {
DOMWrapperWorld::DOMWrapperWorld(JSC::JSGlobalData* globalData, bool isNormal)
: m_globalData(globalData)
, m_isNormal(isNormal)
, m_isRegistered(false)
{
registerWorld();
}
DOMWrapperWorld::~DOMWrapperWorld()
{
unregisterWorld();
}
void DOMWrapperWorld::registerWorld()
{
JSGlobalData::ClientData* clientData = m_globalData->clientData;
ASSERT(clientData);
static_cast<WebCoreJSClientData*>(clientData)->rememberWorld(this);
m_isRegistered = true;
}
void DOMWrapperWorld::unregisterWorld()
{
if (!m_isRegistered)
return;
m_isRegistered = false;
JSGlobalData::ClientData* clientData = m_globalData->clientData;
ASSERT(clientData);
static_cast<WebCoreJSClientData*>(clientData)->forgetWorld(this);
while (!m_documentsWithWrapperCaches.isEmpty())
(*m_documentsWithWrapperCaches.begin())->destroyWrapperCache(this);
while (!m_scriptControllersWithWindowShells.isEmpty())
(*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this);
}
DOMWrapperWorld* normalWorld(JSC::JSGlobalData& globalData)
{
JSGlobalData::ClientData* clientData = globalData.clientData;
ASSERT(clientData);
return static_cast<WebCoreJSClientData*>(clientData)->normalWorld();
}
DOMWrapperWorld* mainThreadNormalWorld() {
ASSERT(isMainThread() || pthread_main_np());
static DOMWrapperWorld* cachedNormalWorld = normalWorld(*JSDOMWindow::commonJSGlobalData());
return cachedNormalWorld;
}
}