DOMWrapperWorld.cpp [plain text]
#include "config.h"
#include "DOMWrapperWorld.h"
#include "JSDOMWindow.h"
#include "ScriptController.h"
#include "WebCoreJSClientData.h"
#include <wtf/MainThread.h>
using namespace JSC;
namespace WebCore {
void JSStringOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
JSString* jsString = jsCast<JSString*>(handle.get().asCell());
StringImpl* stringImpl = static_cast<StringImpl*>(context);
ASSERT_UNUSED(jsString, m_world->m_stringCache.find(stringImpl)->second.was(jsString));
m_world->m_stringCache.remove(stringImpl);
}
DOMWrapperWorld::DOMWrapperWorld(JSC::JSGlobalData* globalData, bool isNormal)
: m_globalData(globalData)
, m_isNormal(isNormal)
, m_stringWrapperOwner(this)
{
JSGlobalData::ClientData* clientData = m_globalData->clientData;
ASSERT(clientData);
static_cast<WebCoreJSClientData*>(clientData)->rememberWorld(this);
}
DOMWrapperWorld::~DOMWrapperWorld()
{
JSGlobalData::ClientData* clientData = m_globalData->clientData;
ASSERT(clientData);
static_cast<WebCoreJSClientData*>(clientData)->forgetWorld(this);
while (!m_scriptControllersWithWindowShells.isEmpty())
(*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this);
}
void DOMWrapperWorld::clearWrappers()
{
m_wrappers.clear();
m_stringCache.clear();
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;
}
}