OLD | NEW |
---|---|
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 def use_local_result(method): | 55 def use_local_result(method): |
56 extended_attributes = method.extended_attributes | 56 extended_attributes = method.extended_attributes |
57 idl_type = method.idl_type | 57 idl_type = method.idl_type |
58 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or | 58 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or |
59 'ImplementedInPrivateScript' in extended_attributes or | 59 'ImplementedInPrivateScript' in extended_attributes or |
60 'RaisesException' in extended_attributes or | 60 'RaisesException' in extended_attributes or |
61 idl_type.is_union_type or | 61 idl_type.is_union_type or |
62 idl_type.is_explicit_nullable) | 62 idl_type.is_explicit_nullable) |
63 | 63 |
64 | 64 |
65 def use_output_parameter_for_result(idl_type): | |
66 return idl_type.is_dictionary or idl_type.is_union_type | |
67 | |
68 | |
65 def method_context(interface, method, is_visible=True): | 69 def method_context(interface, method, is_visible=True): |
66 arguments = method.arguments | 70 arguments = method.arguments |
67 extended_attributes = method.extended_attributes | 71 extended_attributes = method.extended_attributes |
68 idl_type = method.idl_type | 72 idl_type = method.idl_type |
69 is_static = method.is_static | 73 is_static = method.is_static |
70 name = method.name | 74 name = method.name |
71 | 75 |
72 idl_type.add_includes_for_type() | 76 idl_type.add_includes_for_type() |
73 this_cpp_value = cpp_value(interface, method, len(arguments)) | 77 this_cpp_value = cpp_value(interface, method, len(arguments)) |
74 | 78 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 argument for argument in arguments | 175 argument for argument in arguments |
172 if not argument.is_optional]), | 176 if not argument.is_optional]), |
173 'only_exposed_to_private_script': is_only_exposed_to_private_script, | 177 'only_exposed_to_private_script': is_only_exposed_to_private_script, |
174 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled] | 178 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled] |
175 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value( | 179 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value( |
176 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True), | 180 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True), |
177 'property_attributes': property_attributes(method), | 181 'property_attributes': property_attributes(method), |
178 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled] | 182 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled] |
179 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), | 183 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), |
180 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature', | 184 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature', |
181 'union_arguments': idl_type.union_arguments, | 185 'use_output_parameter_for_result': use_output_parameter_for_result(idl_t ype), |
182 'use_output_parameter_for_result': idl_type.is_dictionary, | |
183 'use_local_result': use_local_result(method), | 186 'use_local_result': use_local_result(method), |
184 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), | 187 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), |
185 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), | 188 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), |
186 'visible': is_visible, | 189 'visible': is_visible, |
187 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings], | 190 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings], |
188 } | 191 } |
189 | 192 |
190 | 193 |
191 def argument_context(interface, method, argument, index): | 194 def argument_context(interface, method, argument, index): |
192 extended_attributes = argument.extended_attributes | 195 extended_attributes = argument.extended_attributes |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 | 292 |
290 # Members of IDL partial interface definitions are implemented in C++ as | 293 # Members of IDL partial interface definitions are implemented in C++ as |
291 # static member functions, which for instance members (non-static members) | 294 # static member functions, which for instance members (non-static members) |
292 # take *impl as their first argument | 295 # take *impl as their first argument |
293 if ('PartialInterfaceImplementedAs' in method.extended_attributes and | 296 if ('PartialInterfaceImplementedAs' in method.extended_attributes and |
294 not 'ImplementedInPrivateScript' in method.extended_attributes and | 297 not 'ImplementedInPrivateScript' in method.extended_attributes and |
295 not method.is_static): | 298 not method.is_static): |
296 cpp_arguments.append('*impl') | 299 cpp_arguments.append('*impl') |
297 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) | 300 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) |
298 | 301 |
299 this_union_arguments = method.idl_type and method.idl_type.union_arguments | |
300 if this_union_arguments: | |
301 cpp_arguments.extend([member_argument['cpp_value'] | |
302 for member_argument in this_union_arguments]) | |
303 | |
304 if 'ImplementedInPrivateScript' in method.extended_attributes: | 302 if 'ImplementedInPrivateScript' in method.extended_attributes: |
305 if method.idl_type.name != 'void': | 303 if method.idl_type.name != 'void': |
306 cpp_arguments.append('&result') | 304 cpp_arguments.append('&result') |
307 elif ('RaisesException' in method.extended_attributes or | 305 elif ('RaisesException' in method.extended_attributes or |
308 (method.is_constructor and | 306 (method.is_constructor and |
309 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))): | 307 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))): |
310 cpp_arguments.append('exceptionState') | 308 cpp_arguments.append('exceptionState') |
311 | 309 |
312 # If a method returns an IDL dictionary, the return value is passed | 310 # If a method returns an IDL dictionary or union type, the return value is |
313 # as an argument to impl classes. | 311 # passed as an argument to impl classes. |
314 if method.idl_type and method.idl_type.is_dictionary: | 312 idl_type = method.idl_type |
313 if idl_type and (idl_type.is_dictionary or idl_type.is_union_type): | |
haraken
2014/10/29 04:59:30
Can we use use_output_parameter_for_result(idl_typ
bashi
2014/10/29 09:57:36
Done.
| |
315 cpp_arguments.append('result') | 314 cpp_arguments.append('result') |
316 | 315 |
317 if method.name == 'Constructor': | 316 if method.name == 'Constructor': |
318 base_name = 'create' | 317 base_name = 'create' |
319 elif method.name == 'NamedConstructor': | 318 elif method.name == 'NamedConstructor': |
320 base_name = 'createForJSConstructor' | 319 base_name = 'createForJSConstructor' |
321 elif 'ImplementedInPrivateScript' in method.extended_attributes: | 320 elif 'ImplementedInPrivateScript' in method.extended_attributes: |
322 base_name = '%sMethod' % method.name | 321 base_name = '%sMethod' % method.name |
323 else: | 322 else: |
324 base_name = v8_utilities.cpp_name(method) | 323 base_name = v8_utilities.cpp_name(method) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 property_attributes_list = [] | 394 property_attributes_list = [] |
396 if 'NotEnumerable' in extended_attributes: | 395 if 'NotEnumerable' in extended_attributes: |
397 property_attributes_list.append('v8::DontEnum') | 396 property_attributes_list.append('v8::DontEnum') |
398 if 'Unforgeable' in extended_attributes: | 397 if 'Unforgeable' in extended_attributes: |
399 property_attributes_list.append('v8::ReadOnly') | 398 property_attributes_list.append('v8::ReadOnly') |
400 if property_attributes_list: | 399 if property_attributes_list: |
401 property_attributes_list.insert(0, 'v8::DontDelete') | 400 property_attributes_list.insert(0, 'v8::DontDelete') |
402 return property_attributes_list | 401 return property_attributes_list |
403 | 402 |
404 | 403 |
405 def union_member_argument_context(idl_type, index): | |
406 """Returns a context of union member for argument.""" | |
407 this_cpp_value = 'result%d' % index | |
408 this_cpp_type = idl_type.cpp_type | |
409 this_cpp_type_initializer = idl_type.cpp_type_initializer | |
410 cpp_return_value = this_cpp_value | |
411 | |
412 if not idl_type.cpp_type_has_null_value: | |
413 this_cpp_type = v8_types.cpp_template_type('Nullable', this_cpp_type) | |
414 this_cpp_type_initializer = '' | |
415 cpp_return_value = '%s.get()' % this_cpp_value | |
416 | |
417 if idl_type.is_string_type: | |
418 null_check_value = '!%s.isNull()' % this_cpp_value | |
419 else: | |
420 null_check_value = this_cpp_value | |
421 | |
422 return { | |
423 'cpp_type': this_cpp_type, | |
424 'cpp_type_initializer': this_cpp_type_initializer, | |
425 'cpp_value': this_cpp_value, | |
426 'null_check_value': null_check_value, | |
427 'v8_set_return_value': idl_type.v8_set_return_value( | |
428 cpp_value=cpp_return_value, | |
429 release=idl_type.release), | |
430 } | |
431 | |
432 | |
433 def union_arguments(idl_type): | |
434 return [union_member_argument_context(member_idl_type, index) | |
435 for index, member_idl_type | |
436 in enumerate(idl_type.member_types)] | |
437 | |
438 | |
439 def argument_default_cpp_value(argument): | 404 def argument_default_cpp_value(argument): |
440 if argument.idl_type.is_dictionary: | 405 if argument.idl_type.is_dictionary: |
441 return None | 406 return None |
442 if not argument.default_value: | 407 if not argument.default_value: |
443 return None | 408 return None |
444 return argument.idl_type.literal_cpp_value(argument.default_value) | 409 return argument.idl_type.literal_cpp_value(argument.default_value) |
445 | 410 |
446 IdlTypeBase.union_arguments = None | |
447 IdlUnionType.union_arguments = property(union_arguments) | |
448 IdlArgument.default_cpp_value = property(argument_default_cpp_value) | 411 IdlArgument.default_cpp_value = property(argument_default_cpp_value) |
449 | 412 |
450 | 413 |
451 def method_returns_promise(method): | 414 def method_returns_promise(method): |
452 return method.idl_type and method.idl_type.name == 'Promise' | 415 return method.idl_type and method.idl_type.name == 'Promise' |
453 | 416 |
454 IdlOperation.returns_promise = property(method_returns_promise) | 417 IdlOperation.returns_promise = property(method_returns_promise) |
455 | 418 |
456 | 419 |
457 def argument_conversion_needs_exception_state(method, argument): | 420 def argument_conversion_needs_exception_state(method, argument): |
458 idl_type = argument.idl_type | 421 idl_type = argument.idl_type |
459 return (idl_type.v8_conversion_needs_exception_state or | 422 return (idl_type.v8_conversion_needs_exception_state or |
460 argument.is_variadic or | 423 argument.is_variadic or |
461 (method.returns_promise and (idl_type.is_string_type or | 424 (method.returns_promise and (idl_type.is_string_type or |
462 idl_type.is_enum))) | 425 idl_type.is_enum))) |
OLD | NEW |