Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Unified Diff: Source/bindings/v8/V8NodeFilterCondition.h

Issue 21274004: Fix Document leak from NodeFilter. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: don't print numberOfLiveDocuments when test passed Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/V8HiddenPropertyName.h ('k') | Source/bindings/v8/V8NodeFilterCondition.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/V8NodeFilterCondition.h
diff --git a/Source/bindings/v8/V8NodeFilterCondition.h b/Source/bindings/v8/V8NodeFilterCondition.h
index 3314a1aca4bde54a4308c150cafb9141be17794f..daaeb0f0d3c7d45ebe72792b9a3df1124d9061b1 100644
--- a/Source/bindings/v8/V8NodeFilterCondition.h
+++ b/Source/bindings/v8/V8NodeFilterCondition.h
@@ -41,11 +41,28 @@ namespace WebCore {
class Node;
class ScriptState;
+// V8NodeFilterCondition maintains a Javascript implemented callback for
+// filtering Node returned by NodeIterator/TreeWalker.
+// A NodeFilterCondition is referenced by a NodeFilter, and A NodeFilter is
+// referenced by a NodeIterator/TreeWalker. As V8NodeFilterCondition maintains
+// a Javascript callback which may reference Document, we need to avoid circular
+// reference spanning V8/Blink object space.
+// To address this issue, V8NodeFilterCondition holds a weak reference to
+// |m_filter|, the Javascript value, and the whole reference is exposed to V8 to
+// let V8 GC handle collection of |m_filter|.
+// (DOM)
+// NodeIterator ----RefPtr----> NodeFilter ----RefPtr----> NodeFilterCondition
+// | ^ | ^ |
+// weak | weak | ScopedPersistent(weak)
+// | RefPtr | RefPtr |
+// v | v | v
+// NodeIterator --HiddenValue--> NodeFilter --HiddenValue--> JS Callback
+// (V8)
class V8NodeFilterCondition : public NodeFilterCondition {
public:
- static PassRefPtr<V8NodeFilterCondition> create(v8::Handle<v8::Value> filter)
+ static PassRefPtr<V8NodeFilterCondition> create(v8::Handle<v8::Value> filter, v8::Handle<v8::Object> owner)
{
- return adoptRef(new V8NodeFilterCondition(filter));
+ return adoptRef(new V8NodeFilterCondition(filter, owner));
}
virtual ~V8NodeFilterCondition();
@@ -53,7 +70,12 @@ public:
virtual short acceptNode(ScriptState*, Node*) const;
private:
- explicit V8NodeFilterCondition(v8::Handle<v8::Value> filter);
+ // As the value |filter| is maintained by V8GC, the |owner| which references
+ // V8NodeFilterCondition, usually a wrapper of NodeFilter, is specified here
+ // to hold a strong reference to |filter|.
+ V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::Handle<v8::Object> owner);
+
+ static void makeWeakCallback(v8::Isolate*, v8::Persistent<v8::Value>*, V8NodeFilterCondition*);
ScopedPersistent<v8::Value> m_filter;
};
« no previous file with comments | « Source/bindings/v8/V8HiddenPropertyName.h ('k') | Source/bindings/v8/V8NodeFilterCondition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698