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 JSDOMWrapperOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
35 JSDOMWrapper* wrapper = static_cast<JSDOMWrapper*>(handle.get().asCell());
36 void* domObject = context;
37 uncacheWrapper(m_world, domObject, wrapper);
40 void JSStringOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
42 JSString* jsString = static_cast<JSString*>(handle.get().asCell());
43 StringImpl* stringImpl = static_cast<StringImpl*>(context);
44 ASSERT_UNUSED(jsString, m_world->m_stringCache.find(stringImpl)->second.get() == jsString);
45 m_world->m_stringCache.remove(stringImpl);
48 DOMWrapperWorld::DOMWrapperWorld(JSC::JSGlobalData* globalData, bool isNormal)
49 : m_globalData(globalData)
50 , m_isNormal(isNormal)
51 , m_defaultWrapperOwner(this)
52 , m_stringWrapperOwner(this)
54 JSGlobalData::ClientData* clientData = m_globalData->clientData;
56 static_cast<WebCoreJSClientData*>(clientData)->rememberWorld(this);
59 DOMWrapperWorld::~DOMWrapperWorld()
61 JSGlobalData::ClientData* clientData = m_globalData->clientData;
63 static_cast<WebCoreJSClientData*>(clientData)->forgetWorld(this);
65 // These items are created lazily.
66 while (!m_scriptControllersWithWindowShells.isEmpty())
67 (*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this);
70 void DOMWrapperWorld::clearWrappers()
73 m_stringCache.clear();
75 // These items are created lazily.
76 while (!m_scriptControllersWithWindowShells.isEmpty())
77 (*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this);
80 DOMWrapperWorld* normalWorld(JSC::JSGlobalData& globalData)
82 JSGlobalData::ClientData* clientData = globalData.clientData;
84 return static_cast<WebCoreJSClientData*>(clientData)->normalWorld();
87 DOMWrapperWorld* mainThreadNormalWorld()
89 ASSERT(isMainThread());
90 static DOMWrapperWorld* cachedNormalWorld = normalWorld(*JSDOMWindow::commonJSGlobalData());
91 return cachedNormalWorld;
94 } // namespace WebCore