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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 {##############################################################################} 1 {##############################################################################}
2 {% macro generate_method(method, world_suffix) %} 2 {% macro generate_method(method, world_suffix) %}
3 {% filter conditional(method.conditional_string) %} 3 {% filter conditional(method.conditional_string) %}
4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
5 { 5 {
6 {% if method.name in ['addEventListener', 'removeEventListener'] %}
7 {{add_remove_event_listener_method(method.name) | indent}}
8 {% else %}
6 {% if method.number_of_required_arguments %} 9 {% if method.number_of_required_arguments %}
7 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { 10 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
8 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{ interface_name}}", ExceptionMessages::notEnoughArguments({{method.number_of_requ ired_arguments}}, info.Length())), info.GetIsolate()); 11 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{ interface_name}}", ExceptionMessages::notEnoughArguments({{method.number_of_requ ired_arguments}}, info.Length())), info.GetIsolate());
9 return; 12 return;
10 } 13 }
11 {% endif %} 14 {% endif %}
12 {% if not method.is_static %} 15 {% if not method.is_static %}
13 {{cpp_class_name}}* imp = {{v8_class_name}}::toNative(info.Holder()); 16 {{cpp_class_name}}* imp = {{v8_class_name}}::toNative(info.Holder());
14 {% endif %} 17 {% endif %}
15 {% if method.is_custom_element_callbacks %} 18 {% if method.is_custom_element_callbacks %}
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 81 }
79 {% endif %} 82 {% endif %}
80 {% if argument.idl_type in ['Dictionary', 'Promise'] %} 83 {% if argument.idl_type in ['Dictionary', 'Promise'] %}
81 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { 84 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) {
82 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{ interface_name}}", "parameter {{argument.index + 1}} ('{{argument.name}}') is no t an object."), info.GetIsolate()); 85 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{ interface_name}}", "parameter {{argument.index + 1}} ('{{argument.name}}') is no t an object."), info.GetIsolate());
83 return; 86 return;
84 } 87 }
85 {% endif %} 88 {% endif %}
86 {% endfor %}{# arguments #} 89 {% endfor %}{# arguments #}
87 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} 90 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}}
91 {% endif %}{# addEventListener, removeEventListener #}
88 } 92 }
89 {% endfilter %} 93 {% endfilter %}
90 {% endmacro %} 94 {% endmacro %}
91 95
92 96
93 {######################################} 97 {######################################}
98 {% macro add_remove_event_listener_method(method_name) %}
99 {# Set template values for addEventListener vs. removeEventListener #}
100 {% set listener_lookup_type, listener, hidden_dependency_action =
101 ('ListenerFindOrCreate', 'listener', 'createHiddenDependency')
102 if method_name == 'addEventListener' else
103 ('ListenerFindOnly', 'listener.get()', 'removeHiddenDependency')
104 %}
105 EventTarget* impl = {{v8_class_name}}::toNative(info.Holder());
106 if (DOMWindow* window = impl->toDOMWindow()) {
107 ExceptionState es(info.GetIsolate());
108 if (!BindingSecurity::shouldAllowAccessToFrame(window->frame(), es)) {
109 es.throwIfNeeded();
110 return;
111 }
112 if (!window->document())
113 return;
114 }
115 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1], false, {{listener_lookup_type}});
116 if (listener) {
117 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN ame, info[0]);
118 impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue());
119 if (!impl->toNode())
120 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class_name}}:: eventListenerCacheIndex, info.GetIsolate());
121 }
122 {% endmacro %}
123
124
125 {######################################}
94 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} 126 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %}
95 {% if method.is_call_with_script_state %} 127 {% if method.is_call_with_script_state %}
96 ScriptState* currentState = ScriptState::current(); 128 ScriptState* currentState = ScriptState::current();
97 if (!currentState) 129 if (!currentState)
98 return; 130 return;
99 ScriptState& state = *currentState; 131 ScriptState& state = *currentState;
100 {% endif %} 132 {% endif %}
101 {% if method.is_call_with_execution_context %} 133 {% if method.is_call_with_execution_context %}
102 ExecutionContext* scriptContext = getExecutionContext(); 134 ExecutionContext* scriptContext = getExecutionContext();
103 {% endif %} 135 {% endif %}
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 {% endif %} 202 {% endif %}
171 {% if method.is_custom %} 203 {% if method.is_custom %}
172 {{v8_class_name}}::{{method.name}}MethodCustom(info); 204 {{v8_class_name}}::{{method.name}}MethodCustom(info);
173 {% else %} 205 {% else %}
174 {{cpp_class_name}}V8Internal::{{method.name}}Method{{world_suffix}}(info); 206 {{cpp_class_name}}V8Internal::{{method.name}}Method{{world_suffix}}(info);
175 {% endif %} 207 {% endif %}
176 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 208 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
177 } 209 }
178 {% endfilter %} 210 {% endfilter %}
179 {% endmacro %} 211 {% endmacro %}
OLDNEW
« 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