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

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

Issue 265293004: Create fewer local v8::TryCatch objects in generated bindings code (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: avoid some unused v8::TryCatch objects Created 6 years, 7 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 {% 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 {# Local variables #} 6 {# Local variables #}
7 {% if method.has_exception_state %} 7 {% if method.has_exception_state %}
8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
9 {% endif %} 9 {% endif %}
10 {% if method.number_of_required_arguments %} 10 {% if method.number_of_required_arguments %}
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 {% endif %} 38 {% endif %}
39 {% if method.is_check_security_for_node %} 39 {% if method.is_check_security_for_node %}
40 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) { 40 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) {
41 v8SetReturnValueNull(info); 41 v8SetReturnValueNull(info);
42 exceptionState.throwIfNeeded(); 42 exceptionState.throwIfNeeded();
43 return; 43 return;
44 } 44 }
45 {% endif %} 45 {% endif %}
46 {# Call method #} 46 {# Call method #}
47 {% for argument in method.arguments %} 47 {% if method.arguments %}
48 {{generate_argument(method, argument, world_suffix) | indent}} 48 {{generate_arguments(method, world_suffix) | indent}}
49 {% endfor %} 49 {% endif %}
50 {% if world_suffix %} 50 {% if world_suffix %}
51 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} 51 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}}
52 {% else %} 52 {% else %}
53 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} 53 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}}
54 {% endif %} 54 {% endif %}
55 {# Post-call #} 55 {# Post-call #}
56 {% if method.has_event_listener_argument %} 56 {% if method.has_event_listener_argument %}
57 {{hidden_dependency_action(method.name) | indent}} 57 {{hidden_dependency_action(method.name) | indent}}
58 {% endif %} 58 {% endif %}
59 } 59 }
60 {% endfilter %} 60 {% endfilter %}
61 {% endmacro %} 61 {% endmacro %}
62 62
63 63
64 {######################################} 64 {######################################}
65 {% macro hidden_dependency_action(method_name) %} 65 {% macro hidden_dependency_action(method_name) %}
66 if (listener && !impl->toNode()) 66 if (listener && !impl->toNode())
67 {% if method_name == 'addEventListener' %} 67 {% if method_name == 'addEventListener' %}
68 addHiddenValueToArray(info.Holder(), info[1], {{v8_class}}::eventListenerCac heIndex, info.GetIsolate()); 68 addHiddenValueToArray(info.Holder(), info[1], {{v8_class}}::eventListenerCac heIndex, info.GetIsolate());
69 {% else %}{# method_name == 'removeEventListener' #} 69 {% else %}{# method_name == 'removeEventListener' #}
70 removeHiddenValueFromArray(info.Holder(), info[1], {{v8_class}}::eventListen erCacheIndex, info.GetIsolate()); 70 removeHiddenValueFromArray(info.Holder(), info[1], {{v8_class}}::eventListen erCacheIndex, info.GetIsolate());
71 {% endif %} 71 {% endif %}
72 {% endmacro %} 72 {% endmacro %}
73 73
74 74
75 {######################################} 75 {######################################}
76 {% macro generate_arguments(method, world_suffix) %}
77 {% for argument in method.arguments %}
78 {{generate_argument_var_declaration(argument)}};
79 {% endfor %}
80 {
81 {% if method.arguments_need_try_catch %}
82 v8::TryCatch block;
83 {% endif %}
84 {% for argument in method.arguments %}
85 {{generate_argument(method, argument, world_suffix) | indent}}
86 {% endfor %}
87 }
88 {% endmacro %}
89
90
91 {######################################}
92 {% macro generate_argument_var_declaration(argument) %}
93 {% if argument.is_callback_interface %}
94 {# FIXME: remove EventListener special case #}
95 {% if argument.idl_type == 'EventListener' %}
96 RefPtr<{{argument.idl_type}}> {{argument.name}}
97 {%- else %}
98 OwnPtr<{{argument.idl_type}}> {{argument.name}}
99 {%- endif %}{# argument.idl_type == 'EventListener' #}
100 {%- elif argument.is_clamp %}{# argument.is_callback_interface #}
101 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #}
102 {{argument.cpp_type}} {{argument.name}} = 0
103 {%- elif argument.is_variadic_wrapper_type %}
104 {{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}}
105 {%- else %}
106 {{argument.cpp_type}} {{argument.name}}
107 {%- endif %}
108 {% endmacro %}
109
110
111 {######################################}
76 {% macro generate_argument(method, argument, world_suffix) %} 112 {% macro generate_argument(method, argument, world_suffix) %}
77 {% if argument.is_optional and not argument.has_default and 113 {% if argument.is_optional and not argument.has_default and
78 argument.idl_type != 'Dictionary' and 114 argument.idl_type != 'Dictionary' and
79 not argument.is_callback_interface %} 115 not argument.is_callback_interface %}
80 {# Optional arguments without a default value generate an early call with 116 {# Optional arguments without a default value generate an early call with
81 fewer arguments if they are omitted. 117 fewer arguments if they are omitted.
82 Optional Dictionary arguments default to empty dictionary. #} 118 Optional Dictionary arguments default to empty dictionary. #}
83 if (UNLIKELY(info.Length() <= {{argument.index}})) { 119 if (UNLIKELY(info.Length() <= {{argument.index}})) {
84 {% if world_suffix %} 120 {% if world_suffix %}
85 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum ent.cpp_value) | indent}} 121 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum ent.cpp_value) | indent}}
86 {% else %} 122 {% else %}
87 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}} 123 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}}
88 {% endif %} 124 {% endif %}
89 {% if argument.has_event_listener_argument %} 125 {% if argument.has_event_listener_argument %}
90 {{hidden_dependency_action(method.name) | indent}} 126 {{hidden_dependency_action(method.name) | indent}}
91 {% endif %} 127 {% endif %}
92 return; 128 return;
93 } 129 }
94 {% endif %} 130 {% endif %}
95 {% if argument.has_type_checking_interface %} 131 {% if argument.has_type_checking_interface %}
96 {# Type checking for wrapper interface types (if interface not implemented, 132 {# Type checking for wrapper interface types (if interface not implemented,
97 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} 133 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
98 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())) { 134 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())) {
99 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 135 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
100 (argument.index + 1, argument.idl_type)) | indent }} 136 (argument.index + 1, argument.idl_type)) | indent }}
101 return; 137 return;
102 } 138 }
103 {% endif %} 139 {% endif %}{# argument.has_type_checking_interface #}
104 {% if argument.is_callback_interface %} 140 {% if argument.is_callback_interface %}
105 {# FIXME: remove EventListener special case #} 141 {# FIXME: remove EventListener special case #}
106 {% if argument.idl_type == 'EventListener' %} 142 {% if argument.idl_type == 'EventListener' %}
107 {% if method.name == 'removeEventListener' %} 143 {% if method.name == 'removeEventListener' %}
108 RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventL istener(info[1], false, ListenerFindOnly); 144 {{argument.name}} = V8EventListenerList::getEventListener(info[1], false, Listen erFindOnly);
109 {% else %}{# method.name == 'addEventListener' #} 145 {% else %}{# method.name == 'addEventListener' #}
110 RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventL istener(info[1], false, ListenerFindOrCreate); 146 {{argument.name}} = V8EventListenerList::getEventListener(info[1], false, Listen erFindOrCreate);
111 {% endif %}{# method.name #} 147 {% endif %}{# method.name #}
112 {% else %} 148 {% else %}{# argument.idl_type == 'EventListener' #}
113 {# Callback functions must be functions: 149 {# Callback functions must be functions:
114 http://www.w3.org/TR/WebIDL/#es-callback-function #} 150 http://www.w3.org/TR/WebIDL/#es-callback-function #}
115 {% if argument.is_optional %} 151 {% if argument.is_optional %}
116 OwnPtr<{{argument.idl_type}}> {{argument.name}};
117 if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind ex}}])) { 152 if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind ex}}])) {
118 if (!info[{{argument.index}}]->IsFunction()) { 153 if (!info[{{argument.index}}]->IsFunction()) {
119 {{throw_type_error(method, 154 {{throw_type_error(method,
120 '"The callback provided as parameter %s is not a function."' % 155 '"The callback provided as parameter %s is not a function."' %
121 (argument.index + 1)) | indent(8)}} 156 (argument.index + 1)) | indent(8)}}
122 return; 157 return;
123 } 158 }
124 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Handle<v8::Function> ::Cast(info[{{argument.index}}]), currentExecutionContext(info.GetIsolate())); 159 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Handle<v8::Function> ::Cast(info[{{argument.index}}]), currentExecutionContext(info.GetIsolate()));
125 } 160 }
126 {% else %} 161 {% else %}{# argument.is_optional #}
127 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) { 162 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) {
128 {{throw_type_error(method, 163 {{throw_type_error(method,
129 '"The callback provided as parameter %s is not a function."' % 164 '"The callback provided as parameter %s is not a function."' %
130 (argument.index + 1)) | indent }} 165 (argument.index + 1)) | indent }}
131 return; 166 return;
132 } 167 }
133 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())); 168 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Handle<v8::Functi on>::Cast(info[{{argument.index}}]), currentExecutionContext(info.GetIsolate())) ;
134 {% endif %}{# argument.is_optional #} 169 {% endif %}{# argument.is_optional #}
135 {% endif %}{# argument.idl_type == 'EventListener' #} 170 {% endif %}{# argument.idl_type == 'EventListener' #}
136 {% elif argument.is_clamp %}{# argument.is_callback_interface #} 171 {% elif argument.is_clamp %}{# argument.is_callback_interface #}
137 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} 172 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #}
138 {{argument.cpp_type}} {{argument.name}} = 0; 173 double {{argument.name}}NativeValue;
139 TONATIVE_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]->Nu mberValue()); 174 TONATIVE_VOID_NO_DECL({{argument.name}}NativeValue, info[{{argument.index}}]->Nu mberValue());
140 if (!std::isnan({{argument.name}}NativeValue)) 175 if (!std::isnan({{argument.name}}NativeValue))
141 {# IDL type is used for clamping, for the right bounds, since different 176 {# IDL type is used for clamping, for the right bounds, since different
142 IDL integer types have same internal C++ type (int or unsigned) #} 177 IDL integer types have same internal C++ type (int or unsigned) #}
143 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa lue); 178 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa lue);
144 {% elif argument.idl_type == 'SerializedScriptValue' %} 179 {% elif argument.idl_type == 'SerializedScriptValue' %}
145 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{a rgument.index}}], 0, 0, exceptionState, info.GetIsolate()); 180 {{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0 , exceptionState, info.GetIsolate());
146 if (exceptionState.throwIfNeeded()) 181 if (exceptionState.throwIfNeeded())
147 return; 182 return;
148 {% elif argument.is_variadic_wrapper_type %} 183 {% elif argument.is_variadic_wrapper_type %}
149 {{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}};
150 for (int i = {{argument.index}}; i < info.Length(); ++i) { 184 for (int i = {{argument.index}}; i < info.Length(); ++i) {
151 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { 185 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) {
152 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 186 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
153 (argument.index + 1, argument.idl_type)) | in dent(8)}} 187 (argument.index + 1, argument.idl_type)) | in dent(8)}}
154 return; 188 return;
155 } 189 }
156 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob ject>::Cast(info[i]))); 190 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob ject>::Cast(info[i])));
157 } 191 }
158 {% else %} 192 {% else %}
159 {{argument.v8_value_to_local_cpp_value}}; 193 {{argument.v8_value_to_local_cpp_value}};
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 {% if constructor.has_exception_state %} 434 {% if constructor.has_exception_state %}
401 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), isolate); 435 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), isolate);
402 {% endif %} 436 {% endif %}
403 {% if interface_length and not constructor.overload_index %} 437 {% if interface_length and not constructor.overload_index %}
404 {# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #} 438 {# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #}
405 if (UNLIKELY(info.Length() < {{interface_length}})) { 439 if (UNLIKELY(info.Length() < {{interface_length}})) {
406 {{throw_arity_type_error(constructor, interface_length)}}; 440 {{throw_arity_type_error(constructor, interface_length)}};
407 return; 441 return;
408 } 442 }
409 {% endif %} 443 {% endif %}
410 {% for argument in constructor.arguments %} 444 {% if constructor.arguments %}
411 {{generate_argument(constructor, argument) | indent}} 445 {{generate_arguments(constructor) | indent}}
412 {% endfor %} 446 {% endif %}
413 {% if is_constructor_call_with_execution_context %} 447 {% if is_constructor_call_with_execution_context %}
414 ExecutionContext* context = currentExecutionContext(isolate); 448 ExecutionContext* context = currentExecutionContext(isolate);
415 {% endif %} 449 {% endif %}
416 {% if is_constructor_call_with_document %} 450 {% if is_constructor_call_with_document %}
417 Document& document = *toDocument(currentExecutionContext(isolate)); 451 Document& document = *toDocument(currentExecutionContext(isolate));
418 {% endif %} 452 {% endif %}
419 {{constructor.cpp_type}} impl = {{cpp_class}}::create({{constructor.argument _list | join(', ')}}); 453 {{constructor.cpp_type}} impl = {{cpp_class}}::create({{constructor.argument _list | join(', ')}});
420 {% if is_constructor_raises_exception %} 454 {% if is_constructor_raises_exception %}
421 if (exceptionState.throwIfNeeded()) 455 if (exceptionState.throwIfNeeded())
422 return; 456 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 500
467 {% if constructor.has_exception_state %} 501 {% if constructor.has_exception_state %}
468 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), isolate); 502 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), isolate);
469 {% endif %} 503 {% endif %}
470 {% if constructor.number_of_required_arguments %} 504 {% if constructor.number_of_required_arguments %}
471 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { 505 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) {
472 {{throw_arity_type_error(constructor, constructor.number_of_required_arg uments)}}; 506 {{throw_arity_type_error(constructor, constructor.number_of_required_arg uments)}};
473 return; 507 return;
474 } 508 }
475 {% endif %} 509 {% endif %}
476 {% for argument in constructor.arguments %} 510 {% if constructor.arguments %}
477 {{generate_argument(constructor, argument) | indent}} 511 {{generate_arguments(constructor) | indent}}
478 {% endfor %} 512 {% endif %}
479 {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{cons tructor.argument_list | join(', ')}}); 513 {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{cons tructor.argument_list | join(', ')}});
480 {% if is_constructor_raises_exception %} 514 {% if is_constructor_raises_exception %}
481 if (exceptionState.throwIfNeeded()) 515 if (exceptionState.throwIfNeeded())
482 return; 516 return;
483 {% endif %} 517 {% endif %}
484 518
485 {{generate_constructor_wrapper(constructor) | indent}} 519 {{generate_constructor_wrapper(constructor) | indent}}
486 } 520 }
487 {% endmacro %} 521 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698