This source file includes following definitions.
- m_filter
- acceptNode
- setWeakCallback
#include "config.h"
#include "bindings/v8/V8NodeFilterCondition.h"
#include "V8Node.h"
#include "bindings/v8/ScriptController.h"
#include "bindings/v8/V8HiddenValue.h"
#include "core/dom/Node.h"
#include "core/dom/NodeFilter.h"
#include "wtf/OwnPtr.h"
namespace WebCore {
V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::Handle<v8::Object> owner, v8::Isolate* isolate)
: m_scriptState(NewScriptState::current(isolate))
, m_filter(isolate, filter)
{
V8HiddenValue::setHiddenValue(isolate, owner, V8HiddenValue::condition(isolate), filter);
m_filter.setWeak(this, &setWeakCallback);
}
V8NodeFilterCondition::~V8NodeFilterCondition()
{
}
short V8NodeFilterCondition::acceptNode(Node* node, ExceptionState& exceptionState) const
{
v8::Isolate* isolate = m_scriptState->isolate();
ASSERT(!m_scriptState->context().IsEmpty());
v8::HandleScope handleScope(isolate);
v8::Handle<v8::Value> filter = m_filter.newLocal(isolate);
ASSERT(!filter.IsEmpty());
if (filter.IsEmpty() || !filter->IsObject())
return NodeFilter::FILTER_ACCEPT;
v8::TryCatch exceptionCatcher;
v8::Handle<v8::Function> callback;
if (filter->IsFunction())
callback = v8::Handle<v8::Function>::Cast(filter);
else {
v8::Local<v8::Value> value = filter->ToObject()->Get(v8AtomicString(isolate, "acceptNode"));
if (value.IsEmpty() || !value->IsFunction()) {
throwTypeError("NodeFilter object does not have an acceptNode function", isolate);
return NodeFilter::FILTER_REJECT;
}
callback = v8::Handle<v8::Function>::Cast(value);
}
OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Value>[1]);
info[0] = toV8(node, v8::Handle<v8::Object>(), isolate);
v8::Handle<v8::Object> object = m_scriptState->context()->Global();
v8::Handle<v8::Value> result = ScriptController::callFunction(m_scriptState->executionContext(), callback, object, 1, info.get(), isolate);
if (exceptionCatcher.HasCaught()) {
exceptionState.rethrowV8Exception(exceptionCatcher.Exception());
return NodeFilter::FILTER_REJECT;
}
ASSERT(!result.IsEmpty());
return result->Int32Value();
}
void V8NodeFilterCondition::setWeakCallback(const v8::WeakCallbackData<v8::Value, V8NodeFilterCondition>& data)
{
data.GetParameter()->m_filter.clear();
}
}