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); |
59 if (!filter->IsObject()) | 62 if (!filter->IsObject()) |
dominicc (has gone to gerrit)
2013/07/31 14:09:55
Is it worth asserting that this is non-empty?
kouhei (in TOK)
2013/08/01 01:12:24
Done.
| |
60 return NodeFilter::FILTER_ACCEPT; | 63 return NodeFilter::FILTER_ACCEPT; |
61 | 64 |
62 v8::TryCatch exceptionCatcher; | 65 v8::TryCatch exceptionCatcher; |
63 | 66 |
64 v8::Handle<v8::Function> callback; | 67 v8::Handle<v8::Function> callback; |
65 if (filter->IsFunction()) | 68 if (filter->IsFunction()) |
66 callback = v8::Handle<v8::Function>::Cast(filter); | 69 callback = v8::Handle<v8::Function>::Cast(filter); |
67 else { | 70 else { |
68 v8::Local<v8::Value> value = filter->ToObject()->Get(v8::String::NewSymb ol("acceptNode")); | 71 v8::Local<v8::Value> value = filter->ToObject()->Get(v8::String::NewSymb ol("acceptNode")); |
69 if (!value->IsFunction()) { | 72 if (!value->IsFunction()) { |
(...skipping 12 matching lines...) Expand all Loading... | |
82 if (exceptionCatcher.HasCaught()) { | 85 if (exceptionCatcher.HasCaught()) { |
83 state->setException(exceptionCatcher.Exception()); | 86 state->setException(exceptionCatcher.Exception()); |
84 return NodeFilter::FILTER_REJECT; | 87 return NodeFilter::FILTER_REJECT; |
85 } | 88 } |
86 | 89 |
87 ASSERT(!result.IsEmpty()); | 90 ASSERT(!result.IsEmpty()); |
88 | 91 |
89 return result->Int32Value(); | 92 return result->Int32Value(); |
90 } | 93 } |
91 | 94 |
95 void V8NodeFilterCondition::makeWeakCallback(v8::Isolate*, v8::Persistent<v8::Va lue>*, V8NodeFilterCondition* condition) | |
96 { | |
97 condition->m_filter.clear(); | |
98 } | |
99 | |
92 } // namespace WebCore | 100 } // namespace WebCore |
OLD | NEW |