summaryrefslogtreecommitdiffstats
path: root/webkit/port/bindings/v8/v8_events.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/port/bindings/v8/v8_events.cpp')
-rw-r--r--webkit/port/bindings/v8/v8_events.cpp106
1 files changed, 33 insertions, 73 deletions
diff --git a/webkit/port/bindings/v8/v8_events.cpp b/webkit/port/bindings/v8/v8_events.cpp
index ff0ef27..d0ff3ba 100644
--- a/webkit/port/bindings/v8/v8_events.cpp
+++ b/webkit/port/bindings/v8/v8_events.cpp
@@ -146,6 +146,24 @@ void V8AbstractEventListener::DisposeListenerObject() {
}
+v8::Local<v8::Object> V8AbstractEventListener::GetReceiverObject(
+ Event* event,
+ bool isWindowEvent) {
+ if (!m_listener.IsEmpty() && !m_listener->IsFunction()) {
+ return v8::Local<v8::Object>::New(m_listener);
+ }
+
+ if (isWindowEvent) {
+ return v8::Context::GetCurrent()->Global();
+ }
+
+ EventTarget* target = event->currentTarget();
+ v8::Handle<v8::Value> value = V8Proxy::EventTargetToV8Object(target);
+ if (value.IsEmpty()) return v8::Local<v8::Object>();
+ return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
+}
+
+
V8EventListener::V8EventListener(Frame* frame, v8::Local<v8::Object> listener,
bool isInline)
: V8AbstractEventListener(frame, isInline) {
@@ -191,68 +209,22 @@ v8::Local<v8::Value>
V8EventListener::CallListenerFunction(v8::Handle<v8::Value> jsevent,
Event* event, bool isWindowEvent) {
v8::Local<v8::Function> handler_func = GetListenerFunction();
- if (handler_func.IsEmpty()) return v8::Local<v8::Value>();
-
- v8::Local<v8::Object> this_obj = GetThisObject(event, isWindowEvent);
- v8::Handle<v8::Value> parameters[1] = {jsevent};
-
- V8Proxy* proxy = V8Proxy::retrieve(m_frame);
- ASSERT(proxy);
-
- return proxy->CallFunction(handler_func, this_obj, 1, parameters);
-}
-
-
-v8::Local<v8::Object> V8EventListener::GetThisObject(Event* event,
- bool isWindowEvent) {
- if (!m_listener.IsEmpty() && !m_listener->IsFunction()) {
- return v8::Local<v8::Object>::New(m_listener);
- }
-
- if (isWindowEvent) {
- return v8::Context::GetCurrent()->Global();
+ v8::Local<v8::Object> receiver = GetReceiverObject(event, isWindowEvent);
+ if (handler_func.IsEmpty() || receiver.IsEmpty()) {
+ return v8::Local<v8::Value>();
}
- // make sure to sync type conversions with V8Proxy::EventTargetToV8Object
- EventTarget* target = event->currentTarget();
- if (target->toNode()) {
- v8::Handle<v8::Value> value =
- V8Proxy::NodeToV8Object(target->toNode());
- return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
-
- } else if (target->toXMLHttpRequest()) {
- v8::Handle<v8::Value> value = V8Proxy::ToV8Object(
- V8ClassIndex::XMLHTTPREQUEST, target->toXMLHttpRequest());
- return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
-
- } else if (target->toXMLHttpRequestUpload()) {
- v8::Handle<v8::Value> value = V8Proxy::ToV8Object(
- V8ClassIndex::XMLHTTPREQUESTUPLOAD, target->toXMLHttpRequestUpload());
- return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
-
- } else if (target->toMessagePort()) {
- v8::Handle<v8::Value> value = V8Proxy::ToV8Object(
- V8ClassIndex::MESSAGEPORT, target->toMessagePort());
- return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
-
-#if ENABLE(SVG)
- } else if (target->toSVGElementInstance()) {
- v8::Handle<v8::Value> value = V8Proxy::ToV8Object(
- V8ClassIndex::SVGELEMENTINSTANCE, target->toSVGElementInstance());
- return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
-#endif
+ v8::Handle<v8::Value> parameters[1] = { jsevent };
- } else {
- ASSERT(false);
- return v8::Local<v8::Object>();
- }
+ V8Proxy* proxy = V8Proxy::retrieve(m_frame);
+ return proxy->CallFunction(handler_func, receiver, 1, parameters);
}
// ------- V 8 X H R E v e n t L i s t e n e r -----------------
static void WeakObjectEventListenerCallback(v8::Persistent<v8::Value> obj,
- void* para) {
+ void* para) {
V8ObjectEventListener* listener = static_cast<V8ObjectEventListener*>(para);
// Remove the wrapper
@@ -274,8 +246,8 @@ static void WeakObjectEventListenerCallback(v8::Persistent<v8::Value> obj,
V8ObjectEventListener::V8ObjectEventListener(Frame* frame,
- v8::Local<v8::Object> listener,
- bool isInline)
+ v8::Local<v8::Object> listener,
+ bool isInline)
: V8EventListener(frame, listener, isInline) {
// make m_listener weak.
m_listener.MakeWeak(this, WeakObjectEventListenerCallback);
@@ -318,20 +290,6 @@ V8LazyEventListener::~V8LazyEventListener() {
}
-v8::Local<v8::Object> V8LazyEventListener::GetThisObject(Event* event,
- bool isWindowEvent) {
- if (isWindowEvent) {
- return v8::Context::GetCurrent()->Global();
- }
-
- v8::Handle<v8::Value> value =
- V8Proxy::NodeToV8Object(event->currentTarget()->toNode());
- ASSERT(!value.IsEmpty());
-
- return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
-}
-
-
v8::Local<v8::Function> V8LazyEventListener::GetListenerFunction() {
if (m_compiled) {
ASSERT(m_listener.IsEmpty() || m_listener->IsFunction());
@@ -409,14 +367,16 @@ v8::Local<v8::Function> V8LazyEventListener::GetListenerFunction() {
v8::Local<v8::Value>
V8LazyEventListener::CallListenerFunction(v8::Handle<v8::Value> jsevent,
Event* event, bool isWindowEvent) {
- v8::Local<v8::Object> this_obj = GetThisObject(event, isWindowEvent);
v8::Local<v8::Function> handler_func = GetWrappedListenerFunction();
- if (handler_func.IsEmpty()) return v8::Local<v8::Value>();
+ v8::Local<v8::Object> receiver = GetReceiverObject(event, isWindowEvent);
+ if (handler_func.IsEmpty() || receiver.IsEmpty()) {
+ return v8::Local<v8::Value>();
+ }
- v8::Handle<v8::Value> parameters[1] = {jsevent};
+ v8::Handle<v8::Value> parameters[1] = { jsevent };
V8Proxy* proxy = V8Proxy::retrieve(m_frame);
- return proxy->CallFunction(handler_func, this_obj, 1, parameters);
+ return proxy->CallFunction(handler_func, receiver, 1, parameters);
}