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 {% if method.number_of_required_arguments %} | 10 {% if method.number_of_required_arguments %} |
11 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 11 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
12 {{throw_arity_type_error(method, method.number_of_required_arguments)}}; | 12 {{throw_arity_type_error(method, method.number_of_required_arguments)}}; |
13 return; | 13 return; |
14 } | 14 } |
15 {% endif %} | 15 {% endif %} |
16 {% if not method.is_static %} | 16 {% if not method.is_static %} |
17 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 17 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); |
18 {% endif %} | 18 {% endif %} |
19 {% if method.is_custom_element_callbacks %} | 19 {% if method.is_custom_element_callbacks %} |
20 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 20 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
21 {% endif %} | 21 {% endif %} |
22 {# Security checks #} | 22 {# Security checks #} |
23 {# FIXME: change to method.is_check_security_for_window #} | 23 {# FIXME: change to method.is_check_security_for_window #} |
24 {% if interface_name == 'EventTarget' %} | 24 {% if interface_name == 'EventTarget' %} |
25 if (DOMWindow* window = impl->toDOMWindow()) { | 25 if (DOMWindow* window = impl->toDOMWindow()) { |
26 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window ->frame(), exceptionState)) { | 26 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window ->frame(), exceptionState)) { |
27 exceptionState.throwIfNeeded(); | 27 {{throw_from_exception_state(method) | indent}} |
Nils Barth (inactive)
2014/04/10 07:48:03
No indent here (it's a 1-line macro, right), and '
yhirano
2014/04/11 10:19:04
Done.
| |
28 return; | 28 return; |
29 } | 29 } |
30 if (!window->document()) | 30 if (!window->document()) |
31 return; | 31 return; |
32 } | 32 } |
33 {% elif method.is_check_security_for_frame %} | 33 {% elif method.is_check_security_for_frame %} |
34 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram e(), exceptionState)) { | 34 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram e(), exceptionState)) { |
35 exceptionState.throwIfNeeded(); | 35 {{throw_from_exception_state(method) | indent}} |
Nils Barth (inactive)
2014/04/10 07:48:03
no indent, ; at call
yhirano
2014/04/11 10:19:04
Done.
| |
36 return; | 36 return; |
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 {{throw_from_exception_state(method) | indent}} |
Nils Barth (inactive)
2014/04/10 07:48:03
no indent, ; at call
yhirano
2014/04/11 10:19:04
Done.
| |
43 return; | 43 return; |
44 } | 44 } |
45 {% endif %} | 45 {% endif %} |
46 {# Call method #} | 46 {# Call method #} |
47 {% for argument in method.arguments %} | 47 {% for argument in method.arguments %} |
48 {{generate_argument(method, argument, world_suffix) | indent}} | 48 {{generate_argument(method, argument, world_suffix) | indent}} |
49 {% endfor %} | 49 {% endfor %} |
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 %} |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 '"The callback provided as parameter %s is not a function."' % | 127 '"The callback provided as parameter %s is not a function."' % |
128 (argument.index + 1)) | indent }} | 128 (argument.index + 1)) | indent }} |
129 return; | 129 return; |
130 } | 130 } |
131 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())); | 131 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())); |
132 {% endif %}{# argument.is_optional #} | 132 {% endif %}{# argument.is_optional #} |
133 {% endif %}{# argument.idl_type == 'EventListener' #} | 133 {% endif %}{# argument.idl_type == 'EventListener' #} |
134 {% elif argument.is_clamp %}{# argument.is_callback_interface #} | 134 {% elif argument.is_clamp %}{# argument.is_callback_interface #} |
135 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} | 135 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
136 {{argument.cpp_type}} {{argument.name}} = 0; | 136 {{argument.cpp_type}} {{argument.name}} = 0; |
137 {% if method.idl_type == 'Promise' %} | |
138 V8TRYCATCH_VOID_PROMISE(double, {{argument.name}}NativeValue, info[{{argument.in dex}}]->NumberValue(), info); | |
139 {% else %} | |
137 V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]-> NumberValue()); | 140 V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]-> NumberValue()); |
141 {% endif %} | |
138 if (!std::isnan({{argument.name}}NativeValue)) | 142 if (!std::isnan({{argument.name}}NativeValue)) |
139 {# IDL type is used for clamping, for the right bounds, since different | 143 {# IDL type is used for clamping, for the right bounds, since different |
140 IDL integer types have same internal C++ type (int or unsigned) #} | 144 IDL integer types have same internal C++ type (int or unsigned) #} |
141 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa lue); | 145 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa lue); |
142 {% elif argument.idl_type == 'SerializedScriptValue' %} | 146 {% elif argument.idl_type == 'SerializedScriptValue' %} |
143 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{a rgument.index}}], 0, 0, exceptionState, info.GetIsolate()); | 147 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{a rgument.index}}], 0, 0, exceptionState, info.GetIsolate()); |
144 if (exceptionState.throwIfNeeded()) | 148 if (exceptionState.hadException()) { |
149 {{throw_from_exception_state(method) | indent}} | |
145 return; | 150 return; |
151 } | |
146 {% elif argument.is_variadic_wrapper_type %} | 152 {% elif argument.is_variadic_wrapper_type %} |
147 {{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}}; | 153 {{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}}; |
148 for (int i = {{argument.index}}; i < info.Length(); ++i) { | 154 for (int i = {{argument.index}}; i < info.Length(); ++i) { |
149 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { | 155 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { |
150 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 156 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
151 (argument.index + 1, argument.idl_type)) | in dent(8)}} | 157 (argument.index + 1, argument.idl_type)) | in dent(8)}} |
152 return; | 158 return; |
153 } | 159 } |
154 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob ject>::Cast(info[i]))); | 160 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob ject>::Cast(info[i]))); |
155 } | 161 } |
156 {% else %} | 162 {% else %} |
163 {% if method.idl_type == 'Promise' %} | |
164 {{argument.v8_value_to_local_cpp_value_async}}; | |
165 {% else %} | |
157 {{argument.v8_value_to_local_cpp_value}}; | 166 {{argument.v8_value_to_local_cpp_value}}; |
158 {% endif %} | 167 {% endif %} |
168 {% endif %} | |
159 {% if argument.enum_validation_expression %} | 169 {% if argument.enum_validation_expression %} |
160 {# Methods throw on invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} | 170 {# Methods throw on invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} |
161 String string = {{argument.name}}; | 171 String string = {{argument.name}}; |
162 if (!({{argument.enum_validation_expression}})) { | 172 if (!({{argument.enum_validation_expression}})) { |
163 {{throw_type_error(method, | 173 {{throw_type_error(method, |
164 '"parameter %s (\'" + string + "\') is not a valid enum value."' % | 174 '"parameter %s (\'" + string + "\') is not a valid enum value."' % |
165 (argument.index + 1)) | indent}} | 175 (argument.index + 1)) | indent}} |
166 return; | 176 return; |
167 } | 177 } |
168 {% endif %} | 178 {% endif %} |
(...skipping 30 matching lines...) Expand all Loading... | |
199 {% endif %} | 209 {% endif %} |
200 {# Call #} | 210 {# Call #} |
201 {% if method.idl_type == 'void' %} | 211 {% if method.idl_type == 'void' %} |
202 {{cpp_value}}; | 212 {{cpp_value}}; |
203 {% elif method.is_call_with_script_state or method.is_call_with_new_script_state or method.is_raises_exception %} | 213 {% elif method.is_call_with_script_state or method.is_call_with_new_script_state or method.is_raises_exception %} |
204 {# FIXME: consider always using a local variable #} | 214 {# FIXME: consider always using a local variable #} |
205 {{method.cpp_type}} result = {{cpp_value}}; | 215 {{method.cpp_type}} result = {{cpp_value}}; |
206 {% endif %} | 216 {% endif %} |
207 {# Post-call #} | 217 {# Post-call #} |
208 {% if method.is_raises_exception %} | 218 {% if method.is_raises_exception %} |
209 if (exceptionState.throwIfNeeded()) | 219 if (exceptionState.hadException()) { |
220 {{throw_from_exception_state(method) | indent}} | |
210 return; | 221 return; |
222 } | |
211 {% endif %} | 223 {% endif %} |
212 {# Set return value #} | 224 {# Set return value #} |
213 {% if method.union_arguments %} | 225 {% if method.union_arguments %} |
214 {{union_type_method_call_and_set_return_value(method)}} | 226 {{union_type_method_call_and_set_return_value(method)}} |
215 {% elif v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for voi d #} | 227 {% elif v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for voi d #} |
216 {% endmacro %} | 228 {% endmacro %} |
217 | 229 |
218 | 230 |
219 {######################################} | 231 {######################################} |
220 {% macro union_type_method_call_and_set_return_value(method) %} | 232 {% macro union_type_method_call_and_set_return_value(method) %} |
(...skipping 14 matching lines...) Expand all Loading... | |
235 {% endfor %} | 247 {% endfor %} |
236 {# Fall back to null if none of the union members results are returned #} | 248 {# Fall back to null if none of the union members results are returned #} |
237 v8SetReturnValueNull(info); | 249 v8SetReturnValueNull(info); |
238 {%- endmacro %} | 250 {%- endmacro %} |
239 | 251 |
240 | 252 |
241 {######################################} | 253 {######################################} |
242 {% macro throw_type_error(method, error_message) %} | 254 {% macro throw_type_error(method, error_message) %} |
243 {% if method.has_exception_state %} | 255 {% if method.has_exception_state %} |
244 exceptionState.throwTypeError({{error_message}}); | 256 exceptionState.throwTypeError({{error_message}}); |
245 exceptionState.throwIfNeeded(); | 257 {{throw_from_exception_state(method)}} |
246 {%- elif method.is_constructor %} | 258 {%- elif method.is_constructor %} |
259 {% if method.idl_type == 'Promise' %} | |
260 v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ExceptionMessages::fai ledToConstruct("{{interface_name}}", {{error_message}}), info.GetIsolate()).v8Va lue()); | |
261 {%- else %} | |
247 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro r_message}}), info.GetIsolate()); | 262 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro r_message}}), info.GetIsolate()); |
263 {%- endif %}{# if method.idl_type == 'Promise' #} | |
264 {%- else %} | |
265 {% if method.idl_type == 'Promise' %} | |
266 v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ExceptionMessages::fai ledToExecute("{{method.name}}", "{{interface_name}}", {{error_message}}), info.G etIsolate()).v8Value()); | |
248 {%- else %} | 267 {%- else %} |
249 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac e_name}}", {{error_message}}), info.GetIsolate()); | 268 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac e_name}}", {{error_message}}), info.GetIsolate()); |
269 {%- endif %}{# if method.idl_type == 'Promise' #} | |
250 {%- endif %} | 270 {%- endif %} |
251 {% endmacro %} | 271 {% endmacro %} |
252 | 272 |
Nils Barth (inactive)
2014/04/10 07:48:03
2 lines between macros
yhirano
2014/04/11 10:19:04
Done.
| |
273 {######################################} | |
274 {% macro throw_from_exception_state(method) %} | |
275 {% if method.idl_type == 'Promise' %} | |
276 v8SetReturnValue(info, exceptionState.rejectedPromise().v8Value()); | |
277 {%- else %} | |
278 exceptionState.throwIfNeeded(); | |
279 {%- endif %} | |
280 {% endmacro %} | |
253 | 281 |
Nils Barth (inactive)
2014/04/10 07:48:03
2 lines between macros
yhirano
2014/04/11 10:19:04
Done.
| |
254 {######################################} | 282 {######################################} |
255 {% macro throw_arity_type_error(method, number_of_required_arguments) %} | 283 {% macro throw_arity_type_error(method, number_of_required_arguments) %} |
284 {% if method.idl_type == 'Promise' %} | |
285 {% if method.has_exception_state %} | |
286 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeError(exceptionState, { {number_of_required_arguments}}, info.Length()).v8Value()) | |
287 {%- elif method.is_constructor %} | |
288 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForConstructor("{{ interface_name}}", {{number_of_required_arguments}}, info.Length(), info.GetIsol ate().v8Value()) | |
289 {%- else %} | |
290 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForMethod("{{metho d.name}}", "{{interface_name}}", {{number_of_required_arguments}}, info.Length() , info.GetIsolate()).v8Value()) | |
291 {%- endif %} | |
292 {%- else %} | |
256 {% if method.has_exception_state %} | 293 {% if method.has_exception_state %} |
257 throwArityTypeError(exceptionState, {{number_of_required_arguments}}, info.Lengt h()) | 294 throwArityTypeError(exceptionState, {{number_of_required_arguments}}, info.Lengt h()) |
258 {%- elif method.is_constructor %} | 295 {%- elif method.is_constructor %} |
259 throwArityTypeErrorForConstructor("{{interface_name}}", {{number_of_required_arg uments}}, info.Length(), info.GetIsolate()) | 296 throwArityTypeErrorForConstructor("{{interface_name}}", {{number_of_required_arg uments}}, info.Length(), info.GetIsolate()) |
260 {%- else %} | 297 {%- else %} |
261 throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{number_o f_required_arguments}}, info.Length(), info.GetIsolate()) | 298 throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{number_o f_required_arguments}}, info.Length(), info.GetIsolate()) |
262 {%- endif %} | 299 {%- endif %} |
300 {%- endif %} | |
263 {% endmacro %} | 301 {% endmacro %} |
264 | 302 |
265 | 303 |
266 {##############################################################################} | 304 {##############################################################################} |
267 {% macro overload_resolution_method(overloads, world_suffix) %} | 305 {% macro overload_resolution_method(overloads, world_suffix) %} |
268 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) | 306 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) |
269 { | 307 { |
270 {% for method in overloads.methods %} | 308 {% for method in overloads.methods %} |
271 if ({{method.overload_resolution_expression}}) { | 309 if ({{method.overload_resolution_expression}}) { |
272 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); | 310 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 | 483 |
446 {% if has_custom_wrap %} | 484 {% if has_custom_wrap %} |
447 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIso late()); | 485 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIso late()); |
448 {% else %} | 486 {% else %} |
449 v8::Handle<v8::Object> wrapper = info.Holder(); | 487 v8::Handle<v8::Object> wrapper = info.Holder(); |
450 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8 _class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_conf iguration}}); | 488 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8 _class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_conf iguration}}); |
451 {% endif %} | 489 {% endif %} |
452 v8SetReturnValue(info, wrapper); | 490 v8SetReturnValue(info, wrapper); |
453 } | 491 } |
454 {% endmacro %} | 492 {% endmacro %} |
OLD | NEW |