| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 'number_of_required_arguments': len([ | 121 'number_of_required_arguments': len([ |
| 122 argument for argument in arguments | 122 argument for argument in arguments |
| 123 if not (argument.is_optional or argument.is_variadic)]), | 123 if not (argument.is_optional or argument.is_variadic)]), |
| 124 'number_of_required_or_variadic_arguments': len([ | 124 'number_of_required_or_variadic_arguments': len([ |
| 125 argument for argument in arguments | 125 argument for argument in arguments |
| 126 if not argument.is_optional]), | 126 if not argument.is_optional]), |
| 127 'per_context_enabled_function': v8_utilities.per_context_enabled_functio
n_name(method), # [PerContextEnabled] | 127 'per_context_enabled_function': v8_utilities.per_context_enabled_functio
n_name(method), # [PerContextEnabled] |
| 128 'property_attributes': property_attributes(method), | 128 'property_attributes': property_attributes(method), |
| 129 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m
ethod), # [RuntimeEnabled] | 129 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m
ethod), # [RuntimeEnabled] |
| 130 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig
nature' in extended_attributes else 'defaultSignature', | 130 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig
nature' in extended_attributes else 'defaultSignature', |
| 131 'union_arguments': union_arguments(idl_type), |
| 131 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 132 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
| 132 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 133 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
| 133 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings] | 134 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings] |
| 134 } | 135 } |
| 135 | 136 |
| 136 | 137 |
| 137 def generate_argument(interface, method, argument, index): | 138 def generate_argument(interface, method, argument, index): |
| 138 extended_attributes = argument.extended_attributes | 139 extended_attributes = argument.extended_attributes |
| 139 idl_type = argument.idl_type | 140 idl_type = argument.idl_type |
| 140 this_cpp_value = cpp_value(interface, method, index) | 141 this_cpp_value = cpp_value(interface, method, index) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 152 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes, | 153 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes, |
| 153 'is_variadic_wrapper_type': argument.is_variadic and v8_types.is_wrapper
_type(idl_type), | 154 'is_variadic_wrapper_type': argument.is_variadic and v8_types.is_wrapper
_type(idl_type), |
| 154 'is_wrapper_type': v8_types.is_wrapper_type(idl_type), | 155 'is_wrapper_type': v8_types.is_wrapper_type(idl_type), |
| 155 'name': argument.name, | 156 'name': argument.name, |
| 156 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 157 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
| 157 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 158 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
| 158 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex), | 159 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex), |
| 159 } | 160 } |
| 160 | 161 |
| 161 | 162 |
| 163 ################################################################################ |
| 164 # Value handling |
| 165 ################################################################################ |
| 166 |
| 162 def cpp_value(interface, method, number_of_arguments): | 167 def cpp_value(interface, method, number_of_arguments): |
| 163 def cpp_argument(argument): | 168 def cpp_argument(argument): |
| 164 idl_type = argument.idl_type | 169 idl_type = argument.idl_type |
| 165 if (v8_types.is_callback_interface(idl_type) or | 170 if (v8_types.is_callback_interface(idl_type) or |
| 166 idl_type in ['NodeFilter', 'XPathNSResolver']): | 171 idl_type in ['NodeFilter', 'XPathNSResolver']): |
| 167 # FIXME: remove this special case | 172 # FIXME: remove this special case |
| 168 return '%s.release()' % argument.name | 173 return '%s.release()' % argument.name |
| 169 return argument.name | 174 return argument.name |
| 170 | 175 |
| 171 # Truncate omitted optional arguments | 176 # Truncate omitted optional arguments |
| 172 arguments = method.arguments[:number_of_arguments] | 177 arguments = method.arguments[:number_of_arguments] |
| 173 cpp_arguments = v8_utilities.call_with_arguments(method) | 178 cpp_arguments = v8_utilities.call_with_arguments(method) |
| 174 if ('ImplementedBy' in method.extended_attributes and | 179 if ('ImplementedBy' in method.extended_attributes and |
| 175 not method.is_static): | 180 not method.is_static): |
| 176 cpp_arguments.append('imp') | 181 cpp_arguments.append('imp') |
| 177 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) | 182 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) |
| 183 this_union_arguments = union_arguments(method.idl_type) |
| 184 if this_union_arguments: |
| 185 cpp_arguments.extend(this_union_arguments) |
| 186 |
| 178 if 'RaisesException' in method.extended_attributes: | 187 if 'RaisesException' in method.extended_attributes: |
| 179 cpp_arguments.append('exceptionState') | 188 cpp_arguments.append('exceptionState') |
| 180 | 189 |
| 181 cpp_method_name = v8_utilities.scoped_name(interface, method, v8_utilities.c
pp_name(method)) | 190 cpp_method_name = v8_utilities.scoped_name(interface, method, v8_utilities.c
pp_name(method)) |
| 182 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) | 191 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) |
| 183 | 192 |
| 184 | 193 |
| 185 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False)
: | 194 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False)
: |
| 186 idl_type = method.idl_type | 195 idl_type = method.idl_type |
| 187 extended_attributes = method.extended_attributes | 196 extended_attributes = method.extended_attributes |
| 188 if idl_type == 'void': | 197 if idl_type == 'void': |
| 189 return None | 198 return None |
| 199 is_union_type = v8_types.is_union_type(idl_type) |
| 190 | 200 |
| 191 release = False | 201 release = False |
| 192 # [CallWith=ScriptState], [RaisesException] | 202 # [CallWith=ScriptState], [RaisesException] |
| 193 if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or | 203 if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or |
| 194 'RaisesException' in extended_attributes): | 204 'RaisesException' in extended_attributes or |
| 205 is_union_type): |
| 195 # use local variable for value | 206 # use local variable for value |
| 196 cpp_value = 'result' | 207 cpp_value = 'result' |
| 197 if v8_types.is_interface_type(idl_type): | 208 |
| 198 release = True | 209 if is_union_type: |
| 210 release = [v8_types.is_interface_type(union_member_type) |
| 211 for union_member_type in idl_type.union_member_types] |
| 212 else: |
| 213 release = v8_types.is_interface_type(idl_type) |
| 199 | 214 |
| 200 script_wrappable = 'imp' if v8_types.inherits_interface(interface_name, 'Nod
e') else '' | 215 script_wrappable = 'imp' if v8_types.inherits_interface(interface_name, 'Nod
e') else '' |
| 201 return v8_types.v8_set_return_value(idl_type, cpp_value, extended_attributes
, script_wrappable=script_wrappable, release=release, for_main_world=for_main_wo
rld) | 216 return v8_types.v8_set_return_value(idl_type, cpp_value, extended_attributes
, script_wrappable=script_wrappable, release=release, for_main_world=for_main_wo
rld) |
| 202 | 217 |
| 203 | 218 |
| 204 # [NotEnumerable] | |
| 205 def property_attributes(method): | |
| 206 extended_attributes = method.extended_attributes | |
| 207 property_attributes_list = [] | |
| 208 if 'NotEnumerable' in extended_attributes: | |
| 209 property_attributes_list.append('v8::DontEnum') | |
| 210 if 'ReadOnly' in extended_attributes: | |
| 211 property_attributes_list.append('v8::ReadOnly') | |
| 212 if property_attributes_list: | |
| 213 property_attributes_list.insert(0, 'v8::DontDelete') | |
| 214 return property_attributes_list | |
| 215 | |
| 216 | |
| 217 def v8_value_to_local_cpp_value(argument, index): | 219 def v8_value_to_local_cpp_value(argument, index): |
| 218 extended_attributes = argument.extended_attributes | 220 extended_attributes = argument.extended_attributes |
| 219 idl_type = argument.idl_type | 221 idl_type = argument.idl_type |
| 220 name = argument.name | 222 name = argument.name |
| 221 if argument.is_variadic: | 223 if argument.is_variadic: |
| 222 return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{c
pp_type}>(info, {index}))'.format( | 224 return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{c
pp_type}>(info, {index}))'.format( |
| 223 cpp_type=v8_types.cpp_type(idl_type), name=name, index=index) | 225 cpp_type=v8_types.cpp_type(idl_type), name=name, index=index) |
| 224 # [Default=NullString] | 226 # [Default=NullString] |
| 225 if (argument.is_optional and idl_type == 'DOMString' and | 227 if (argument.is_optional and idl_type == 'DOMString' and |
| 226 extended_attributes.get('Default') == 'NullString'): | 228 extended_attributes.get('Default') == 'NullString'): |
| 227 v8_value = 'argumentOrNull(info, %s)' % index | 229 v8_value = 'argumentOrNull(info, %s)' % index |
| 228 else: | 230 else: |
| 229 v8_value = 'info[%s]' % index | 231 v8_value = 'info[%s]' % index |
| 230 return v8_types.v8_value_to_local_cpp_value( | 232 return v8_types.v8_value_to_local_cpp_value( |
| 231 idl_type, argument.extended_attributes, v8_value, name, index=index) | 233 idl_type, argument.extended_attributes, v8_value, name, index=index) |
| 234 |
| 235 |
| 236 ################################################################################ |
| 237 # Auxiliary functions |
| 238 ################################################################################ |
| 239 |
| 240 # [NotEnumerable] |
| 241 def property_attributes(method): |
| 242 extended_attributes = method.extended_attributes |
| 243 property_attributes_list = [] |
| 244 if 'NotEnumerable' in extended_attributes: |
| 245 property_attributes_list.append('v8::DontEnum') |
| 246 if 'ReadOnly' in extended_attributes: |
| 247 property_attributes_list.append('v8::ReadOnly') |
| 248 if property_attributes_list: |
| 249 property_attributes_list.insert(0, 'v8::DontDelete') |
| 250 return property_attributes_list |
| 251 |
| 252 |
| 253 def union_arguments(idl_type): |
| 254 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u
nion types, for use in setting return value""" |
| 255 if not v8_types.is_union_type(idl_type): |
| 256 return None |
| 257 return [arg |
| 258 for i in range(len(idl_type.union_member_types)) |
| 259 for arg in ['result%sEnabled' % i, 'result%s' % i]] |
| OLD | NEW |