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

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: Revised 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
« no previous file with comments | « Source/bindings/scripts/unstable/v8_types.py ('k') | Source/bindings/tests/idls/TestObjectPython.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/templates/methods.cpp
diff --git a/Source/bindings/templates/methods.cpp b/Source/bindings/templates/methods.cpp
index 4d6aebf215d9c8f43bf25aac9a614766ba4bb604..3566e7383dac76a6b7bdf04d72fae02fc04927ef 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,41 @@ 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 template values for addEventListener vs. removeEventListener #}
+{% set listener_lookup_type, listener, hidden_dependency_action =
+ ('ListenerFindOrCreate', 'listener', 'createHiddenDependency')
+ if method_name == 'addEventListener' else
+ ('ListenerFindOnly', 'listener.get()', 'removeHiddenDependency')
+%}
+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, {{listener_lookup_type}});
+if (listener) {
+ V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventName, info[0]);
+ impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue());
+ if (!impl->toNode())
+ {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class_name}}::eventListenerCacheIndex, info.GetIsolate());
+}
+{% endmacro %}
+
+
+{######################################}
{% macro cpp_method_call(method, v8_set_return_value, cpp_value) %}
{% if method.is_call_with_script_state %}
ScriptState* currentState = ScriptState::current();
« no previous file with comments | « Source/bindings/scripts/unstable/v8_types.py ('k') | Source/bindings/tests/idls/TestObjectPython.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698