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

Unified Diff: Source/bindings/templates/methods.cpp

Issue 70963003: IDL compiler: addEventListener, removeEventListener methods (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Other test Created 7 years, 1 month 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/templates/methods.cpp
diff --git a/Source/bindings/templates/methods.cpp b/Source/bindings/templates/methods.cpp
index c77ffcb5f7356182f9ecb5e61d9412ceb6908244..516520ba517e9f4fd16522e907fe9bfe7aa0dae9 100644
--- a/Source/bindings/templates/methods.cpp
+++ b/Source/bindings/templates/methods.cpp
@@ -3,6 +3,9 @@
{% filter conditional(method.conditional_string) %}
static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
{
+ {% if method.name in ['addEventListener', 'removeEventListener'] %}
+ {{add_remove_event_listener_method(method.name) | indent}}
+ {% else %}
{% if method.number_of_required_arguments %}
if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", ExceptionMessages::notEnoughArguments({{method.number_of_required_arguments}}, info.Length())), info.GetIsolate());
@@ -85,12 +88,40 @@ static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
{% endif %}
{% endfor %}{# arguments #}
{{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | indent}}
+ {% endif %}{# addEventListener, removeEventListener #}
}
{% endfilter %}
{% endmacro %}
{######################################}
+{% macro add_remove_event_listener_method(method_name) %}
+{% set lookup_type, pass_ref_ptr_handling, hidden_dependency_action =
haraken 2013/11/13 08:33:53 Actually I don't understand why we need these comp
Nils Barth (inactive) 2013/11/13 11:33:29 Clarified by: * adding a comment, and * making the
haraken 2013/11/13 11:37:46 Can't we somehow get rid of the distinction betwee
Nils Barth (inactive) 2013/11/14 03:01:53 We probably need to generate *some* different code
haraken 2013/11/14 04:33:02 Yeah, I haven't yet checked the code of event list
+ ('OrCreate', '', 'create')
+ if method_name.startswith('add') else
+ ('Only', '.get()', 'remove')
+%}
+EventTarget* impl = {{v8_class_name}}::toNative(info.Holder());
+if (DOMWindow* window = impl->toDOMWindow()) {
+ ExceptionState es(info.GetIsolate());
+ if (!BindingSecurity::shouldAllowAccessToFrame(window->frame(), es)) {
+ es.throwIfNeeded();
+ return;
+ }
+ if (!window->document())
+ return;
+}
+RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1], false, ListenerFind{{lookup_type}});
+if (listener) {
+ V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, stringResource, info[0]);
haraken 2013/11/13 08:33:53 stringResource => eventName ?
Nils Barth (inactive) 2013/11/13 11:33:29 Done.
+ impl->{{method_name}}(stringResource, listener{{pass_ref_ptr_handling}}, info[2]->BooleanValue());
+ if (!impl->toNode())
+ {{hidden_dependency_action}}HiddenDependency(info.Holder(), info[1], {{v8_class_name}}::eventListenerCacheIndex, info.GetIsolate());
haraken 2013/11/13 08:33:53 Probably we need to refactor *HiddenDependency cod
Nils Barth (inactive) 2013/11/13 11:33:29 Got it; added to TODO, and will look into. Quick
haraken 2013/11/14 04:33:02 Regarding hidden dependency, kouhei-san might have
Nils Barth (inactive) 2013/11/14 05:47:20 Thanks, will do!
+}
+{% endmacro %}
+
+
+{######################################}
{% macro cpp_method_call(method, v8_set_return_value, cpp_value) %}
{% if method.is_call_with_script_state %}
ScriptState* currentState = ScriptState::current();

Powered by Google App Engine
This is Rietveld 408576698