2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "DOMDataStore.h"
36 #include "ScopedDOMDataStore.h"
37 #include "V8Binding.h"
38 #include <wtf/MainThread.h>
42 DOMDataStoreHandle::DOMDataStoreHandle()
43 : m_store(adoptPtr(new ScopedDOMDataStore()))
45 V8BindingPerIsolateData::current()->registerDOMDataStore(m_store.get());
48 DOMDataStoreHandle::~DOMDataStoreHandle()
50 V8BindingPerIsolateData::current()->unregisterDOMDataStore(m_store.get());
53 static inline DOMDataStore& getDOMDataStore()
55 return DOMData::getCurrentStore();
58 void enableFasterDOMStoreAccess()
62 DOMNodeMapping& getDOMNodeMap()
64 return getDOMDataStore().domNodeMap();
67 DOMNodeMapping& getActiveDOMNodeMap()
69 return getDOMDataStore().activeDomNodeMap();
72 DOMWrapperMap<void>& getDOMObjectMap()
74 return getDOMDataStore().domObjectMap();
77 DOMWrapperMap<void>& getActiveDOMObjectMap()
79 return getDOMDataStore().activeDomObjectMap();
84 DOMWrapperMap<SVGElementInstance>& getDOMSVGElementInstanceMap()
86 return getDOMDataStore().domSvgElementInstanceMap();
91 void removeAllDOMObjects()
93 DOMDataStore& store = getDOMDataStore();
95 v8::HandleScope scope;
97 // The DOM objects with the following types only exist on the main thread.
99 // Remove all DOM nodes.
100 DOMData::removeObjectsFromWrapperMap<Node>(&store, store.domNodeMap());
102 // Remove all active DOM nodes.
103 DOMData::removeObjectsFromWrapperMap<Node>(&store, store.activeDomNodeMap());
106 // Remove all SVG element instances in the wrapper map.
107 DOMData::removeObjectsFromWrapperMap<SVGElementInstance>(&store, store.domSvgElementInstanceMap());
111 // Remove all DOM objects in the wrapper map.
112 DOMData::removeObjectsFromWrapperMap<void>(&store, store.domObjectMap());
114 // Remove all active DOM objects in the wrapper map.
115 DOMData::removeObjectsFromWrapperMap<void>(&store, store.activeDomObjectMap());
118 void visitDOMNodes(DOMWrapperMap<Node>::Visitor* visitor)
120 v8::HandleScope scope;
122 DOMDataList& list = DOMDataStore::allStores();
123 for (size_t i = 0; i < list.size(); ++i) {
124 DOMDataStore* store = list[i];
126 store->domNodeMap().visit(store, visitor);
130 void visitActiveDOMNodes(DOMWrapperMap<Node>::Visitor* visitor)
132 v8::HandleScope scope;
134 DOMDataList& list = DOMDataStore::allStores();
135 for (size_t i = 0; i < list.size(); ++i) {
136 DOMDataStore* store = list[i];
138 store->activeDomNodeMap().visit(store, visitor);
142 void visitDOMObjects(DOMWrapperMap<void>::Visitor* visitor)
144 v8::HandleScope scope;
146 DOMDataList& list = DOMDataStore::allStores();
147 for (size_t i = 0; i < list.size(); ++i) {
148 DOMDataStore* store = list[i];
150 store->domObjectMap().visit(store, visitor);
154 void visitActiveDOMObjects(DOMWrapperMap<void>::Visitor* visitor)
156 v8::HandleScope scope;
158 DOMDataList& list = DOMDataStore::allStores();
159 for (size_t i = 0; i < list.size(); ++i) {
160 DOMDataStore* store = list[i];
162 store->activeDomObjectMap().visit(store, visitor);
168 void visitDOMSVGElementInstances(DOMWrapperMap<SVGElementInstance>::Visitor* visitor)
170 v8::HandleScope scope;
172 DOMDataList& list = DOMDataStore::allStores();
173 for (size_t i = 0; i < list.size(); ++i) {
174 DOMDataStore* store = list[i];
176 store->domSvgElementInstanceMap().visit(store, visitor);
182 } // namespace WebCore