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

Side by Side Diff: Source/bindings/core/v8/ScriptEventListener.cpp

Issue 1268353005: [DevTools] Support JQuery event listeners (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 ScriptController& scriptController = frame->script(); 81 ScriptController& scriptController = frame->script();
82 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) 82 if (!scriptController.canExecuteScripts(AboutToExecuteScript))
83 return nullptr; 83 return nullptr;
84 84
85 TextPosition position = scriptController.eventHandlerPosition(); 85 TextPosition position = scriptController.eventHandlerPosition();
86 String sourceURL = frame->document()->url().string(); 86 String sourceURL = frame->document()->url().string();
87 87
88 return V8LazyEventListener::create(name.localName(), eventParameterName, val ue, sourceURL, position, 0, toIsolate(frame)); 88 return V8LazyEventListener::create(name.localName(), eventParameterName, val ue, sourceURL, position, 0, toIsolate(frame));
89 } 89 }
90 90
91 static v8::MaybeLocal<v8::Function> eventListenerEffectiveFunction(v8::Isolate* isolate, v8::Local<v8::Context> context, v8::Local<v8::Object> listenerObject) 91 v8::Local<v8::Object> eventListenerHandler(ExecutionContext* executionContext, E ventListener* listener)
92 { 92 {
93 if (listenerObject->IsFunction()) { 93 if (listener->type() != EventListener::JSEventListenerType)
94 return v8::MaybeLocal<v8::Function>(listenerObject.As<v8::Function>()); 94 return v8::Local<v8::Object>();
95 } else if (listenerObject->IsObject()) { 95 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>( listener);
96 // Try the "handleEvent" method (EventListener interface). 96 return v8Listener->getListenerObject(executionContext);
97 v8::Local<v8::Value> property;
98 if (listenerObject->Get(context, v8AtomicString(isolate, "handleEvent")) .ToLocal(&property) && property->IsFunction())
99 return v8::MaybeLocal<v8::Function>(property.As<v8::Function>());
100 // Fall back to the "constructor" property.
101 if (listenerObject->Get(context, v8AtomicString(isolate, "constructor")) .ToLocal(&property) && property->IsFunction())
102 return v8::MaybeLocal<v8::Function>(property.As<v8::Function>());
103 }
104 return v8::MaybeLocal<v8::Function>();
105 } 97 }
106 98
107 ScriptValue eventListenerHandler(ExecutionContext* executionContext, EventListen er* listener) 99 v8::Local<v8::Function> eventListenerEffectiveFunction(v8::Isolate* isolate, v8: :Local<v8::Object> handler)
108 { 100 {
109 if (listener->type() != EventListener::JSEventListenerType) 101 v8::Local<v8::Function> function;
110 return ScriptValue(); 102 if (handler->IsFunction()) {
111 103 function = handler.As<v8::Function>();
112 v8::Isolate* isolate = toIsolate(executionContext); 104 } else if (handler->IsObject()) {
113 v8::HandleScope scope(isolate); 105 v8::Local<v8::Value> property;
114 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>( listener); 106 // Try the "handleEvent" method (EventListener interface).
115 v8::Local<v8::Context> context = toV8Context(executionContext, v8Listener->w orld()); 107 if (handler->Get(handler->CreationContext(), v8AtomicString(isolate, "ha ndleEvent")).ToLocal(&property) && property->IsFunction())
116 v8::Context::Scope contextScope(context); 108 function = property.As<v8::Function>();
117 v8::Local<v8::Object> function = v8Listener->getListenerObject(executionCont ext); 109 // Fall back to the "constructor" property.
118 if (function.IsEmpty()) 110 else if (handler->Get(handler->CreationContext(), v8AtomicString(isolate , "constructor")).ToLocal(&property) && property->IsFunction())
119 return ScriptValue(); 111 function = property.As<v8::Function>();
120 return ScriptValue(ScriptState::from(context), function); 112 }
113 if (!function.IsEmpty())
114 return getBoundFunction(function);
115 return v8::Local<v8::Function>();
121 } 116 }
122 117
123 ScriptState* eventListenerHandlerScriptState(LocalFrame* frame, EventListener* l istener) 118 void functionLocation(v8::Local<v8::Function> function, String& scriptId, int& l ineNumber, int& columnNumber)
yurys 2015/08/11 21:10:24 style: getFunctionLocation since we use return par
kozy 2015/08/12 18:02:22 Done.
124 { 119 {
125 if (listener->type() != EventListener::JSEventListenerType) 120 int scriptIdValue = function->ScriptId();
126 return 0;
127 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>( listener);
128 v8::HandleScope scope(toIsolate(frame));
129 v8::Local<v8::Context> v8Context = frame->script().windowProxy(v8Listener->w orld())->context();
130 return ScriptState::from(v8Context);
131 }
132
133 bool eventListenerHandlerLocation(ExecutionContext* executionContext, EventListe ner* listener, String& scriptId, int& lineNumber, int& columnNumber)
134 {
135 if (listener->type() != EventListener::JSEventListenerType)
136 return false;
137
138 v8::HandleScope scope(toIsolate(executionContext));
139 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>( listener);
140 v8::Local<v8::Context> context = toV8Context(executionContext, v8Listener->w orld());
141 v8::Context::Scope contextScope(context);
142 v8::Local<v8::Object> object = v8Listener->getListenerObject(executionContex t);
143 if (object.IsEmpty())
144 return false;
145 v8::Local<v8::Function> function;
146 if (!eventListenerEffectiveFunction(scope.GetIsolate(), context, object).ToL ocal(&function))
147 return false;
148 v8::Local<v8::Function> originalFunction = getBoundFunction(function);
149 int scriptIdValue = originalFunction->ScriptId();
150 scriptId = String::number(scriptIdValue); 121 scriptId = String::number(scriptIdValue);
151 lineNumber = originalFunction->GetScriptLineNumber(); 122 lineNumber = function->GetScriptLineNumber();
152 columnNumber = originalFunction->GetScriptColumnNumber(); 123 columnNumber = function->GetScriptColumnNumber();
153 return true;
154 } 124 }
155 125
156 } // namespace blink 126 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698