| 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 21 matching lines...) Expand all Loading... |
| 32 #define V8NodeFilterCondition_h | 32 #define V8NodeFilterCondition_h |
| 33 | 33 |
| 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 ExceptionState; |
| 43 | 43 |
| 44 // V8NodeFilterCondition maintains a Javascript implemented callback for | 44 // V8NodeFilterCondition maintains a Javascript implemented callback for |
| 45 // filtering Node returned by NodeIterator/TreeWalker. | 45 // filtering Node returned by NodeIterator/TreeWalker. |
| 46 // A NodeFilterCondition is referenced by a NodeFilter, and A NodeFilter is | 46 // A NodeFilterCondition is referenced by a NodeFilter, and A NodeFilter is |
| 47 // referenced by a NodeIterator/TreeWalker. As V8NodeFilterCondition maintains | 47 // referenced by a NodeIterator/TreeWalker. As V8NodeFilterCondition maintains |
| 48 // a Javascript callback which may reference Document, we need to avoid circular | 48 // a Javascript callback which may reference Document, we need to avoid circular |
| 49 // reference spanning V8/Blink object space. | 49 // reference spanning V8/Blink object space. |
| 50 // To address this issue, V8NodeFilterCondition holds a weak reference to | 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 | 51 // |m_filter|, the Javascript value, and the whole reference is exposed to V8 to |
| 52 // let V8 GC handle collection of |m_filter|. | 52 // let V8 GC handle collection of |m_filter|. |
| 53 // (DOM) | 53 // (DOM) |
| 54 // NodeIterator ----RefPtr----> NodeFilter ----RefPtr----> NodeFilterCondition | 54 // NodeIterator ----RefPtr----> NodeFilter ----RefPtr----> NodeFilterCondition |
| 55 // | ^ | ^ | | 55 // | ^ | ^ | |
| 56 // weak | weak | ScopedPersistent(weak) | 56 // weak | weak | ScopedPersistent(weak) |
| 57 // | RefPtr | RefPtr | | 57 // | RefPtr | RefPtr | |
| 58 // v | v | v | 58 // v | v | v |
| 59 // NodeIterator --HiddenValue--> NodeFilter --HiddenValue--> JS Callback | 59 // NodeIterator --HiddenValue--> NodeFilter --HiddenValue--> JS Callback |
| 60 // (V8) | 60 // (V8) |
| 61 class V8NodeFilterCondition FINAL : public NodeFilterCondition { | 61 class V8NodeFilterCondition FINAL : public NodeFilterCondition { |
| 62 public: | 62 public: |
| 63 static PassRefPtr<V8NodeFilterCondition> create(v8::Handle<v8::Value> filter
, v8::Handle<v8::Object> owner, v8::Isolate* isolate) | 63 static PassRefPtr<V8NodeFilterCondition> create(v8::Handle<v8::Value> filter
, v8::Handle<v8::Object> owner, v8::Isolate* isolate) |
| 64 { | 64 { |
| 65 return adoptRef(new V8NodeFilterCondition(filter, owner, isolate)); | 65 return adoptRef(new V8NodeFilterCondition(filter, owner, isolate)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual ~V8NodeFilterCondition(); | 68 virtual ~V8NodeFilterCondition(); |
| 69 | 69 |
| 70 virtual short acceptNode(ScriptState*, Node*) const OVERRIDE; | 70 virtual short acceptNode(Node*, ExceptionState&) const OVERRIDE; |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 // As the value |filter| is maintained by V8GC, the |owner| which references | 73 // As the value |filter| is maintained by V8GC, the |owner| which references |
| 74 // V8NodeFilterCondition, usually a wrapper of NodeFilter, is specified here | 74 // V8NodeFilterCondition, usually a wrapper of NodeFilter, is specified here |
| 75 // to hold a strong reference to |filter|. | 75 // to hold a strong reference to |filter|. |
| 76 V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::Handle<v8::Object> o
wner, v8::Isolate*); | 76 V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::Handle<v8::Object> o
wner, v8::Isolate*); |
| 77 | 77 |
| 78 static void setWeakCallback(const v8::WeakCallbackData<v8::Value, V8NodeFilt
erCondition>&); | 78 static void setWeakCallback(const v8::WeakCallbackData<v8::Value, V8NodeFilt
erCondition>&); |
| 79 | 79 |
| 80 ScopedPersistent<v8::Value> m_filter; | 80 ScopedPersistent<v8::Value> m_filter; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 } // namespace WebCore | 83 } // namespace WebCore |
| 84 | 84 |
| 85 #endif // V8NodeFilterCondition_h | 85 #endif // V8NodeFilterCondition_h |
| OLD | NEW |