[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.17-1283-gcf603cf
eric at webkit.org
eric at webkit.org
Tue Jan 5 23:47:24 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit f78668a53335c73a39bd7af8a8c33d9660f3e63b
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Dec 11 17:21:14 2009 +0000
2009-12-11 anton muhin <antonm at chromium.org>
Reviewed by Adam Barth.
[v8] refactor WeakReferenceMap.
Move common bits of functionality to reduce duplication.
https://bugs.webkit.org/show_bug.cgi?id=32389
Should be covered by buildbots.
* bindings/v8/DOMData.h:
(WebCore::DOMData::WrapperMapObjectRemover::visitDOMWrapper):
(WebCore::DOMData::handleWeakObject):
(WebCore::DOMData::removeObjectsFromWrapperMap):
* bindings/v8/DOMDataStore.cpp:
(WebCore::DOMDataStore::weakDOMObjectCallback):
(WebCore::DOMDataStore::weakActiveDOMObjectCallback):
(WebCore::DOMDataStore::weakNodeCallback):
(WebCore::DOMDataStore::weakSVGElementInstanceCallback):
(WebCore::DOMDataStore::weakSVGObjectWithContextCallback):
* bindings/v8/DOMDataStore.h:
* bindings/v8/V8DOMMap.cpp:
(WebCore::visitDOMNodesInCurrentThread):
(WebCore::visitDOMObjectsInCurrentThread):
(WebCore::visitActiveDOMObjectsInCurrentThread):
(WebCore::visitDOMSVGElementInstancesInCurrentThread):
(WebCore::visitSVGObjectsInCurrentThread):
* bindings/v8/V8DOMMap.h:
(WebCore::WeakReferenceMap::removeIfPresent):
(WebCore::WeakReferenceMap::clear):
(WebCore::WeakReferenceMap::visit):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51998 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index cdc85c9..90371d0 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,4 +1,37 @@
2009-12-11 anton muhin <antonm at chromium.org>
+
+ Reviewed by Adam Barth.
+
+ [v8] refactor WeakReferenceMap.
+ Move common bits of functionality to reduce duplication.
+
+ https://bugs.webkit.org/show_bug.cgi?id=32389
+
+ Should be covered by buildbots.
+
+ * bindings/v8/DOMData.h:
+ (WebCore::DOMData::WrapperMapObjectRemover::visitDOMWrapper):
+ (WebCore::DOMData::handleWeakObject):
+ (WebCore::DOMData::removeObjectsFromWrapperMap):
+ * bindings/v8/DOMDataStore.cpp:
+ (WebCore::DOMDataStore::weakDOMObjectCallback):
+ (WebCore::DOMDataStore::weakActiveDOMObjectCallback):
+ (WebCore::DOMDataStore::weakNodeCallback):
+ (WebCore::DOMDataStore::weakSVGElementInstanceCallback):
+ (WebCore::DOMDataStore::weakSVGObjectWithContextCallback):
+ * bindings/v8/DOMDataStore.h:
+ * bindings/v8/V8DOMMap.cpp:
+ (WebCore::visitDOMNodesInCurrentThread):
+ (WebCore::visitDOMObjectsInCurrentThread):
+ (WebCore::visitActiveDOMObjectsInCurrentThread):
+ (WebCore::visitDOMSVGElementInstancesInCurrentThread):
+ (WebCore::visitSVGObjectsInCurrentThread):
+ * bindings/v8/V8DOMMap.h:
+ (WebCore::WeakReferenceMap::removeIfPresent):
+ (WebCore::WeakReferenceMap::clear):
+ (WebCore::WeakReferenceMap::visit):
+
+2009-12-11 anton muhin <antonm at chromium.org>
Reviewed by Adam Barth.
[v8] in Debug builds create an additional handle scope
diff --git a/WebCore/bindings/v8/DOMData.h b/WebCore/bindings/v8/DOMData.h
index 65fe8fc..b58f138 100644
--- a/WebCore/bindings/v8/DOMData.h
+++ b/WebCore/bindings/v8/DOMData.h
@@ -50,7 +50,7 @@ namespace WebCore {
virtual DOMDataStore& getStore() = 0;
template<typename T>
- static void handleWeakObject(DOMDataStore::DOMWrapperMapType, v8::Handle<v8::Object>, T* domObject);
+ static void handleWeakObject(DOMDataStore::DOMWrapperMapType, v8::Persistent<v8::Object>, T* domObject);
void forgetDelayedObject(void* object) { m_delayedObjectMap.take(object); }
@@ -71,6 +71,17 @@ namespace WebCore {
void ensureDeref(V8ClassIndex::V8WrapperType type, void* domObject);
static void derefObject(V8ClassIndex::V8WrapperType type, void* domObject);
+ template<typename T>
+ class WrapperMapObjectRemover : public WeakReferenceMap<T, v8::Object>::Visitor {
+ public:
+ virtual void visitDOMWrapper(T* domObject, v8::Persistent<v8::Object> v8Object)
+ {
+ V8ClassIndex::V8WrapperType type = V8DOMWrapper::domWrapperType(v8Object);
+ derefObject(type, domObject);
+ v8Object.Dispose();
+ }
+ };
+
// Stores all the DOM objects that are delayed to be processed when the
// owning thread gains control.
DelayedObjectMap m_delayedObjectMap;
@@ -84,7 +95,7 @@ namespace WebCore {
};
template<typename T>
- void DOMData::handleWeakObject(DOMDataStore::DOMWrapperMapType mapType, v8::Handle<v8::Object> v8Object, T* domObject)
+ void DOMData::handleWeakObject(DOMDataStore::DOMWrapperMapType mapType, v8::Persistent<v8::Object> v8Object, T* domObject)
{
ASSERT(WTF::isMainThread());
DOMDataList& list = DOMDataStore::allStores();
@@ -93,10 +104,7 @@ namespace WebCore {
DOMDataStore::InternalDOMWrapperMap<T>* domMap = static_cast<DOMDataStore::InternalDOMWrapperMap<T>*>(store->getDOMWrapperMap(mapType));
- v8::Handle<v8::Object> wrapper = domMap->get(domObject);
- if (*wrapper == *v8Object) {
- // Clear the JS reference.
- domMap->forgetOnly(domObject);
+ if (domMap->removeIfPresent(domObject, v8Object)) {
ASSERT(store->domData()->owningThread() == WTF::currentThread());
store->domData()->derefObject(V8DOMWrapper::domWrapperType(v8Object), domObject);
}
@@ -106,19 +114,9 @@ namespace WebCore {
template<typename T>
void DOMData::removeObjectsFromWrapperMap(DOMWrapperMap<T>& domMap)
{
- for (typename WTF::HashMap<T*, v8::Object*>::iterator iter(domMap.impl().begin()); iter != domMap.impl().end(); ++iter) {
- T* domObject = static_cast<T*>(iter->first);
- v8::Persistent<v8::Object> v8Object(iter->second);
-
- V8ClassIndex::V8WrapperType type = V8DOMWrapper::domWrapperType(v8::Handle<v8::Object>::Cast(v8Object));
-
- // Deref the DOM object.
- derefObject(type, domObject);
-
- // Clear the JS wrapper.
- v8Object.Dispose();
- }
- domMap.impl().clear();
+ WrapperMapObjectRemover<T> remover;
+ domMap.visit(&remover);
+ domMap.clear();
}
} // namespace WebCore
diff --git a/WebCore/bindings/v8/DOMDataStore.cpp b/WebCore/bindings/v8/DOMDataStore.cpp
index a76ca53..336f662 100644
--- a/WebCore/bindings/v8/DOMDataStore.cpp
+++ b/WebCore/bindings/v8/DOMDataStore.cpp
@@ -146,14 +146,14 @@ void DOMDataStore::weakDOMObjectCallback(v8::Persistent<v8::Value> v8Object, voi
{
v8::HandleScope scope;
ASSERT(v8Object->IsObject());
- DOMData::handleWeakObject(DOMDataStore::DOMObjectMap, v8::Handle<v8::Object>::Cast(v8Object), domObject);
+ DOMData::handleWeakObject(DOMDataStore::DOMObjectMap, v8::Persistent<v8::Object>::Cast(v8Object), domObject);
}
void DOMDataStore::weakActiveDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* domObject)
{
v8::HandleScope scope;
ASSERT(v8Object->IsObject());
- DOMData::handleWeakObject(DOMDataStore::ActiveDOMObjectMap, v8::Handle<v8::Object>::Cast(v8Object), domObject);
+ DOMData::handleWeakObject(DOMDataStore::ActiveDOMObjectMap, v8::Persistent<v8::Object>::Cast(v8Object), domObject);
}
void DOMDataStore::weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* domObject)
@@ -166,15 +166,11 @@ void DOMDataStore::weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* do
DOMDataList& list = DOMDataStore::allStores();
for (size_t i = 0; i < list.size(); ++i) {
DOMDataStore* store = list[i];
- HashMap<Node*, v8::Object*>& domMapImpl = store->domNodeMap().impl();
- HashMap<Node*, v8::Object*>::iterator it = domMapImpl.find(node);
- if (it == domMapImpl.end() || it->second != *v8Object)
- continue;
- ASSERT(store->domData()->owningThread() == WTF::currentThread());
- v8Object.Dispose();
- domMapImpl.remove(it);
- node->deref(); // Nobody overrides Node::deref so it's safe
- break; // There might be at most one wrapper for the node in world's maps
+ if (store->domNodeMap().removeIfPresent(node, v8Object)) {
+ ASSERT(store->domData()->owningThread() == WTF::currentThread());
+ node->deref(); // Nobody overrides Node::deref so it's safe
+ break; // There might be at most one wrapper for the node in world's maps
+ }
}
}
@@ -184,14 +180,14 @@ void DOMDataStore::weakSVGElementInstanceCallback(v8::Persistent<v8::Value> v8Ob
{
v8::HandleScope scope;
ASSERT(v8Object->IsObject());
- DOMData::handleWeakObject(DOMDataStore::DOMSVGElementInstanceMap, v8::Handle<v8::Object>::Cast(v8Object), static_cast<SVGElementInstance*>(domObject));
+ DOMData::handleWeakObject(DOMDataStore::DOMSVGElementInstanceMap, v8::Persistent<v8::Object>::Cast(v8Object), static_cast<SVGElementInstance*>(domObject));
}
void DOMDataStore::weakSVGObjectWithContextCallback(v8::Persistent<v8::Value> v8Object, void* domObject)
{
v8::HandleScope scope;
ASSERT(v8Object->IsObject());
- DOMData::handleWeakObject(DOMDataStore::DOMSVGObjectWithContextMap, v8::Handle<v8::Object>::Cast(v8Object), domObject);
+ DOMData::handleWeakObject(DOMDataStore::DOMSVGObjectWithContextMap, v8::Persistent<v8::Object>::Cast(v8Object), domObject);
}
#endif // ENABLE(SVG)
diff --git a/WebCore/bindings/v8/DOMDataStore.h b/WebCore/bindings/v8/DOMDataStore.h
index b127089..e027058 100644
--- a/WebCore/bindings/v8/DOMDataStore.h
+++ b/WebCore/bindings/v8/DOMDataStore.h
@@ -82,8 +82,6 @@ namespace WebCore {
forgetDelayedObject(m_domData, object);
}
- void forgetOnly(KeyType* object) { DOMWrapperMap<KeyType>::forget(object); }
-
private:
DOMData* m_domData;
};
diff --git a/WebCore/bindings/v8/V8DOMMap.cpp b/WebCore/bindings/v8/V8DOMMap.cpp
index acd88ec..83e2684 100644
--- a/WebCore/bindings/v8/V8DOMMap.cpp
+++ b/WebCore/bindings/v8/V8DOMMap.cpp
@@ -145,9 +145,7 @@ void visitDOMNodesInCurrentThread(DOMWrapperMap<Node>::Visitor* visitor)
if (!store->domData()->owningThread() == WTF::currentThread())
continue;
- HashMap<Node*, v8::Object*>& map = store->domNodeMap().impl();
- for (HashMap<Node*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it)
- visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second));
+ store->domNodeMap().visit(visitor);
}
}
@@ -162,9 +160,7 @@ void visitDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor)
if (!store->domData()->owningThread() == WTF::currentThread())
continue;
- HashMap<void*, v8::Object*> & map = store->domObjectMap().impl();
- for (HashMap<void*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it)
- visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second));
+ store->domObjectMap().visit(visitor);
}
}
@@ -179,9 +175,7 @@ void visitActiveDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor)
if (!store->domData()->owningThread() == WTF::currentThread())
continue;
- HashMap<void*, v8::Object*>& map = store->activeDomObjectMap().impl();
- for (HashMap<void*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it)
- visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second));
+ store->activeDomObjectMap().visit(visitor);
}
}
@@ -198,9 +192,7 @@ void visitDOMSVGElementInstancesInCurrentThread(DOMWrapperMap<SVGElementInstance
if (!store->domData()->owningThread() == WTF::currentThread())
continue;
- HashMap<SVGElementInstance*, v8::Object*> & map = store->domSvgElementInstanceMap().impl();
- for (HashMap<SVGElementInstance*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it)
- visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second));
+ store->domSvgElementInstanceMap().visit(visitor);
}
}
@@ -215,9 +207,7 @@ void visitSVGObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor)
if (!store->domData()->owningThread() == WTF::currentThread())
continue;
- HashMap<void*, v8::Object*>& map = store->domSvgObjectWithContextMap().impl();
- for (HashMap<void*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it)
- visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second));
+ store->domSvgObjectWithContextMap().visit(visitor);
}
}
diff --git a/WebCore/bindings/v8/V8DOMMap.h b/WebCore/bindings/v8/V8DOMMap.h
index 12605a6..3a197fa 100644
--- a/WebCore/bindings/v8/V8DOMMap.h
+++ b/WebCore/bindings/v8/V8DOMMap.h
@@ -81,9 +81,35 @@ namespace WebCore {
handle.Clear();
}
+ bool removeIfPresent(KeyType* key, v8::Persistent<v8::Data> value)
+ {
+ typename HashMap<KeyType*, ValueType*>::iterator it = m_map.find(key);
+ if (it == m_map.end() || it->second != *value)
+ return false;
+
+ m_map.remove(it);
+ value.Dispose();
+ return true;
+ }
+
+ void clear()
+ {
+ m_map.clear();
+ }
+
bool contains(KeyType* obj) { return m_map.contains(obj); }
- HashMap<KeyType*, ValueType*>& impl() { return m_map; }
+ class Visitor {
+ public:
+ virtual void visitDOMWrapper(KeyType*, v8::Persistent<ValueType>) = 0;
+ };
+
+ virtual void visit(Visitor* visitor)
+ {
+ typename HashMap<KeyType*, ValueType*>::iterator it = m_map.begin();
+ for (; it != m_map.end(); ++it)
+ visitor->visitDOMWrapper(it->first, v8::Persistent<ValueType>(it->second));
+ }
protected:
HashMap<KeyType*, ValueType*> m_map;
@@ -93,11 +119,6 @@ namespace WebCore {
template <class KeyType> class DOMWrapperMap : public WeakReferenceMap<KeyType, v8::Object> {
public:
DOMWrapperMap(v8::WeakReferenceCallback callback) : WeakReferenceMap<KeyType, v8::Object>(callback) { }
-
- class Visitor {
- public:
- virtual void visitDOMWrapper(KeyType* key, v8::Persistent<v8::Object> object) = 0;
- };
};
// An opaque class that represents a set of DOM wrappers.
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list