This source file includes following definitions.
- getListenerFunction
- callListenerFunction
#include "config.h"
#include "bindings/v8/V8EventListener.h"
#include "bindings/v8/ScriptController.h"
#include "bindings/v8/V8Binding.h"
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
namespace WebCore {
V8EventListener::V8EventListener(v8::Local<v8::Object> listener, bool isAttribute, v8::Isolate* isolate)
: V8AbstractEventListener(isAttribute, DOMWrapperWorld::current(isolate), isolate)
{
setListenerObject(listener);
}
v8::Local<v8::Function> V8EventListener::getListenerFunction(ExecutionContext* context)
{
v8::Local<v8::Object> listener = getListenerObject(context);
if (listener.IsEmpty())
return v8::Local<v8::Function>();
if (listener->IsFunction())
return v8::Local<v8::Function>::Cast(listener);
if (listener->IsObject()) {
ASSERT_WITH_MESSAGE(!isAttribute(), "EventHandler attributes should only accept JS Functions as input.");
v8::Local<v8::Value> property = listener->Get(v8AtomicString(isolate(), "handleEvent"));
if (!property.IsEmpty() && property->IsFunction())
return v8::Local<v8::Function>::Cast(property);
}
return v8::Local<v8::Function>();
}
v8::Local<v8::Value> V8EventListener::callListenerFunction(ExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event)
{
v8::Local<v8::Function> handlerFunction = getListenerFunction(context);
v8::Local<v8::Object> receiver = getReceiverObject(context, event);
if (handlerFunction.IsEmpty() || receiver.IsEmpty())
return v8::Local<v8::Value>();
if (!context)
return v8::Local<v8::Value>();
if (!context->isDocument())
return v8::Local<v8::Value>();
LocalFrame* frame = toDocument(context)->frame();
if (!frame)
return v8::Local<v8::Value>();
if (!frame->script().canExecuteScripts(AboutToExecuteScript))
return v8::Local<v8::Value>();
v8::Handle<v8::Value> parameters[1] = { jsEvent };
return frame->script().callFunction(handlerFunction, receiver, WTF_ARRAY_LENGTH(parameters), parameters);
}
}