2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "DOMWrapperWorld.h"
24 #include "JSDOMWindow.h"
25 #include "ScriptController.h"
26 #include "WebCoreJSClientData.h"
27 #include <wtf/MainThread.h>
33 void JSStringOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
35 JSString* jsString = static_cast<JSString*>(handle.get().asCell());
36 StringImpl* stringImpl = static_cast<StringImpl*>(context);
37 ASSERT_UNUSED(jsString, m_world->m_stringCache.find(stringImpl)->second.get() == jsString);
38 m_world->m_stringCache.remove(stringImpl);
41 DOMWrapperWorld::DOMWrapperWorld(JSC::JSGlobalData* globalData, bool isNormal)
42 : m_globalData(globalData)
43 , m_isNormal(isNormal)
44 , m_stringWrapperOwner(this)
46 JSGlobalData::ClientData* clientData = m_globalData->clientData;
48 static_cast<WebCoreJSClientData*>(clientData)->rememberWorld(this);
51 DOMWrapperWorld::~DOMWrapperWorld()
53 JSGlobalData::ClientData* clientData = m_globalData->clientData;
55 static_cast<WebCoreJSClientData*>(clientData)->forgetWorld(this);
57 // These items are created lazily.
58 while (!m_scriptControllersWithWindowShells.isEmpty())
59 (*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this);
62 void DOMWrapperWorld::clearWrappers()
65 m_stringCache.clear();
67 // These items are created lazily.
68 while (!m_scriptControllersWithWindowShells.isEmpty())
69 (*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this);
72 DOMWrapperWorld* normalWorld(JSC::JSGlobalData& globalData)
74 JSGlobalData::ClientData* clientData = globalData.clientData;
76 return static_cast<WebCoreJSClientData*>(clientData)->normalWorld();
79 DOMWrapperWorld* mainThreadNormalWorld()
81 ASSERT(isMainThread());
82 static DOMWrapperWorld* cachedNormalWorld = normalWorld(*JSDOMWindow::commonJSGlobalData());
83 return cachedNormalWorld;
86 } // namespace WebCore