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

Side by Side Diff: Source/bindings/scripts/v8_methods.py

Issue 385603002: IDL: Support using nullable on any method return type (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add comment in is_nullable_simple() Created 6 years, 5 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
« no previous file with comments | « Source/bindings/scripts/v8_attributes.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 # generate_argument() macro in Source/bindings/templates/methods.cpp. 60 # generate_argument() macro in Source/bindings/templates/methods.cpp.
61 idl_type.is_callback_interface or 61 idl_type.is_callback_interface or
62 base_type == 'SerializedScriptValue' or 62 base_type == 'SerializedScriptValue' or
63 (argument.is_variadic and idl_type.is_wrapper_type) or 63 (argument.is_variadic and idl_type.is_wrapper_type) or
64 # String and enumeration arguments converted using one of the 64 # String and enumeration arguments converted using one of the
65 # TOSTRING_* macros in Source/bindings/core/v8/V8BindingMacros.h don't 65 # TOSTRING_* macros in Source/bindings/core/v8/V8BindingMacros.h don't
66 # use a v8::TryCatch. 66 # use a v8::TryCatch.
67 (base_type == 'DOMString' and not argument.is_variadic)) 67 (base_type == 'DOMString' and not argument.is_variadic))
68 68
69 69
70 def use_result_local(method):
haraken 2014/07/10 15:21:37 use_result_local => use_local_result
Jens Widell 2014/07/10 15:28:53 Done.
71 extended_attributes = method.extended_attributes
72 idl_type = method.idl_type
73 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
74 'ImplementedInPrivateScript' in extended_attributes or
75 'RaisesException' in extended_attributes or
76 idl_type.is_union_type or
77 (idl_type.is_nullable and not idl_type.is_nullable_simple))
78
79
70 def method_context(interface, method): 80 def method_context(interface, method):
71 arguments = method.arguments 81 arguments = method.arguments
72 extended_attributes = method.extended_attributes 82 extended_attributes = method.extended_attributes
73 idl_type = method.idl_type 83 idl_type = method.idl_type
74 is_static = method.is_static 84 is_static = method.is_static
75 name = method.name 85 name = method.name
76 86
77 idl_type.add_includes_for_type() 87 idl_type.add_includes_for_type()
78 this_cpp_value = cpp_value(interface, method, len(arguments)) 88 this_cpp_value = cpp_value(interface, method, len(arguments))
79 89
(...skipping 23 matching lines...) Expand all
103 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') 113 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
104 114
105 is_check_security_for_frame = ( 115 is_check_security_for_frame = (
106 'CheckSecurity' in interface.extended_attributes and 116 'CheckSecurity' in interface.extended_attributes and
107 'DoNotCheckSecurity' not in extended_attributes) 117 'DoNotCheckSecurity' not in extended_attributes)
108 is_raises_exception = 'RaisesException' in extended_attributes 118 is_raises_exception = 'RaisesException' in extended_attributes
109 119
110 arguments_need_try_catch = any(argument_needs_try_catch(argument) 120 arguments_need_try_catch = any(argument_needs_try_catch(argument)
111 for argument in arguments) 121 for argument in arguments)
112 122
123 is_nullable = idl_type.is_nullable and not idl_type.is_nullable_simple
124
113 return { 125 return {
114 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 126 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
115 'arguments': [argument_context(interface, method, argument, index) 127 'arguments': [argument_context(interface, method, argument, index)
116 for index, argument in enumerate(arguments)], 128 for index, argument in enumerate(arguments)],
117 'argument_declarations_for_private_script': 129 'argument_declarations_for_private_script':
118 argument_declarations_for_private_script(interface, method), 130 argument_declarations_for_private_script(interface, method),
119 'arguments_need_try_catch': arguments_need_try_catch, 131 'arguments_need_try_catch': arguments_need_try_catch,
120 'conditional_string': v8_utilities.conditional_string(method), 132 'conditional_string': v8_utilities.conditional_string(method),
121 'cpp_type': idl_type.cpp_type, 133 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type)
134 if is_nullable else idl_type.cpp_type),
122 'cpp_value': this_cpp_value, 135 'cpp_value': this_cpp_value,
123 'custom_registration_extended_attributes': 136 'custom_registration_extended_attributes':
124 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( 137 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection(
125 extended_attributes.iterkeys()), 138 extended_attributes.iterkeys()),
126 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 139 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
127 'function_template': function_template(), 140 'function_template': function_template(),
128 'has_custom_registration': is_static or 141 'has_custom_registration': is_static or
129 v8_utilities.has_extended_attribute( 142 v8_utilities.has_extended_attribute(
130 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), 143 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES),
131 'has_exception_state': 144 'has_exception_state':
132 is_raises_exception or 145 is_raises_exception or
133 is_check_security_for_frame or 146 is_check_security_for_frame or
134 interface.name == 'EventTarget' or # FIXME: merge with is_check_sec urity_for_frame http://crbug.com/383699 147 interface.name == 'EventTarget' or # FIXME: merge with is_check_sec urity_for_frame http://crbug.com/383699
135 any(argument for argument in arguments 148 any(argument for argument in arguments
136 if argument.idl_type.name == 'SerializedScriptValue' or 149 if argument.idl_type.name == 'SerializedScriptValue' or
137 argument.idl_type.may_raise_exception_on_conversion), 150 argument.idl_type.may_raise_exception_on_conversion),
138 'idl_type': idl_type.base_type, 151 'idl_type': idl_type.base_type,
139 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'), 152 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'),
140 'is_call_with_script_arguments': is_call_with_script_arguments, 153 'is_call_with_script_arguments': is_call_with_script_arguments,
141 'is_call_with_script_state': is_call_with_script_state, 154 'is_call_with_script_state': is_call_with_script_state,
142 'is_check_security_for_frame': is_check_security_for_frame, 155 'is_check_security_for_frame': is_check_security_for_frame,
143 'is_check_security_for_node': is_check_security_for_node, 156 'is_check_security_for_node': is_check_security_for_node,
144 'is_custom': 'Custom' in extended_attributes, 157 'is_custom': 'Custom' in extended_attributes,
145 'is_custom_element_callbacks': is_custom_element_callbacks, 158 'is_custom_element_callbacks': is_custom_element_callbacks,
146 'is_do_not_check_security': 'DoNotCheckSecurity' in extended_attributes, 159 'is_do_not_check_security': 'DoNotCheckSecurity' in extended_attributes,
147 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s, 160 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s,
148 'is_implemented_in_private_script': is_implemented_in_private_script, 161 'is_implemented_in_private_script': is_implemented_in_private_script,
162 'is_nullable': is_nullable,
149 'is_partial_interface_member': 163 'is_partial_interface_member':
150 'PartialInterfaceImplementedAs' in extended_attributes, 164 'PartialInterfaceImplementedAs' in extended_attributes,
151 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 165 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
152 'is_raises_exception': is_raises_exception, 166 'is_raises_exception': is_raises_exception,
153 'is_read_only': 'Unforgeable' in extended_attributes, 167 'is_read_only': 'Unforgeable' in extended_attributes,
154 'is_static': is_static, 168 'is_static': is_static,
169 'is_use_result_local': use_result_local(method),
haraken 2014/07/10 15:21:37 is_use_result_local => use_local_result
Jens Widell 2014/07/10 15:28:53 Done.
155 'is_variadic': arguments and arguments[-1].is_variadic, 170 'is_variadic': arguments and arguments[-1].is_variadic,
156 'measure_as': v8_utilities.measure_as(method), # [MeasureAs] 171 'measure_as': v8_utilities.measure_as(method), # [MeasureAs]
157 'name': name, 172 'name': name,
158 'number_of_arguments': len(arguments), 173 'number_of_arguments': len(arguments),
159 'number_of_required_arguments': len([ 174 'number_of_required_arguments': len([
160 argument for argument in arguments 175 argument for argument in arguments
161 if not (argument.is_optional or argument.is_variadic)]), 176 if not (argument.is_optional or argument.is_variadic)]),
162 'number_of_required_or_variadic_arguments': len([ 177 'number_of_required_or_variadic_arguments': len([
163 argument for argument in arguments 178 argument for argument in arguments
164 if not argument.is_optional]), 179 if not argument.is_optional]),
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 # Constructors and void methods don't have a return type 325 # Constructors and void methods don't have a return type
311 return None 326 return None
312 327
313 if ('ImplementedInPrivateScript' in extended_attributes and 328 if ('ImplementedInPrivateScript' in extended_attributes and
314 not idl_type.is_wrapper_type and 329 not idl_type.is_wrapper_type and
315 not idl_type.is_basic_type): 330 not idl_type.is_basic_type):
316 raise Exception('Private scripts supports only primitive types and DOM w rappers.') 331 raise Exception('Private scripts supports only primitive types and DOM w rappers.')
317 332
318 release = False 333 release = False
319 # [CallWith=ScriptState], [RaisesException] 334 # [CallWith=ScriptState], [RaisesException]
320 if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 335 if use_result_local(method):
321 'ImplementedInPrivateScript' in extended_attributes or 336 if idl_type.is_nullable and not idl_type.is_nullable_simple:
322 'RaisesException' in extended_attributes or 337 # result is of type Nullable<T>
323 idl_type.is_union_type): 338 cpp_value = 'result.get()'
324 cpp_value = 'result' # use local variable for value 339 else:
340 cpp_value = 'result'
325 release = idl_type.release 341 release = idl_type.release
326 342
327 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' 343 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
328 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) 344 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world)
329 345
330 346
331 def v8_value_to_local_cpp_variadic_value(argument, index): 347 def v8_value_to_local_cpp_variadic_value(argument, index):
332 assert argument.is_variadic 348 assert argument.is_variadic
333 idl_type = argument.idl_type 349 idl_type = argument.idl_type
334 350
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 392
377 393
378 def argument_default_cpp_value(argument): 394 def argument_default_cpp_value(argument):
379 if not argument.default_value: 395 if not argument.default_value:
380 return None 396 return None
381 return argument.idl_type.literal_cpp_value(argument.default_value) 397 return argument.idl_type.literal_cpp_value(argument.default_value)
382 398
383 IdlType.union_arguments = property(lambda self: None) 399 IdlType.union_arguments = property(lambda self: None)
384 IdlUnionType.union_arguments = property(union_arguments) 400 IdlUnionType.union_arguments = property(union_arguments)
385 IdlArgument.default_cpp_value = property(argument_default_cpp_value) 401 IdlArgument.default_cpp_value = property(argument_default_cpp_value)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_attributes.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698