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

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

Issue 2301993002: binding: Introduces ExceptionToPromiseScope. (Closed)
Patch Set: . Created 4 years, 3 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 {% from 'utilities.cpp' import declare_enum_validation_variable, v8_value_to_loc al_cpp_value %} 1 {% from 'utilities.cpp' import declare_enum_validation_variable, v8_value_to_loc al_cpp_value %}
2 2
3 {##############################################################################} 3 {##############################################################################}
4 {% macro generate_method(method, world_suffix) %} 4 {% macro generate_method(method, world_suffix) %}
5 {% if method.returns_promise and method.has_exception_state %}
6 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat e)
7 {% else %}
8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
9 {% endif %} 6 {% filter format_remove_duplicates([
7 'ScriptState* scriptState = ']) %}
haraken 2016/09/02 16:24:13 Honestly speaking, I'm neutral about this formatte
Yuki 2016/09/05 07:19:25 I'm not sure what is the best way, but we definite
haraken 2016/09/05 08:24:22 I won't object if you strongly want to do this, bu
10 { 8 {
11 {# Local variables #} 9 {# Local variables #}
12 {% if method.has_exception_state and not method.returns_promise %} 10 {% if method.has_exception_state %}
13 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 11 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo ntext, "{{interface_name}}", "{{method.name}}");
12 {% if method.returns_promise %}
13 {% if method.is_static %}
14 ScriptState* scriptState = ScriptState::forFunctionObject(info);
15 {% else %}
16 ScriptState* scriptState = ScriptState::forReceiverObject(info);
14 {% endif %} 17 {% endif %}
18 ExceptionToPromiseScope exceptionToPromiseScope(info, scriptState, exception State);
19 {% endif %}
20 {% endif %}
21
15 {# Overloaded methods have length checked during overload resolution #} 22 {# Overloaded methods have length checked during overload resolution #}
16 {% if method.number_of_required_arguments and not method.overload_index %} 23 {% if method.number_of_required_arguments and
24 not method.overload_index %}
17 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { 25 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
18 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}} 26 {{throw_minimum_arity_error(method, method.number_of_required_arguments) }}
27 return;
19 } 28 }
20 {% endif %} 29 {% endif %}
30
21 {% if not method.is_static %} 31 {% if not method.is_static %}
22 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 32 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
23 {% endif %} 33 {% endif %}
34
24 {% if method.is_custom_element_callbacks %} 35 {% if method.is_custom_element_callbacks %}
25 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 36 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
26 {% endif %} 37 {% endif %}
38
27 {# Security checks #} 39 {# Security checks #}
28 {% if method.is_check_security_for_receiver %} 40 {% if method.is_check_security_for_receiver %}
29 {% if interface_name == 'EventTarget' %} 41 {% if interface_name == 'EventTarget' %}
30 // Performance hack for EventTarget. Checking whether it's a Window or not 42 // Performance hack for EventTarget. Checking whether it's a Window or not
31 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30% 43 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30%
32 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE 44 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE
33 // didn't work in this case. 45 // didn't work in this case.
34 if (const DOMWindow* window = impl->toDOMWindow()) { 46 if (const DOMWindow* window = impl->toDOMWindow()) {
35 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsola te()), window, exceptionState)) { 47 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsola te()), window, exceptionState)) {
36 return; 48 return;
37 } 49 }
38 } 50 }
39 {% else %}{# interface_name == 'EventTarget' #} 51 {% else %}{# interface_name == 'EventTarget' #}
40 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), impl, exceptionState)) { 52 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), impl, exceptionState)) {
41 return; 53 return;
42 } 54 }
43 {% endif %}{# interface_name == 'EventTarget' #} 55 {% endif %}{# interface_name == 'EventTarget' #}
44 {% endif %} 56 {% endif %}
45 {% if method.is_check_security_for_return_value %} 57 {% if method.is_check_security_for_return_value %}
46 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), {{method.cpp_value}}, exceptionState)) { 58 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), {{method.cpp_value}}, exceptionState)) {
47 v8SetReturnValueNull(info); 59 v8SetReturnValueNull(info);
48 return; 60 return;
49 } 61 }
50 {% endif %} 62 {% endif %}
63
51 {# Call method #} 64 {# Call method #}
65 {% if method.is_call_with_script_state or
66 method.is_call_with_this_value %}
67 {% if method.is_static %}
68 ScriptState* scriptState = ScriptState::forFunctionObject(info);
69 {% else %}
70 ScriptState* scriptState = ScriptState::forReceiverObject(info);
71 {% endif %}
72 {% endif %}
52 {% if method.arguments %} 73 {% if method.arguments %}
53 {{generate_arguments(method, world_suffix) | indent}} 74 {{generate_arguments(method, world_suffix) | indent}}
54 {% endif %} 75 {% endif %}
55 {% if world_suffix %} 76 {% if world_suffix %}
56 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} 77 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}}
57 {% else %} 78 {% else %}
58 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} 79 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}}
59 {% endif %} 80 {% endif %}
60 } 81 }
61 {% if method.returns_promise and method.has_exception_state %} 82 {% endfilter %}
62
63 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
64 {
65 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
66 {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promise(info, exceptionState);
67 if (exceptionState.hadException())
68 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.G etIsolate())).v8Value());
69 }
70 {% endif %}
71 {% endmacro %} 83 {% endmacro %}
72 84
73 85
74 {######################################} 86 {######################################}
75 {% macro generate_arguments(method, world_suffix) %} 87 {% macro generate_arguments(method, world_suffix) %}
76 {% for argument in method.arguments %} 88 {% for argument in method.arguments %}
77 {{argument.cpp_type}} {{argument.name}}; 89 {{argument.cpp_type}} {{argument.name}};
78 {% endfor %} 90 {% endfor %}
79 { 91 {
80 {% if method.has_optional_argument_without_default_value %} 92 {% if method.has_optional_argument_without_default_value %}
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 {{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(i nfo.GetIsolate()), info[{{argument.index}}], false, ListenerFindOrCreate); 142 {{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(i nfo.GetIsolate()), info[{{argument.index}}], false, ListenerFindOrCreate);
131 {% endif %}{# method.name #} 143 {% endif %}{# method.name #}
132 {% else %}{# argument.idl_type == 'EventListener' #} 144 {% else %}{# argument.idl_type == 'EventListener' #}
133 {# Callback functions must be functions: 145 {# Callback functions must be functions:
134 http://www.w3.org/TR/WebIDL/#es-callback-function #} 146 http://www.w3.org/TR/WebIDL/#es-callback-function #}
135 {% if argument.is_optional %} 147 {% if argument.is_optional %}
136 if (!isUndefinedOrNull(info[{{argument.index}}])) { 148 if (!isUndefinedOrNull(info[{{argument.index}}])) {
137 if (!info[{{argument.index}}]->IsFunction()) { 149 if (!info[{{argument.index}}]->IsFunction()) {
138 {{throw_type_error(method, 150 {{throw_type_error(method,
139 '"The callback provided as parameter %s is not a function."' % 151 '"The callback provided as parameter %s is not a function."' %
140 (argument.index + 1)) | indent(8)}} 152 (argument.index + 1))}}
153 return;
141 } 154 }
142 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>: :Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); 155 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>: :Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate()));
143 } else { 156 } else {
144 {{argument.name}} = nullptr; 157 {{argument.name}} = nullptr;
145 } 158 }
146 {% else %}{# argument.is_optional #} 159 {% else %}{# argument.is_optional #}
147 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) { 160 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) {
148 {{throw_type_error(method, 161 {{throw_type_error(method,
149 '"The callback provided as parameter %s is not a function."' % 162 '"The callback provided as parameter %s is not a function."' %
150 (argument.index + 1)) | indent}} 163 (argument.index + 1))}}
164 return;
151 } 165 }
152 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); 166 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate()));
153 {% endif %}{# argument.is_optional #} 167 {% endif %}{# argument.is_optional #}
154 {% endif %}{# argument.idl_type == 'EventListener' #} 168 {% endif %}{# argument.idl_type == 'EventListener' #}
155 {% elif argument.is_callback_function %} 169 {% elif argument.is_callback_function %}
156 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf o[{{argument.index}}]->IsNull(){% endif %}) { 170 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf o[{{argument.index}}]->IsNull(){% endif %}) {
157 {{throw_type_error(method, 171 {{throw_type_error(method,
158 '"The callback provided as parameter %s is not a function."' % 172 '"The callback provided as parameter %s is not a function."' %
159 (argument.index + 1)) | indent}} 173 (argument.index + 1))}}
174 return;
160 } 175 }
161 {{v8_value_to_local_cpp_value(argument)}} 176 {{v8_value_to_local_cpp_value(argument)}}
162 {% elif argument.is_variadic_wrapper_type %} 177 {% elif argument.is_variadic_wrapper_type %}
163 for (int i = {{argument.index}}; i < info.Length(); ++i) { 178 for (int i = {{argument.index}}; i < info.Length(); ++i) {
164 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { 179 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) {
165 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 180 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
166 (argument.index + 1, argument.idl_type)) | in dent(8)}} 181 (argument.index + 1, argument.idl_type))}}
182 return;
167 } 183 }
168 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec t>::Cast(info[i]))); 184 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec t>::Cast(info[i])));
169 } 185 }
170 {% elif argument.is_dictionary %} 186 {% elif argument.is_dictionary %}
171 {% if not argument.use_permissive_dictionary_conversion %} 187 {% if not argument.use_permissive_dictionary_conversion %}
172 {# Dictionaries must have type Undefined, Null or Object: 188 {# Dictionaries must have type Undefined, Null or Object:
173 http://heycam.github.io/webidl/#es-dictionary #} 189 http://heycam.github.io/webidl/#es-dictionary #}
174 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) { 190 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) {
175 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % 191 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' %
176 (argument.index + 1, argument.name)) | indent}} 192 (argument.index + 1, argument.name))}}
193 return;
177 } 194 }
178 {% endif %}{# not argument.use_permissive_dictionary_conversion #} 195 {% endif %}{# not argument.use_permissive_dictionary_conversion #}
179 {{v8_value_to_local_cpp_value(argument)}} 196 {{v8_value_to_local_cpp_value(argument)}}
180 {% elif argument.is_explicit_nullable %} 197 {% elif argument.is_explicit_nullable %}
181 if (!isUndefinedOrNull(info[{{argument.index}}])) { 198 if (!isUndefinedOrNull(info[{{argument.index}}])) {
182 {{v8_value_to_local_cpp_value(argument) | indent}} 199 {{v8_value_to_local_cpp_value(argument) | indent}}
183 } 200 }
184 {% else %}{# argument.is_nullable #} 201 {% else %}{# argument.is_nullable #}
185 {{v8_value_to_local_cpp_value(argument)}} 202 {{v8_value_to_local_cpp_value(argument)}}
186 {% endif %}{# argument.is_nullable #} 203 {% endif %}{# argument.is_nullable #}
187 {# Type checking, possibly throw a TypeError, per: 204 {# Type checking, possibly throw a TypeError, per:
188 http://www.w3.org/TR/WebIDL/#es-type-mapping #} 205 http://www.w3.org/TR/WebIDL/#es-type-mapping #}
189 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %} 206 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %}
190 {# Type checking for wrapper interface types (if interface not implemented, 207 {# Type checking for wrapper interface types (if interface not implemented,
191 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface 208 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface
192 Note: for variadic arguments, the type checking is done for each matched 209 Note: for variadic arguments, the type checking is done for each matched
193 argument instead; see argument.is_variadic_wrapper_type code-path above. #} 210 argument instead; see argument.is_variadic_wrapper_type code-path above. #}
194 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) { 211 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) {
195 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 212 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
196 (argument.index + 1, argument.idl_type)) | indent }} 213 (argument.index + 1, argument.idl_type))}}
214 return;
197 } 215 }
198 {% elif argument.enum_values %} 216 {% elif argument.enum_values %}
199 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} 217 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #}
200 {{declare_enum_validation_variable(argument.enum_values)}} 218 {{declare_enum_validation_variable(argument.enum_values)}}
201 if (!isValidEnum({{argument.name}}, validValues, WTF_ARRAY_LENGTH(validValues), "{{argument.enum_type}}", exceptionState)) { 219 if (!isValidEnum({{argument.name}}, validValues, WTF_ARRAY_LENGTH(validValues), "{{argument.enum_type}}", exceptionState)) {
202 return; 220 return;
203 } 221 }
204 {% elif argument.idl_type == 'Promise' %} 222 {% elif argument.idl_type == 'Promise' %}
205 {# We require this for our implementation of promises, though not in spec: 223 {# We require this for our implementation of promises, though not in spec:
206 http://heycam.github.io/webidl/#es-promise #} 224 http://heycam.github.io/webidl/#es-promise #}
207 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { 225 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) {
208 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % 226 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' %
209 (argument.index + 1, argument.name)) | indent}} 227 (argument.index + 1, argument.name))}}
228 return;
210 } 229 }
211 {% endif %} 230 {% endif %}
212 {% endmacro %} 231 {% endmacro %}
213 232
214 233
215 {######################################} 234 {######################################}
216 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} 235 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %}
217 {% if method.is_custom_call_prologue %} 236 {% if method.is_custom_call_prologue %}
218 {{v8_class}}::{{method.name}}MethodPrologueCustom(info, impl); 237 {{v8_class}}::{{method.name}}MethodPrologueCustom(info, impl);
219 {% endif %} 238 {% endif %}
220 {# Local variables #} 239 {# Local variables #}
221 {% if method.is_call_with_script_state or method.is_call_with_this_value %}
222 {# [ConstructorCallWith=ScriptState] #}
223 {# [CallWith=ScriptState] #}
224 {% if method.is_static %}
225 ScriptState* scriptState = ScriptState::forFunctionObject(info);
226 {% else %}
227 ScriptState* scriptState = ScriptState::forReceiverObject(info);
228 {% endif %}
229 {% endif %}
230 {% if method.is_call_with_execution_context %} 240 {% if method.is_call_with_execution_context %}
231 {# [ConstructorCallWith=ExecutionContext] #} 241 {# [ConstructorCallWith=ExecutionContext] #}
232 {# [CallWith=ExecutionContext] #} 242 {# [CallWith=ExecutionContext] #}
233 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate()); 243 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
234 {% endif %} 244 {% endif %}
235 {% if method.is_call_with_script_arguments %} 245 {% if method.is_call_with_script_arguments %}
236 {# [CallWith=ScriptArguments] #} 246 {# [CallWith=ScriptArguments] #}
237 ScriptArguments* scriptArguments(ScriptArguments::create(scriptState, info, {{me thod.number_of_arguments}})); 247 ScriptArguments* scriptArguments(ScriptArguments::create(scriptState, info, {{me thod.number_of_arguments}}));
238 {% endif %} 248 {% endif %}
239 {% if method.is_call_with_document %} 249 {% if method.is_call_with_document %}
(...skipping 11 matching lines...) Expand all
251 {{method.cpp_type}} result; 261 {{method.cpp_type}} result;
252 {{cpp_value}}; 262 {{cpp_value}};
253 {% elif method.is_constructor %} 263 {% elif method.is_constructor %}
254 {{method.cpp_type}} impl = {{cpp_value}}; 264 {{method.cpp_type}} impl = {{cpp_value}};
255 {% elif method.use_local_result %} 265 {% elif method.use_local_result %}
256 {{method.cpp_type}} result = {{cpp_value}}; 266 {{method.cpp_type}} result = {{cpp_value}};
257 {% endif %} 267 {% endif %}
258 {# Post-call #} 268 {# Post-call #}
259 {% if method.is_raises_exception %} 269 {% if method.is_raises_exception %}
260 if (exceptionState.hadException()) { 270 if (exceptionState.hadException()) {
261 {{propagate_error_with_exception_state(method) | indent}} 271 return;
262 } 272 }
263 {% endif %} 273 {% endif %}
264 {# Set return value #} 274 {# Set return value #}
265 {% if method.is_new_object and not method.do_not_test_new_object %} 275 {% if method.is_new_object and not method.do_not_test_new_object %}
266 // [NewObject] must always create a new wrapper. Check that a wrapper 276 // [NewObject] must always create a new wrapper. Check that a wrapper
267 // does not exist yet. 277 // does not exist yet.
268 DCHECK(!result || DOMDataStore::getWrapper(result, info.GetIsolate()).IsEmpty()) ; 278 DCHECK(!result || DOMDataStore::getWrapper(result, info.GetIsolate()).IsEmpty()) ;
269 {% endif %} 279 {% endif %}
270 {% if method.is_constructor %} 280 {% if method.is_constructor %}
271 {{generate_constructor_wrapper(method)}} 281 {{generate_constructor_wrapper(method)}}
(...skipping 10 matching lines...) Expand all
282 {% if method.is_custom_call_epilogue %} 292 {% if method.is_custom_call_epilogue %}
283 {{v8_class}}::{{method.name}}MethodEpilogueCustom(info, impl); 293 {{v8_class}}::{{method.name}}MethodEpilogueCustom(info, impl);
284 {% endif %} 294 {% endif %}
285 {% endmacro %} 295 {% endmacro %}
286 296
287 297
288 {######################################} 298 {######################################}
289 {% macro throw_type_error(method, error_message) %} 299 {% macro throw_type_error(method, error_message) %}
290 {% if method.has_exception_state %} 300 {% if method.has_exception_state %}
291 exceptionState.throwTypeError({{error_message}}); 301 exceptionState.throwTypeError({{error_message}});
292 {{propagate_error_with_exception_state(method)}} 302 {%- elif method.is_constructor %}
293 {% elif method.idl_type == 'Promise' %} 303 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToC onstruct("{{interface_name}}", {{error_message}}));
294 v8SetReturnValue(info, ScriptPromise::rejectRaw(ScriptState::current(info.GetIso late()), V8ThrowException::createTypeError(info.GetIsolate(), {{type_error_messa ge(method, error_message)}}))); 304 {%- else %}
295 return; 305 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToE xecute("{{method.name}}", "{{interface_name}}", {{error_message}}));
296 {% else %} 306 {%- endif %}
297 V8ThrowException::throwTypeError(info.GetIsolate(), {{type_error_message(method, error_message)}});
298 return;
299 {% endif %}{# method.has_exception_state #}
300 {% endmacro %} 307 {% endmacro %}
301 308
302 309
303 {######################################} 310 {######################################}
304 {% macro type_error_message(method, error_message) %} 311 {% macro throw_minimum_arity_error(method, number_of_required_arguments) %}
305 {% if method.is_constructor %} 312 {% if method.has_exception_state %}
306 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}) 313 throwMinimumArityError(exceptionState, {{number_of_required_arguments}}, info.Le ngth());
314 {%- elif method.is_constructor %}
315 throwMinimumArityErrorForConstructor(info.GetIsolate(), "{{interface_name}}", {{ number_of_required_arguments}}, info.Length());
307 {%- else %} 316 {%- else %}
308 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er ror_message}}) 317 throwMinimumArityErrorForMethod(info.GetIsolate(), "{{interface_name}}", "{{meth od.name}}", {{number_of_required_arguments}}, info.Length());
309 {%- endif %} 318 {%- endif %}
310 {%- endmacro %} 319 {% endmacro %}
311
312
313 {######################################}
314 {% macro propagate_error_with_exception_state(method_or_overloads) %}
315 {% if method_or_overloads.returns_promise_all or
316 method_or_overloads.returns_promise %}
317 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value());
318 {% endif %}
319 return;
320 {%- endmacro %}
321
322
323 {######################################}
324 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %}
325 {% if method.has_exception_state %}
326 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info. Length());
327 {{propagate_error_with_exception_state(method)}}
328 {%- elif method.idl_type == 'Promise' %}
329 v8SetReturnValue(info, ScriptPromise::rejectRaw(ScriptState::current(info.GetIso late()), {{create_minimum_arity_type_error_without_exception_state(method, numbe r_of_required_arguments)}}));
330 return;
331 {%- else %}
332 V8ThrowException::throwException(info.GetIsolate(), {{create_minimum_arity_type_ error_without_exception_state(method, number_of_required_arguments)}});
333 return;
334 {%- endif %}
335 {%- endmacro %}
336
337
338 {######################################}
339 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %}
340 {% if method.is_constructor %}
341 createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "{{interface_name}} ", {{number_of_required_arguments}}, info.Length())
342 {%- else %}
343 createMinimumArityTypeErrorForMethod(info.GetIsolate(), "{{method.name}}", "{{in terface_name}}", {{number_of_required_arguments}}, info.Length())
344 {%- endif %}
345 {%- endmacro %}
346 320
347 321
348 {##############################################################################} 322 {##############################################################################}
349 {% macro runtime_determined_length_method(overloads) %} 323 {% macro runtime_determined_length_method(overloads) %}
350 static int {{overloads.name}}MethodLength() 324 static int {{overloads.name}}MethodLength()
351 { 325 {
352 {% for length, runtime_enabled_functions in overloads.runtime_determined_len gths %} 326 {% for length, runtime_enabled_functions in overloads.runtime_determined_len gths %}
353 {% for runtime_enabled_function in runtime_enabled_functions %} 327 {% for runtime_enabled_function in runtime_enabled_functions %}
354 {% filter runtime_enabled(runtime_enabled_function) %} 328 {% filter runtime_enabled(runtime_enabled_function) %}
355 return {{length}}; 329 return {{length}};
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 {% if is_partial or not overloads.has_partial_overloads %} 393 {% if is_partial or not overloads.has_partial_overloads %}
420 default: 394 default:
421 {# If methods are overloaded between interface and partial interface #} 395 {# If methods are overloaded between interface and partial interface #}
422 {# definitions, need to invoke methods defined in the partial #} 396 {# definitions, need to invoke methods defined in the partial #}
423 {# interface. #} 397 {# interface. #}
424 {# FIXME: we do not need to always generate this code. #} 398 {# FIXME: we do not need to always generate this code. #}
425 {# Invalid arity, throw error #} 399 {# Invalid arity, throw error #}
426 {# Report full list of valid arities if gaps and above minimum #} 400 {# Report full list of valid arities if gaps and above minimum #}
427 {% if overloads.valid_arities %} 401 {% if overloads.valid_arities %}
428 if (info.Length() >= {{overloads.length}}) { 402 if (info.Length() >= {{overloads.length}}) {
429 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length()); 403 throwInvalidArityError(exceptionState, "{{overloads.valid_arities}}" , info.Length());
430 {{propagate_error_with_exception_state(overloads) | indent(12)}} 404 return;
431 } 405 }
432 {% endif %} 406 {% endif %}
433 break; 407 break;
434 {% endif %} 408 {% endif %}
435 } 409 }
436 {% if not is_partial and overloads.has_partial_overloads %} 410 {% if not is_partial and overloads.has_partial_overloads %}
437 ASSERT({{overloads.name}}MethodForPartialInterface); 411 ASSERT({{overloads.name}}MethodForPartialInterface);
438 ({{overloads.name}}MethodForPartialInterface)(info); 412 ({{overloads.name}}MethodForPartialInterface)(info);
439 {% else %} 413 {% else %}
440 {% if overloads.length != 0 %} 414 {% if overloads.length != 0 %}
441 if (info.Length() < {{overloads.length}}) { 415 if (info.Length() < {{overloads.length}}) {
442 {# Otherwise just report "not enough arguments" #} 416 {# Otherwise just report "not enough arguments" #}
443 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.length}}, info.Length())); 417 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.length}}, info.Length()));
444 {{propagate_error_with_exception_state(overloads) | indent(8)}} 418 return;
445 } 419 }
446 {% endif %} 420 {% endif %}
447 {# No match, throw error #} 421 {# No match, throw error #}
448 exceptionState.throwTypeError("No function was found that matched the signat ure provided."); 422 exceptionState.throwTypeError("No function was found that matched the signat ure provided.");
449 {{propagate_error_with_exception_state(overloads) | indent}}
450 {% endif %} 423 {% endif %}
451 } 424 }
452 {% endmacro %} 425 {% endmacro %}
453 426
454 427
455 {##############################################################################} 428 {##############################################################################}
456 {% macro generate_post_message_impl() %} 429 {% macro generate_post_message_impl(method) %}
457 void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance, const v 8::FunctionCallbackInfo<v8::Value>& info) 430 void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance, const v 8::FunctionCallbackInfo<v8::Value>& info)
458 { 431 {
459 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", interfaceName, info.Holder(), info.GetIsolate()); 432 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", interfaceName, info.Holder(), info.GetIsolate());
460 if (UNLIKELY(info.Length() < 1)) { 433 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
461 setMinimumArityTypeError(exceptionState, 1, info.Length()); 434 {{throw_minimum_arity_error(method, method.number_of_required_arguments) }}
462 return; 435 return;
463 } 436 }
464 Transferables transferables; 437 Transferables transferables;
465 if (info.Length() > 1) { 438 if (info.Length() > 1) {
466 const int transferablesArgIndex = 1; 439 const int transferablesArgIndex = 1;
467 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) { 440 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) {
468 return; 441 return;
469 } 442 }
470 } 443 }
471 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); 444 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf o.GetIsolate(), info[0], &transferables, nullptr, exceptionState);
472 if (exceptionState.hadException()) 445 if (exceptionState.hadException())
473 return; 446 return;
474 // FIXME: Only pass context/exceptionState if instance really requires it. 447 // FIXME: Only pass context/exceptionState if instance really requires it.
475 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); 448 ExecutionContext* context = currentExecutionContext(info.GetIsolate());
476 instance->postMessage(context, message.release(), transferables.messagePorts , exceptionState); 449 instance->postMessage(context, message.release(), transferables.messagePorts , exceptionState);
477 } 450 }
478 {% endmacro %} 451 {% endmacro %}
479 452
453
480 {##############################################################################} 454 {##############################################################################}
481 {% macro method_callback(method, world_suffix) %} 455 {% macro method_callback(method, world_suffix) %}
482 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall backInfo<v8::Value>& info) 456 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall backInfo<v8::Value>& info)
483 { 457 {
484 {% if not method.overloads %}{# Overloaded methods are measured in overload_ resolution_method() #} 458 {% if not method.overloads %}{# Overloaded methods are measured in overload_ resolution_method() #}
485 {% if method.measure_as %} 459 {% if method.measure_as %}
486 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte xt(info.GetIsolate()), UseCounter::{{method.measure_as('Method')}}); 460 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte xt(info.GetIsolate()), UseCounter::{{method.measure_as('Method')}});
487 {% endif %} 461 {% endif %}
488 {% if method.deprecate_as %} 462 {% if method.deprecate_as %}
489 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx ecutionContext(info.GetIsolate()), UseCounter::{{method.deprecate_as}}); 463 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx ecutionContext(info.GetIsolate()), UseCounter::{{method.deprecate_as}});
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 v8SetReturnValue(info, info.Holder()); 583 v8SetReturnValue(info, info.Holder());
610 return; 584 return;
611 } 585 }
612 {% endif %} 586 {% endif %}
613 {% if constructor.has_exception_state %} 587 {% if constructor.has_exception_state %}
614 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate()); 588 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate());
615 {% endif %} 589 {% endif %}
616 {# Overloaded constructors have length checked during overload resolution #} 590 {# Overloaded constructors have length checked during overload resolution #}
617 {% if constructor.number_of_required_arguments and not constructor.overload_ index %} 591 {% if constructor.number_of_required_arguments and not constructor.overload_ index %}
618 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { 592 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) {
619 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ ired_arguments) | indent(8)}} 593 {{throw_minimum_arity_error(constructor, constructor.number_of_required_ arguments)}}
594 return;
620 } 595 }
621 {% endif %} 596 {% endif %}
597 {% if constructor.is_call_with_script_state or
598 constructor.is_call_with_this_value %}
599 ScriptState* scriptState = ScriptState::forReceiverObject(info);
600 {% endif %}
622 {% if constructor.arguments %} 601 {% if constructor.arguments %}
623 {{generate_arguments(constructor) | indent}} 602 {{generate_arguments(constructor) | indent}}
624 {% endif %} 603 {% endif %}
625 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor. cpp_value) | indent}} 604 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor. cpp_value) | indent}}
626 } 605 }
627 {% endmacro %} 606 {% endmacro %}
628 607
629 608
630 {##############################################################################} 609 {##############################################################################}
631 {% macro generate_constructor_wrapper(constructor) %} 610 {% macro generate_constructor_wrapper(constructor) %}
(...skipping 21 matching lines...) Expand all
653 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{only_exposed_to_private_script}}, {{pr operty_location(method)}}} 632 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{only_exposed_to_private_script}}, {{pr operty_location(method)}}}
654 {%- endmacro %} 633 {%- endmacro %}
655 634
656 635
657 {######################################} 636 {######################################}
658 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %} 637 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %}
659 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 638 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
660 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration); 639 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration);
661 {%- endmacro %} 640 {%- endmacro %}
662 641
642
663 {######################################} 643 {######################################}
664 {% macro install_conditionally_enabled_methods() %} 644 {% macro install_conditionally_enabled_methods() %}
665 {% if methods | conditionally_exposed(is_partial) %} 645 {% if methods | conditionally_exposed(is_partial) %}
666 {# Define operations with limited exposure #} 646 {# Define operations with limited exposure #}
667 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTempla te); 647 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTempla te);
668 ExecutionContext* executionContext = toExecutionContext(prototypeObject->Creatio nContext()); 648 ExecutionContext* executionContext = toExecutionContext(prototypeObject->Creatio nContext());
669 ASSERT(executionContext); 649 ASSERT(executionContext);
670 {% for method in methods | conditionally_exposed(is_partial) %} 650 {% for method in methods | conditionally_exposed(is_partial) %}
671 {% filter secure_context(method.overloads.secure_context_test_all 651 {% filter secure_context(method.overloads.secure_context_test_all
672 if method.overloads else 652 if method.overloads else
673 method.secure_context_test) %} 653 method.secure_context_test) %}
674 {% filter exposed(method.overloads.exposed_test_all 654 {% filter exposed(method.overloads.exposed_test_all
675 if method.overloads else 655 if method.overloads else
676 method.exposed_test) %} 656 method.exposed_test) %}
677 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all 657 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all
678 if method.overloads else 658 if method.overloads else
679 method.runtime_enabled_function) %} 659 method.runtime_enabled_function) %}
680 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 660 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
681 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); 661 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration);
682 {% endfilter %}{# runtime_enabled() #} 662 {% endfilter %}{# runtime_enabled() #}
683 {% endfilter %}{# exposed() #} 663 {% endfilter %}{# exposed() #}
684 {% endfilter %}{# secure_context() #} 664 {% endfilter %}{# secure_context() #}
685 {% endfor %} 665 {% endfor %}
686 {% endif %} 666 {% endif %}
687 {%- endmacro %} 667 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698