OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 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 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/v8/V8NodeFilterCondition.h" | 32 #include "bindings/v8/V8NodeFilterCondition.h" |
33 | 33 |
34 #include "V8Node.h" | 34 #include "V8Node.h" |
35 #include "bindings/v8/ScriptController.h" | 35 #include "bindings/v8/ScriptController.h" |
36 #include "bindings/v8/ScriptState.h" | 36 #include "bindings/v8/ScriptState.h" |
| 37 #include "bindings/v8/V8HiddenPropertyName.h" |
37 #include "core/dom/Node.h" | 38 #include "core/dom/Node.h" |
38 #include "core/dom/NodeFilter.h" | 39 #include "core/dom/NodeFilter.h" |
39 #include "wtf/OwnArrayPtr.h" | 40 #include "wtf/OwnArrayPtr.h" |
40 | 41 |
41 namespace WebCore { | 42 namespace WebCore { |
42 | 43 |
43 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter) | 44 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::H
andle<v8::Object> owner) |
44 : m_filter(filter) | 45 : m_filter(filter) |
45 { | 46 { |
| 47 owner->SetHiddenValue(V8HiddenPropertyName::condition(), filter); |
| 48 m_filter.makeWeak(this, &makeWeakCallback); |
46 } | 49 } |
47 | 50 |
48 V8NodeFilterCondition::~V8NodeFilterCondition() | 51 V8NodeFilterCondition::~V8NodeFilterCondition() |
49 { | 52 { |
50 } | 53 } |
51 | 54 |
52 short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const | 55 short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const |
53 { | 56 { |
54 ASSERT(v8::Context::InContext()); | 57 ASSERT(v8::Context::InContext()); |
55 | 58 |
56 v8::Isolate* isolate = state->isolate(); | 59 v8::Isolate* isolate = state->isolate(); |
57 v8::HandleScope handleScope(isolate); | 60 v8::HandleScope handleScope(isolate); |
58 v8::Handle<v8::Value> filter = m_filter.newLocal(isolate); | 61 v8::Handle<v8::Value> filter = m_filter.newLocal(isolate); |
| 62 ASSERT(!filter.IsEmpty()); |
59 if (!filter->IsObject()) | 63 if (!filter->IsObject()) |
60 return NodeFilter::FILTER_ACCEPT; | 64 return NodeFilter::FILTER_ACCEPT; |
61 | 65 |
62 v8::TryCatch exceptionCatcher; | 66 v8::TryCatch exceptionCatcher; |
63 | 67 |
64 v8::Handle<v8::Function> callback; | 68 v8::Handle<v8::Function> callback; |
65 if (filter->IsFunction()) | 69 if (filter->IsFunction()) |
66 callback = v8::Handle<v8::Function>::Cast(filter); | 70 callback = v8::Handle<v8::Function>::Cast(filter); |
67 else { | 71 else { |
68 v8::Local<v8::Value> value = filter->ToObject()->Get(v8::String::NewSymb
ol("acceptNode")); | 72 v8::Local<v8::Value> value = filter->ToObject()->Get(v8::String::NewSymb
ol("acceptNode")); |
(...skipping 13 matching lines...) Expand all Loading... |
82 if (exceptionCatcher.HasCaught()) { | 86 if (exceptionCatcher.HasCaught()) { |
83 state->setException(exceptionCatcher.Exception()); | 87 state->setException(exceptionCatcher.Exception()); |
84 return NodeFilter::FILTER_REJECT; | 88 return NodeFilter::FILTER_REJECT; |
85 } | 89 } |
86 | 90 |
87 ASSERT(!result.IsEmpty()); | 91 ASSERT(!result.IsEmpty()); |
88 | 92 |
89 return result->Int32Value(); | 93 return result->Int32Value(); |
90 } | 94 } |
91 | 95 |
| 96 void V8NodeFilterCondition::makeWeakCallback(v8::Isolate*, v8::Persistent<v8::Va
lue>*, V8NodeFilterCondition* condition) |
| 97 { |
| 98 condition->m_filter.clear(); |
| 99 } |
| 100 |
92 } // namespace WebCore | 101 } // namespace WebCore |
OLD | NEW |