OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "bindings/v8/ScopedPersistent.h" | 34 #include "bindings/v8/ScopedPersistent.h" |
35 #include "core/dom/NodeFilterCondition.h" | 35 #include "core/dom/NodeFilterCondition.h" |
36 #include <v8.h> | 36 #include <v8.h> |
37 #include "wtf/PassRefPtr.h" | 37 #include "wtf/PassRefPtr.h" |
38 | 38 |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 class Node; | 41 class Node; |
42 class ScriptState; | 42 class ScriptState; |
43 | 43 |
44 // V8NodeFilterCondition maintains a Javascript implemented callback for | |
45 // filtering Node returned by NodeIterator/TreeWalker. | |
46 // A NodeFilterCondition is referenced by a NodeFilter, and A NodeFilter is | |
47 // referenced by a NodeIterator/TreeWalker. As V8NodeFilterCondition maintains | |
48 // a Javascript callback which may reference Document, we need to avoid circular | |
49 // reference spanning V8/Blink object space. | |
50 // To address this issue, V8NodeFilterCondition holds a weak reference to | |
51 // |m_filter|, the Javascript value, and the whole reference is exposed to V8 to | |
52 // let V8 GC handle collection of |m_filter|. | |
haraken
2013/08/02 03:47:59
Instead of words, it might be better to illustrate
| |
44 class V8NodeFilterCondition : public NodeFilterCondition { | 53 class V8NodeFilterCondition : public NodeFilterCondition { |
45 public: | 54 public: |
46 static PassRefPtr<V8NodeFilterCondition> create(v8::Handle<v8::Value> filter ) | 55 static PassRefPtr<V8NodeFilterCondition> create(v8::Handle<v8::Value> filter , v8::Handle<v8::Object> owner) |
47 { | 56 { |
48 return adoptRef(new V8NodeFilterCondition(filter)); | 57 return adoptRef(new V8NodeFilterCondition(filter, owner)); |
49 } | 58 } |
50 | 59 |
51 virtual ~V8NodeFilterCondition(); | 60 virtual ~V8NodeFilterCondition(); |
52 | 61 |
53 virtual short acceptNode(ScriptState*, Node*) const; | 62 virtual short acceptNode(ScriptState*, Node*) const; |
54 | 63 |
55 private: | 64 private: |
56 explicit V8NodeFilterCondition(v8::Handle<v8::Value> filter); | 65 // As the value |filter| is maintained by V8GC, the |owner| which references |
66 // V8NodeFilterCondition, usually a wrapper of NodeFilter, is specified here | |
67 // to hold a strong reference to |filter|. | |
68 V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::Handle<v8::Object> o wner); | |
69 | |
70 static void makeWeakCallback(v8::Isolate*, v8::Persistent<v8::Value>*, V8Nod eFilterCondition*); | |
57 | 71 |
58 ScopedPersistent<v8::Value> m_filter; | 72 ScopedPersistent<v8::Value> m_filter; |
59 }; | 73 }; |
60 | 74 |
61 } // namespace WebCore | 75 } // namespace WebCore |
62 | 76 |
63 #endif // V8NodeFilterCondition_h | 77 #endif // V8NodeFilterCondition_h |
OLD | NEW |