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

Side by Side Diff: Source/bindings/templates/methods.cpp

Issue 203143002: Simplify EventTarget bindings generation (2) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add test Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/tests/idls/TestObjectPython.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.has_exception_state %} 6 {% if method.has_exception_state %}
7 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 7 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
8 {% endif %} 8 {% endif %}
9 {# FIXME: remove these special cases: http://crbug.com/353484 #} 9 {# FIXME: remove these special cases: http://crbug.com/353484 #}
10 {% if method.number_of_required_arguments and not 10 {% if method.number_of_required_arguments and not
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 {% endif %} 33 {% endif %}
34 {% if method.is_check_security_for_node %} 34 {% if method.is_check_security_for_node %}
35 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) { 35 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) {
36 v8SetReturnValueNull(info); 36 v8SetReturnValueNull(info);
37 exceptionState.throwIfNeeded(); 37 exceptionState.throwIfNeeded();
38 return; 38 return;
39 } 39 }
40 {% endif %} 40 {% endif %}
41 {# Call method #} 41 {# Call method #}
42 {% if interface_name == 'EventTarget' and
43 method.name in ['addEventListener', 'removeEventListener'] %}
44 {{add_event_listener_remove_event_listener_method(method.name) | indent}}
45 {% else %}
46 {% for argument in method.arguments %} 42 {% for argument in method.arguments %}
47 {{generate_argument(method, argument, world_suffix) | indent}} 43 {{generate_argument(method, argument, world_suffix) | indent}}
48 {% endfor %} 44 {% endfor %}
45 {% if interface_name == 'EventTarget' and
46 method.name in ['addEventListener', 'removeEventListener'] %}
47 {# FIXME: can we move this |listener| check into Blink and
48 hidden_dependency_action? I.e., "if (!listener) return;" in Blink
49 and "if (listener && !impl->toNode())" in hidden_dependency_action} #}
50 if (!listener)
51 return;
52 {% endif %}
49 {% if world_suffix %} 53 {% if world_suffix %}
50 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} 54 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}}
51 {% else %} 55 {% else %}
52 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} 56 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}}
53 {% endif %} 57 {% endif %}
54 {% endif %}{# addEventListener, removeEventListener #} 58 {% if interface_name == 'EventTarget' and
59 method.name in ['addEventListener', 'removeEventListener'] %}
60 {{hidden_dependency_action(method.name) | indent}}
61 {% endif %}
55 } 62 }
56 {% endfilter %} 63 {% endfilter %}
57 {% endmacro %} 64 {% endmacro %}
58 65
59 66
60 {######################################} 67 {######################################}
61 {% macro event_target_check_security_for_frame() %} 68 {% macro event_target_check_security_for_frame() %}
62 {# FIXME: use the existing shouldAllowAccessToFrame check if possible. #} 69 {# FIXME: use the existing shouldAllowAccessToFrame check if possible. #}
63 if (DOMWindow* window = impl->toDOMWindow()) { 70 if (DOMWindow* window = impl->toDOMWindow()) {
64 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr ame(), exceptionState)) { 71 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr ame(), exceptionState)) {
65 exceptionState.throwIfNeeded(); 72 exceptionState.throwIfNeeded();
66 return; 73 return;
67 } 74 }
68 if (!window->document()) 75 if (!window->document())
69 return; 76 return;
70 } 77 }
71 {% endmacro %} 78 {% endmacro %}
72 79
73 80
74 {######################################} 81 {######################################}
75 {% macro add_event_listener_remove_event_listener_method(method_name) %} 82 {% macro hidden_dependency_action(method_name) %}
76 {# Set template values for addEventListener vs. removeEventListener #} 83 if (!impl->toNode())
77 {% set listener_lookup_type, listener, hidden_dependency_action = 84 {% if method_name == 'addEventListener' %}
78 ('ListenerFindOrCreate', 'listener', 'addHiddenValueToArray') 85 addHiddenValueToArray(info.Holder(), info[1], {{v8_class}}::eventListenerCac heIndex, info.GetIsolate());
79 if method_name == 'addEventListener' else 86 {% else %}{# method_name == 'removeEventListener' #}
80 ('ListenerFindOnly', 'listener.get()', 'removeHiddenValueFromArray') 87 removeHiddenValueFromArray(info.Holder(), info[1], {{v8_class}}::eventListen erCacheIndex, info.GetIsolate());
81 %} 88 {% endif %}
82 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1], false, {{listener_lookup_type}});
83 if (listener) {
84 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN ame, info[0]);
85 impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue());
86 if (!impl->toNode())
87 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::event ListenerCacheIndex, info.GetIsolate());
88 }
89 {% endmacro %} 89 {% endmacro %}
90 90
91 91
92 {######################################} 92 {######################################}
93 {% macro generate_argument(method, argument, world_suffix) %} 93 {% macro generate_argument(method, argument, world_suffix) %}
94 {% if argument.is_optional and not argument.has_default and 94 {% if argument.is_optional and not argument.has_default and
95 argument.idl_type != 'Dictionary' and 95 argument.idl_type != 'Dictionary' and
96 not argument.is_callback_interface %} 96 not argument.is_callback_interface %}
97 {# Optional arguments without a default value generate an early call with 97 {# Optional arguments without a default value generate an early call with
98 fewer arguments if they are omitted. 98 fewer arguments if they are omitted.
99 Optional Dictionary arguments default to empty dictionary. #} 99 Optional Dictionary arguments default to empty dictionary. #}
100 if (UNLIKELY(info.Length() <= {{argument.index}})) { 100 if (UNLIKELY(info.Length() <= {{argument.index}})) {
101 {% if interface_name == 'EventTarget' %}
102 {# FIXME: can we move this |listener| check into Blink? (see above) #}
103 if (!listener)
104 return;
105 {% endif %}
101 {% if world_suffix %} 106 {% if world_suffix %}
102 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum ent.cpp_value) | indent}} 107 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum ent.cpp_value) | indent}}
103 {% else %} 108 {% else %}
104 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}} 109 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}}
105 {% endif %} 110 {% endif %}
111 {% if interface_name == 'EventTarget' %}
112 {{hidden_dependency_action(method.name) | indent}}
113 {% endif %}
106 return; 114 return;
107 } 115 }
108 {% endif %} 116 {% endif %}
109 {% if method.is_strict_type_checking and argument.is_wrapper_type %} 117 {% if method.is_strict_type_checking and argument.is_wrapper_type %}
110 {# Type checking for wrapper interface types (if interface not implemented, 118 {# Type checking for wrapper interface types (if interface not implemented,
111 throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} 119 throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
112 if (info.Length() > {{argument.index}} && {% if argument.is_nullable %}!isUndefi nedOrNull(info[{{argument.index}}]) && {% endif %}!V8{{argument.idl_type}}::hasI nstance(info[{{argument.index}}], info.GetIsolate())) { 120 if (info.Length() > {{argument.index}} && {% if argument.is_nullable %}!isUndefi nedOrNull(info[{{argument.index}}]) && {% endif %}!V8{{argument.idl_type}}::hasI nstance(info[{{argument.index}}], info.GetIsolate())) {
113 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 121 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
114 (argument.index + 1, argument.idl_type)) | indent }} 122 (argument.index + 1, argument.idl_type)) | indent }}
115 return; 123 return;
116 } 124 }
117 {% endif %} 125 {% endif %}
118 {% if argument.is_callback_interface %} 126 {% if argument.is_callback_interface %}
127 {# FIXME: remove EventListener special case #}
128 {% if argument.idl_type == 'EventListener' %}
129 {% if method.name == 'removeEventListener' %}
130 RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventL istener(info[1], false, ListenerFindOnly);
131 {% else %}{# method.name == 'addEventListener' #}
132 RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventL istener(info[1], false, ListenerFindOrCreate);
133 {% endif %}{# method.name #}
134 {% else %}
119 {% if argument.is_optional %} 135 {% if argument.is_optional %}
120 OwnPtr<{{argument.idl_type}}> {{argument.name}}; 136 OwnPtr<{{argument.idl_type}}> {{argument.name}};
121 if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind ex}}])) { 137 if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind ex}}])) {
122 if (!info[{{argument.index}}]->IsFunction()) { 138 if (!info[{{argument.index}}]->IsFunction()) {
123 {{throw_type_error(method, 139 {{throw_type_error(method,
124 '"The callback provided as parameter %s is not a function."' % 140 '"The callback provided as parameter %s is not a function."' %
125 (argument.index + 1)) | indent(8)}} 141 (argument.index + 1)) | indent(8)}}
126 return; 142 return;
127 } 143 }
128 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Handle<v8::Function> ::Cast(info[{{argument.index}}]), currentExecutionContext(info.GetIsolate())); 144 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Handle<v8::Function> ::Cast(info[{{argument.index}}]), currentExecutionContext(info.GetIsolate()));
129 } 145 }
130 {% else %} 146 {% else %}
131 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) { 147 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) {
132 {{throw_type_error(method, 148 {{throw_type_error(method,
133 '"The callback provided as parameter %s is not a function."' % 149 '"The callback provided as parameter %s is not a function."' %
134 (argument.index + 1)) | indent }} 150 (argument.index + 1)) | indent }}
135 return; 151 return;
136 } 152 }
137 OwnPtr<{{argument.idl_type}}> {{argument.name}} = {% if argument.is_nullable %}i nfo[{{argument.index}}]->IsNull() ? nullptr : {% endif %}V8{{argument.idl_type}} ::create(v8::Handle<v8::Function>::Cast(info[{{argument.index}}]), currentExecut ionContext(info.GetIsolate())); 153 OwnPtr<{{argument.idl_type}}> {{argument.name}} = {% if argument.is_nullable %}i nfo[{{argument.index}}]->IsNull() ? nullptr : {% endif %}V8{{argument.idl_type}} ::create(v8::Handle<v8::Function>::Cast(info[{{argument.index}}]), currentExecut ionContext(info.GetIsolate()));
138 {% endif %}{# argument.is_optional #} 154 {% endif %}{# argument.is_optional #}
155 {% endif %}{# argument.idl_type == 'EventListener' #}
139 {% elif argument.is_clamp %}{# argument.is_callback_interface #} 156 {% elif argument.is_clamp %}{# argument.is_callback_interface #}
140 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} 157 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #}
141 {{argument.cpp_type}} {{argument.name}} = 0; 158 {{argument.cpp_type}} {{argument.name}} = 0;
142 V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]-> NumberValue()); 159 V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]-> NumberValue());
143 if (!std::isnan({{argument.name}}NativeValue)) 160 if (!std::isnan({{argument.name}}NativeValue))
144 {# IDL type is used for clamping, for the right bounds, since different 161 {# IDL type is used for clamping, for the right bounds, since different
145 IDL integer types have same internal C++ type (int or unsigned) #} 162 IDL integer types have same internal C++ type (int or unsigned) #}
146 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa lue); 163 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa lue);
147 {% elif argument.idl_type == 'SerializedScriptValue' %} 164 {% elif argument.idl_type == 'SerializedScriptValue' %}
148 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{a rgument.index}}], 0, 0, exceptionState, info.GetIsolate()); 165 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{a rgument.index}}], 0, 0, exceptionState, info.GetIsolate());
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 v8::Handle<v8::Object> wrapper = info.Holder(); 454 v8::Handle<v8::Object> wrapper = info.Holder();
438 {% if is_constructor_raises_exception %} 455 {% if is_constructor_raises_exception %}
439 if (exceptionState.throwIfNeeded()) 456 if (exceptionState.throwIfNeeded())
440 return; 457 return;
441 {% endif %} 458 {% endif %}
442 459
443 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8 _class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu ration::Dependent); 460 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8 _class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu ration::Dependent);
444 v8SetReturnValue(info, wrapper); 461 v8SetReturnValue(info, wrapper);
445 } 462 }
446 {% endmacro %} 463 {% endmacro %}
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/tests/idls/TestObjectPython.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698