| 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 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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" | |
| 37 #include "bindings/v8/V8HiddenValue.h" | 36 #include "bindings/v8/V8HiddenValue.h" |
| 38 #include "core/dom/Node.h" | 37 #include "core/dom/Node.h" |
| 39 #include "core/dom/NodeFilter.h" | 38 #include "core/dom/NodeFilter.h" |
| 40 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 41 | 40 |
| 42 namespace WebCore { | 41 namespace WebCore { |
| 43 | 42 |
| 44 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::H
andle<v8::Object> owner, v8::Isolate* isolate) | 43 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::H
andle<v8::Object> owner, v8::Isolate* isolate) |
| 45 : m_filter(isolate, filter) | 44 : m_scriptState(NewScriptState::current(isolate)) |
| 45 , m_filter(isolate, filter) |
| 46 { | 46 { |
| 47 V8HiddenValue::setHiddenValue(isolate, owner, V8HiddenValue::condition(isola
te), filter); | 47 V8HiddenValue::setHiddenValue(isolate, owner, V8HiddenValue::condition(isola
te), filter); |
| 48 m_filter.setWeak(this, &setWeakCallback); | 48 m_filter.setWeak(this, &setWeakCallback); |
| 49 } | 49 } |
| 50 | 50 |
| 51 V8NodeFilterCondition::~V8NodeFilterCondition() | 51 V8NodeFilterCondition::~V8NodeFilterCondition() |
| 52 { | 52 { |
| 53 } | 53 } |
| 54 | 54 |
| 55 short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const | 55 short V8NodeFilterCondition::acceptNode(Node* node, ExceptionState& exceptionSta
te) const |
| 56 { | 56 { |
| 57 v8::Isolate* isolate = state->isolate(); | 57 v8::Isolate* isolate = m_scriptState->isolate(); |
| 58 ASSERT(isolate->InContext()); | 58 ASSERT(!m_scriptState->context().IsEmpty()); |
| 59 v8::HandleScope handleScope(isolate); | 59 v8::HandleScope handleScope(isolate); |
| 60 v8::Handle<v8::Value> filter = m_filter.newLocal(isolate); | 60 v8::Handle<v8::Value> filter = m_filter.newLocal(isolate); |
| 61 ASSERT(!filter.IsEmpty()); | 61 ASSERT(!filter.IsEmpty()); |
| 62 // FIXME: Remove the filter.IsEmpty() check because |filter| must not be emp
ty. | 62 // FIXME: Remove the filter.IsEmpty() check because |filter| must not be emp
ty. |
| 63 // See crbug.com/358858 for more details. | 63 // See crbug.com/358858 for more details. |
| 64 if (filter.IsEmpty() || !filter->IsObject()) | 64 if (filter.IsEmpty() || !filter->IsObject()) |
| 65 return NodeFilter::FILTER_ACCEPT; | 65 return NodeFilter::FILTER_ACCEPT; |
| 66 | 66 |
| 67 v8::TryCatch exceptionCatcher; | 67 v8::TryCatch exceptionCatcher; |
| 68 | 68 |
| 69 v8::Handle<v8::Function> callback; | 69 v8::Handle<v8::Function> callback; |
| 70 if (filter->IsFunction()) | 70 if (filter->IsFunction()) |
| 71 callback = v8::Handle<v8::Function>::Cast(filter); | 71 callback = v8::Handle<v8::Function>::Cast(filter); |
| 72 else { | 72 else { |
| 73 v8::Local<v8::Value> value = filter->ToObject()->Get(v8AtomicString(isol
ate, "acceptNode")); | 73 v8::Local<v8::Value> value = filter->ToObject()->Get(v8AtomicString(isol
ate, "acceptNode")); |
| 74 if (value.IsEmpty() || !value->IsFunction()) { | 74 if (value.IsEmpty() || !value->IsFunction()) { |
| 75 throwTypeError("NodeFilter object does not have an acceptNode functi
on", state->isolate()); | 75 throwTypeError("NodeFilter object does not have an acceptNode functi
on", isolate); |
| 76 return NodeFilter::FILTER_REJECT; | 76 return NodeFilter::FILTER_REJECT; |
| 77 } | 77 } |
| 78 callback = v8::Handle<v8::Function>::Cast(value); | 78 callback = v8::Handle<v8::Function>::Cast(value); |
| 79 } | 79 } |
| 80 | 80 |
| 81 OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Valu
e>[1]); | 81 OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Valu
e>[1]); |
| 82 info[0] = toV8(node, v8::Handle<v8::Object>(), state->isolate()); | 82 info[0] = toV8(node, v8::Handle<v8::Object>(), isolate); |
| 83 | 83 |
| 84 v8::Handle<v8::Object> object = isolate->GetCurrentContext()->Global(); | 84 v8::Handle<v8::Object> object = m_scriptState->context()->Global(); |
| 85 v8::Handle<v8::Value> result = ScriptController::callFunction(state->executi
onContext(), callback, object, 1, info.get(), isolate); | 85 v8::Handle<v8::Value> result = ScriptController::callFunction(m_scriptState-
>executionContext(), callback, object, 1, info.get(), isolate); |
| 86 | 86 |
| 87 if (exceptionCatcher.HasCaught()) { | 87 if (exceptionCatcher.HasCaught()) { |
| 88 state->setException(exceptionCatcher.Exception()); | 88 exceptionState.rethrowV8Exception(exceptionCatcher.Exception()); |
| 89 return NodeFilter::FILTER_REJECT; | 89 return NodeFilter::FILTER_REJECT; |
| 90 } | 90 } |
| 91 | 91 |
| 92 ASSERT(!result.IsEmpty()); | 92 ASSERT(!result.IsEmpty()); |
| 93 | 93 |
| 94 return result->Int32Value(); | 94 return result->Int32Value(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void V8NodeFilterCondition::setWeakCallback(const v8::WeakCallbackData<v8::Value
, V8NodeFilterCondition>& data) | 97 void V8NodeFilterCondition::setWeakCallback(const v8::WeakCallbackData<v8::Value
, V8NodeFilterCondition>& data) |
| 98 { | 98 { |
| 99 data.GetParameter()->m_filter.clear(); | 99 data.GetParameter()->m_filter.clear(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace WebCore | 102 } // namespace WebCore |
| OLD | NEW |