OLD | NEW |
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 {# Overloaded methods have length checked during overload resolution #} | 10 {# Overloaded methods have length checked during overload resolution #} |
11 {% if method.number_of_required_arguments and not method.overload_index %} | 11 {% if method.number_of_required_arguments and not method.overload_index %} |
12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
13 {{throw_minimum_arity_type_error(method, method.number_of_required_argum
ents)}}; | 13 {{throw_minimum_arity_type_error(method, method.number_of_required_argum
ents)}}; |
14 return; | 14 return; |
15 } | 15 } |
16 {% endif %} | 16 {% endif %} |
17 {% if not method.is_static %} | 17 {% if not method.is_static %} |
18 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 18 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); |
19 {% endif %} | 19 {% endif %} |
20 {% if method.is_custom_element_callbacks %} | 20 {% if method.is_custom_element_callbacks %} |
21 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 21 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
22 {% endif %} | 22 {% endif %} |
23 {# Security checks #} | 23 {# Security checks #} |
24 {# FIXME: change to method.is_check_security_for_window #} | 24 {# FIXME: change to method.is_check_security_for_window #} |
25 {% if interface_name == 'EventTarget' %} | 25 {% if interface_name == 'EventTarget' %} |
26 if (DOMWindow* window = impl->toDOMWindow()) { | 26 if (DOMWindow* window = impl->toDOMWindow()) { |
27 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window
->frame(), exceptionState)) { | 27 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window
->frame(), exceptionState)) { |
28 {{throw_from_exception_state(method) | indent(12)}} | 28 {{throw_from_exception_state(method)}}; |
29 return; | 29 return; |
30 } | 30 } |
31 if (!window->document()) | 31 if (!window->document()) |
32 return; | 32 return; |
33 } | 33 } |
34 {% elif method.is_check_security_for_frame %} | 34 {% elif method.is_check_security_for_frame %} |
35 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) { | 35 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) { |
36 {{throw_from_exception_state(method) | indent(8)}} | 36 {{throw_from_exception_state(method)}}; |
37 return; | 37 return; |
38 } | 38 } |
39 {% endif %} | 39 {% endif %} |
40 {% if method.is_check_security_for_node %} | 40 {% if method.is_check_security_for_node %} |
41 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met
hod.name}}(exceptionState), exceptionState)) { | 41 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met
hod.name}}(exceptionState), exceptionState)) { |
42 v8SetReturnValueNull(info); | 42 v8SetReturnValueNull(info); |
43 {{throw_from_exception_state(method) | indent(8)}} | 43 {{throw_from_exception_state(method)}}; |
44 return; | 44 return; |
45 } | 45 } |
46 {% endif %} | 46 {% endif %} |
47 {# Call method #} | 47 {# Call method #} |
48 {% if method.arguments %} | 48 {% if method.arguments %} |
49 {{generate_arguments(method, world_suffix) | indent}} | 49 {{generate_arguments(method, world_suffix) | indent}} |
50 {% endif %} | 50 {% endif %} |
51 {% if world_suffix %} | 51 {% if world_suffix %} |
52 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} | 52 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} |
53 {% else %} | 53 {% else %} |
(...skipping 20 matching lines...) Expand all Loading... |
74 | 74 |
75 | 75 |
76 {######################################} | 76 {######################################} |
77 {% macro generate_arguments(method, world_suffix) %} | 77 {% macro generate_arguments(method, world_suffix) %} |
78 {% for argument in method.arguments %} | 78 {% for argument in method.arguments %} |
79 {{generate_argument_var_declaration(argument)}}; | 79 {{generate_argument_var_declaration(argument)}}; |
80 {% endfor %} | 80 {% endfor %} |
81 { | 81 { |
82 {% if method.arguments_need_try_catch %} | 82 {% if method.arguments_need_try_catch %} |
83 v8::TryCatch block; | 83 v8::TryCatch block; |
| 84 V8RethrowTryCatchScope rethrow(block); |
84 {% endif %} | 85 {% endif %} |
85 {% for argument in method.arguments %} | 86 {% for argument in method.arguments %} |
86 {{generate_argument(method, argument, world_suffix) | indent}} | 87 {{generate_argument(method, argument, world_suffix) | indent}} |
87 {% endfor %} | 88 {% endfor %} |
88 } | 89 } |
89 {% endmacro %} | 90 {% endmacro %} |
90 | 91 |
91 | 92 |
92 {######################################} | 93 {######################################} |
93 {% macro generate_argument_var_declaration(argument) %} | 94 {% macro generate_argument_var_declaration(argument) %} |
(...skipping 16 matching lines...) Expand all Loading... |
110 {######################################} | 111 {######################################} |
111 {% macro generate_argument(method, argument, world_suffix) %} | 112 {% macro generate_argument(method, argument, world_suffix) %} |
112 {% if argument.is_optional and not argument.has_default and | 113 {% if argument.is_optional and not argument.has_default and |
113 argument.idl_type != 'Dictionary' and | 114 argument.idl_type != 'Dictionary' and |
114 not argument.is_callback_interface %} | 115 not argument.is_callback_interface %} |
115 {# Optional arguments without a default value generate an early call with | 116 {# Optional arguments without a default value generate an early call with |
116 fewer arguments if they are omitted. | 117 fewer arguments if they are omitted. |
117 Optional Dictionary arguments default to empty dictionary. #} | 118 Optional Dictionary arguments default to empty dictionary. #} |
118 if (UNLIKELY(info.Length() <= {{argument.index}})) { | 119 if (UNLIKELY(info.Length() <= {{argument.index}})) { |
119 {% if world_suffix %} | 120 {% if world_suffix %} |
120 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum
ent.cpp_value, method.arguments_need_try_catch) | indent}} | 121 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum
ent.cpp_value) | indent}} |
121 {% else %} | 122 {% else %} |
122 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value,
method.arguments_need_try_catch) | indent}} | 123 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} |
123 {% endif %} | 124 {% endif %} |
124 {% if argument.has_event_listener_argument %} | 125 {% if argument.has_event_listener_argument %} |
125 {{hidden_dependency_action(method.name) | indent}} | 126 {{hidden_dependency_action(method.name) | indent}} |
126 {% endif %} | 127 {% endif %} |
127 return; | 128 return; |
128 } | 129 } |
129 {% endif %} | 130 {% endif %} |
130 {% if argument.has_type_checking_interface %} | 131 {% if argument.has_type_checking_interface %} |
131 {# Type checking for wrapper interface types (if interface not implemented, | 132 {# Type checking for wrapper interface types (if interface not implemented, |
132 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 #} |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 {# 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 #} |
172 double {{argument.name}}NativeValue; | 173 double {{argument.name}}NativeValue; |
173 TONATIVE_VOID_INTERNAL({{argument.name}}NativeValue, info[{{argument.index}}]->N
umberValue()); | 174 TONATIVE_VOID_INTERNAL({{argument.name}}NativeValue, info[{{argument.index}}]->N
umberValue()); |
174 if (!std::isnan({{argument.name}}NativeValue)) | 175 if (!std::isnan({{argument.name}}NativeValue)) |
175 {# 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 |
176 IDL integer types have same internal C++ type (int or unsigned) #} | 177 IDL integer types have same internal C++ type (int or unsigned) #} |
177 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa
lue); | 178 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa
lue); |
178 {% elif argument.idl_type == 'SerializedScriptValue' %} | 179 {% elif argument.idl_type == 'SerializedScriptValue' %} |
179 {{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0
, exceptionState, info.GetIsolate()); | 180 {{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0
, exceptionState, info.GetIsolate()); |
180 if (exceptionState.hadException()) { | 181 if (exceptionState.hadException()) { |
181 {{throw_from_exception_state(method) | indent}} | 182 {{throw_from_exception_state(method)}}; |
182 return; | 183 return; |
183 } | 184 } |
184 {% elif argument.is_variadic_wrapper_type %} | 185 {% elif argument.is_variadic_wrapper_type %} |
185 for (int i = {{argument.index}}; i < info.Length(); ++i) { | 186 for (int i = {{argument.index}}; i < info.Length(); ++i) { |
186 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { | 187 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { |
187 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 188 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
188 (argument.index + 1, argument.idl_type)) | in
dent(8)}} | 189 (argument.index + 1, argument.idl_type)) | in
dent(8)}} |
189 return; | 190 return; |
190 } | 191 } |
191 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob
ject>::Cast(info[i]))); | 192 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob
ject>::Cast(info[i]))); |
(...skipping 29 matching lines...) Expand all Loading... |
221 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { | 222 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { |
222 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % | 223 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % |
223 (argument.index + 1, argument.name)) | indent}} | 224 (argument.index + 1, argument.name)) | indent}} |
224 return; | 225 return; |
225 } | 226 } |
226 {% endif %} | 227 {% endif %} |
227 {% endmacro %} | 228 {% endmacro %} |
228 | 229 |
229 | 230 |
230 {######################################} | 231 {######################################} |
231 {% macro cpp_method_call(method, v8_set_return_value, cpp_value, has_try_catch)
%} | 232 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} |
232 {# Local variables #} | 233 {# Local variables #} |
233 {% if method.is_call_with_script_state %} | 234 {% if method.is_call_with_script_state %} |
234 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); | 235 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); |
235 {% endif %} | 236 {% endif %} |
236 {% if method.is_call_with_execution_context %} | 237 {% if method.is_call_with_execution_context %} |
237 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()); | 238 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()); |
238 {% endif %} | 239 {% endif %} |
239 {% if method.is_call_with_script_arguments %} | 240 {% if method.is_call_with_script_arguments %} |
240 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num
ber_of_arguments}})); | 241 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num
ber_of_arguments}})); |
241 {% endif %} | 242 {% endif %} |
242 {# Call #} | 243 {# Call #} |
243 {% if method.idl_type == 'void' %} | 244 {% if method.idl_type == 'void' %} |
244 {{cpp_value}}; | 245 {{cpp_value}}; |
245 {% elif method.is_constructor %} | 246 {% elif method.is_constructor %} |
246 {{method.cpp_type}} impl = {{cpp_value}}; | 247 {{method.cpp_type}} impl = {{cpp_value}}; |
247 {% elif method.is_call_with_script_state or method.is_raises_exception %} | 248 {% elif method.is_call_with_script_state or method.is_raises_exception %} |
248 {# FIXME: consider always using a local variable #} | 249 {# FIXME: consider always using a local variable #} |
249 {{method.cpp_type}} result = {{cpp_value}}; | 250 {{method.cpp_type}} result = {{cpp_value}}; |
250 {% endif %} | 251 {% endif %} |
251 {# Post-call #} | 252 {# Post-call #} |
252 {% if method.is_raises_exception %} | 253 {% if method.is_raises_exception %} |
253 if (exceptionState.hadException()) { | 254 if (exceptionState.hadException()) { |
254 {{throw_from_exception_state(method, has_try_catch) | indent}} | 255 {{throw_from_exception_state(method)}}; |
255 return; | 256 return; |
256 } | 257 } |
257 {% endif %} | 258 {% endif %} |
258 {# Set return value #} | 259 {# Set return value #} |
259 {% if method.is_constructor %} | 260 {% if method.is_constructor %} |
260 {{generate_constructor_wrapper(method)}}{% elif method.union_arguments %} | 261 {{generate_constructor_wrapper(method)}}{% elif method.union_arguments %} |
261 {{union_type_method_call_and_set_return_value(method)}} | 262 {{union_type_method_call_and_set_return_value(method)}} |
262 {% elif v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for voi
d #} | 263 {% elif v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for voi
d #} |
263 {% endmacro %} | 264 {% endmacro %} |
264 | 265 |
(...skipping 17 matching lines...) Expand all Loading... |
282 {% endfor %} | 283 {% endfor %} |
283 {# Fall back to null if none of the union members results are returned #} | 284 {# Fall back to null if none of the union members results are returned #} |
284 v8SetReturnValueNull(info); | 285 v8SetReturnValueNull(info); |
285 {%- endmacro %} | 286 {%- endmacro %} |
286 | 287 |
287 | 288 |
288 {######################################} | 289 {######################################} |
289 {% macro throw_type_error(method, error_message) %} | 290 {% macro throw_type_error(method, error_message) %} |
290 {% if method.has_exception_state %} | 291 {% if method.has_exception_state %} |
291 exceptionState.throwTypeError({{error_message}}); | 292 exceptionState.throwTypeError({{error_message}}); |
292 {{throw_from_exception_state(method, method.arguments_need_try_catch)}} | 293 {{throw_from_exception_state(method)}}; |
293 {%- else %}{# method.has_exception_state #} | 294 {% elif method.is_constructor %} |
294 {% if method.is_constructor %} | |
295 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro
r_message}}), info.GetIsolate()); | 295 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro
r_message}}), info.GetIsolate()); |
296 {% else %}{# method.has_exception_state #} | 296 {% else %}{# method.has_exception_state #} |
297 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac
e_name}}", {{error_message}}), info.GetIsolate()); | 297 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac
e_name}}", {{error_message}}), info.GetIsolate()); |
298 {% endif %} | |
299 {% if method.arguments_need_try_catch %} | |
300 block.ReThrow(); | |
301 {% endif %} | |
302 {% endif %}{# method.has_exception_state #} | 298 {% endif %}{# method.has_exception_state #} |
303 {% endmacro %} | 299 {% endmacro %} |
304 | 300 |
305 | 301 |
306 {######################################} | 302 {######################################} |
307 {# FIXME: return a rejected Promise if method.idl_type == 'Promise' #} | 303 {# FIXME: return a rejected Promise if method.idl_type == 'Promise' #} |
308 {% macro throw_from_exception_state(method, has_try_catch) %} | 304 {% macro throw_from_exception_state(method) %} |
309 exceptionState.throwIfNeeded(); | 305 exceptionState.throwIfNeeded() |
310 {% if has_try_catch %} | |
311 block.ReThrow(); | |
312 {%- endif %} | |
313 {%- endmacro %} | 306 {%- endmacro %} |
314 | 307 |
315 | 308 |
316 {######################################} | 309 {######################################} |
317 {% macro throw_arity_type_error(method, valid_arities) %} | 310 {% macro throw_arity_type_error(method, valid_arities) %} |
318 {% if method.has_exception_state %} | 311 {% if method.has_exception_state %} |
319 throwArityTypeError(exceptionState, {{valid_arities}}, info.Length()) | 312 throwArityTypeError(exceptionState, {{valid_arities}}, info.Length()) |
320 {%- elif method.is_constructor %} | 313 {%- elif method.is_constructor %} |
321 throwArityTypeErrorForConstructor("{{interface_name}}", {{valid_arities}}, info.
Length(), info.GetIsolate()) | 314 throwArityTypeErrorForConstructor("{{interface_name}}", {{valid_arities}}, info.
Length(), info.GetIsolate()) |
322 {%- else %} | 315 {%- else %} |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 {% endif %} | 553 {% endif %} |
561 {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{cons
tructor.argument_list | join(', ')}}); | 554 {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{cons
tructor.argument_list | join(', ')}}); |
562 {% if is_constructor_raises_exception %} | 555 {% if is_constructor_raises_exception %} |
563 if (exceptionState.throwIfNeeded()) | 556 if (exceptionState.throwIfNeeded()) |
564 return; | 557 return; |
565 {% endif %} | 558 {% endif %} |
566 | 559 |
567 {{generate_constructor_wrapper(constructor) | indent}} | 560 {{generate_constructor_wrapper(constructor) | indent}} |
568 } | 561 } |
569 {% endmacro %} | 562 {% endmacro %} |
OLD | NEW |