Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp

Issue 145133008: DevTools: Make getEventListeners() of Console API work for window. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
diff --git a/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
index 408b2a0d314ae456aa11bc2a6365a6bd68db6ab5..b8d8d91567ebdf8fb922ba7b3aca6ff4c5e49687 100644
--- a/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
+++ b/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
@@ -32,17 +32,20 @@
#include "V8InjectedScriptHost.h"
#include "V8Database.h"
+#include "V8EventTarget.h"
#include "V8HTMLAllCollection.h"
#include "V8HTMLCollection.h"
#include "V8Node.h"
#include "V8NodeList.h"
#include "V8Storage.h"
+#include "V8Window.h"
#include "bindings/v8/BindingSecurity.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/ScriptDebugServer.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8AbstractEventListener.h"
#include "bindings/v8/V8Binding.h"
+#include "bindings/v8/V8DOMWrapper.h"
#include "bindings/v8/V8HiddenPropertyName.h"
#include "bindings/v8/V8ScriptRunner.h"
#include "bindings/v8/custom/V8Float32ArrayCustom.h"
@@ -241,7 +244,7 @@ void V8InjectedScriptHost::getInternalPropertiesMethodCustom(const v8::FunctionC
v8SetReturnValue(info, debugServer.getInternalProperties(object));
}
-static v8::Handle<v8::Array> getJSListenerFunctions(Document* document, const EventListenerInfo& listenerInfo, v8::Isolate* isolate)
+static v8::Handle<v8::Array> getJSListenerFunctions(ExecutionContext* executionContext, const EventListenerInfo& listenerInfo, v8::Isolate* isolate)
{
v8::Local<v8::Array> result = v8::Array::New(isolate);
size_t handlersCount = listenerInfo.eventListenerVector.size();
@@ -252,7 +255,7 @@ static v8::Handle<v8::Array> getJSListenerFunctions(Document* document, const Ev
continue;
}
V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(listener.get());
- v8::Local<v8::Context> context = toV8Context(document, v8Listener->world());
+ v8::Local<v8::Context> context = toV8Context(executionContext, v8Listener->world());
// Hide listeners from other contexts.
if (context != isolate->GetCurrentContext())
continue;
@@ -260,7 +263,7 @@ static v8::Handle<v8::Array> getJSListenerFunctions(Document* document, const Ev
{
// getListenerObject() may cause JS in the event attribute to get compiled, potentially unsuccessfully.
v8::TryCatch block;
- function = v8Listener->getListenerObject(document);
+ function = v8Listener->getListenerObject(executionContext);
if (block.HasCaught())
continue;
}
@@ -278,20 +281,35 @@ void V8InjectedScriptHost::getEventListenersMethodCustom(const v8::FunctionCallb
if (info.Length() < 1)
return;
+ EventTarget* target = 0;
v8::Local<v8::Value> value = info[0];
- if (!V8Node::hasInstance(value, info.GetIsolate(), worldType(info.GetIsolate())))
- return;
- Node* node = V8Node::toNative(value->ToObject());
- if (!node)
+
+ if (V8EventTarget::hasInstance(value, info.GetIsolate(), worldType(info.GetIsolate())))
+ target = V8EventTarget::toNative(value->ToObject());
+
+ // We need to handle a DOMWindow specially, because a DOMWindow wrapper exists on a prototype chain.
+ if (!target && value->IsObject()) {
+ v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(value);
+ v8::Handle<v8::Object> window = wrapper->FindInstanceInPrototypeChain(V8Window::domTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())));
+ if (!window.IsEmpty())
+ target = toWrapperTypeInfo(window)->toEventTarget(window);
+ }
+
+ if (!target && V8DOMWrapper::isDOMWrapper(value)) {
+ v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(value);
+ target = toWrapperTypeInfo(wrapper)->toEventTarget(wrapper);
+ }
+
+ if (!target || !target->executionContext())
return;
InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder());
Vector<EventListenerInfo> listenersArray;
- host->getEventListenersImpl(node, listenersArray);
+ host->getEventListenersImpl(target, listenersArray);
v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate());
for (size_t i = 0; i < listenersArray.size(); ++i) {
- v8::Handle<v8::Array> listeners = getJSListenerFunctions(&node->document(), listenersArray[i], info.GetIsolate());
+ v8::Handle<v8::Array> listeners = getJSListenerFunctions(target->executionContext(), listenersArray[i], info.GetIsolate());
if (!listeners->Length())
continue;
AtomicString eventType = listenersArray[i].eventType;

Powered by Google App Engine
This is Rietveld 408576698