| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 # [SpecialWrapFor] | 87 # [SpecialWrapFor] |
| 88 if 'SpecialWrapFor' in extended_attributes: | 88 if 'SpecialWrapFor' in extended_attributes: |
| 89 special_wrap_for = extended_attributes['SpecialWrapFor'].split('|') | 89 special_wrap_for = extended_attributes['SpecialWrapFor'].split('|') |
| 90 else: | 90 else: |
| 91 special_wrap_for = [] | 91 special_wrap_for = [] |
| 92 for special_wrap_interface in special_wrap_for: | 92 for special_wrap_interface in special_wrap_for: |
| 93 v8_types.add_includes_for_type(special_wrap_interface) | 93 v8_types.add_includes_for_type(special_wrap_interface) |
| 94 | 94 |
| 95 # Constructors | 95 # Constructors |
| 96 # [Constructor] | 96 constructors = [generate_constructor(interface, constructor) |
| 97 has_constructor = 'Constructor' in extended_attributes | 97 for constructor in interface.constructors] |
| 98 if has_constructor: | 98 generate_constructor_overloads(constructors) |
| 99 if constructors: |
| 99 includes.add('bindings/v8/V8ObjectConstructor.h') | 100 includes.add('bindings/v8/V8ObjectConstructor.h') |
| 100 | 101 |
| 101 # [EventConstructor] | 102 # [EventConstructor] |
| 102 has_event_constructor = 'EventConstructor' in extended_attributes | 103 has_event_constructor = 'EventConstructor' in extended_attributes |
| 103 any_type_attributes = [attribute for attribute in interface.attributes | 104 any_type_attributes = [attribute for attribute in interface.attributes |
| 104 if attribute.idl_type == 'any'] | 105 if attribute.idl_type == 'any'] |
| 105 if has_event_constructor: | 106 if has_event_constructor: |
| 106 includes.update(['bindings/v8/Dictionary.h', | 107 includes.update(['bindings/v8/Dictionary.h', |
| 107 'bindings/v8/V8ObjectConstructor.h']) | 108 'bindings/v8/V8ObjectConstructor.h']) |
| 108 if any_type_attributes: | 109 if any_type_attributes: |
| 109 includes.add('bindings/v8/SerializedScriptValue.h') | 110 includes.add('bindings/v8/SerializedScriptValue.h') |
| 110 | 111 |
| 111 template_contents = { | 112 template_contents = { |
| 112 'any_type_attributes': any_type_attributes, | 113 'any_type_attributes': any_type_attributes, |
| 113 'conditional_string': conditional_string(interface), # [Conditional] | 114 'conditional_string': conditional_string(interface), # [Conditional] |
| 114 'constructor_argument_list': constructor_argument_list(interface), | 115 'constructors': constructors, |
| 115 'constructor_arguments': constructor_arguments(interface), | |
| 116 'constructor_method': { | |
| 117 'is_constructor': True, | |
| 118 }, | |
| 119 'cpp_class': cpp_name(interface), | 116 'cpp_class': cpp_name(interface), |
| 120 'generate_visit_dom_wrapper_function': generate_visit_dom_wrapper_functi
on, | 117 'generate_visit_dom_wrapper_function': generate_visit_dom_wrapper_functi
on, |
| 121 'has_constructor': has_constructor, | |
| 122 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter
face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] | 118 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter
face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] |
| 123 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T
oV8'), # [Custom=ToV8] | 119 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T
oV8'), # [Custom=ToV8] |
| 124 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr
ap'), # [Custom=Wrap] | 120 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr
ap'), # [Custom=Wrap] |
| 125 'has_event_constructor': has_event_constructor, | 121 'has_event_constructor': has_event_constructor, |
| 126 'has_visit_dom_wrapper': ( | 122 'has_visit_dom_wrapper': ( |
| 127 # [Custom=Wrap], [GenerateVisitDOMWrapper] | 123 # [Custom=Wrap], [GenerateVisitDOMWrapper] |
| 128 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper')
or | 124 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper')
or |
| 129 'GenerateVisitDOMWrapper' in extended_attributes), | 125 'GenerateVisitDOMWrapper' in extended_attributes), |
| 130 'header_includes': header_includes, | 126 'header_includes': header_includes, |
| 131 'interface_length': interface_length(interface), | 127 'interface_length': interface_length(interface, constructors), |
| 132 'interface_name': interface.name, | 128 'interface_name': interface.name, |
| 133 'is_active_dom_object': 'ActiveDOMObject' in extended_attributes, # [Ac
tiveDOMObject] | 129 'is_active_dom_object': 'ActiveDOMObject' in extended_attributes, # [Ac
tiveDOMObject] |
| 134 'is_check_security': is_check_security, | 130 'is_check_security': is_check_security, |
| 135 'is_constructor_call_with_document': has_extended_attribute_value( | 131 'is_constructor_call_with_document': has_extended_attribute_value( |
| 136 interface, 'ConstructorCallWith', 'Document'), # [ConstructorCallWi
th=Document] | 132 interface, 'ConstructorCallWith', 'Document'), # [ConstructorCallWi
th=Document] |
| 137 'is_constructor_call_with_execution_context': has_extended_attribute_val
ue( | 133 'is_constructor_call_with_execution_context': has_extended_attribute_val
ue( |
| 138 interface, 'ConstructorCallWith', 'ExecutionContext'), # [Construct
orCallWith=ExeuctionContext] | 134 interface, 'ConstructorCallWith', 'ExecutionContext'), # [Construct
orCallWith=ExeuctionContext] |
| 139 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept
ion') == 'Constructor', # [RaisesException=Constructor] | 135 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept
ion') == 'Constructor', # [RaisesException=Constructor] |
| 140 'is_dependent_lifetime': 'DependentLifetime' in extended_attributes, #
[DependentLifetime] | 136 'is_dependent_lifetime': 'DependentLifetime' in extended_attributes, #
[DependentLifetime] |
| 141 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] | 137 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 if v8_types.is_wrapper_type(idl_type): | 303 if v8_types.is_wrapper_type(idl_type): |
| 308 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate(),
worldType(info.GetIsolate()))'.format(idl_type=idl_type, cpp_value=cpp_value) | 304 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate(),
worldType(info.GetIsolate()))'.format(idl_type=idl_type, cpp_value=cpp_value) |
| 309 if argument['is_nullable']: | 305 if argument['is_nullable']: |
| 310 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) | 306 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) |
| 311 return type_check | 307 return type_check |
| 312 return None | 308 return None |
| 313 | 309 |
| 314 | 310 |
| 315 # Constructors | 311 # Constructors |
| 316 | 312 |
| 317 def constructor_argument_list(interface): | 313 # [Constructor] |
| 318 if not interface.constructors: | 314 def generate_constructor(interface, constructor): |
| 319 return [] | 315 return { |
| 320 constructor = interface.constructors[0] # FIXME: support overloading | 316 'argument_list': constructor_argument_list(interface, constructor), |
| 317 'arguments': [constructor_argument(argument, index) |
| 318 for index, argument in enumerate(constructor.arguments)], |
| 319 'is_constructor': True, |
| 320 'is_variadic': False, # Required for overload resolution |
| 321 'number_of_required_arguments': |
| 322 len([argument for argument in constructor.arguments |
| 323 if not argument.is_optional]), |
| 324 } |
| 321 | 325 |
| 326 |
| 327 def constructor_argument_list(interface, constructor): |
| 322 arguments = [] | 328 arguments = [] |
| 323 # [ConstructorCallWith=ExecutionContext] | 329 # [ConstructorCallWith=ExecutionContext] |
| 324 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution
Context'): | 330 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution
Context'): |
| 325 arguments.append('context') | 331 arguments.append('context') |
| 326 # [ConstructorCallWith=Document] | 332 # [ConstructorCallWith=Document] |
| 327 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document'
): | 333 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document'
): |
| 328 arguments.append('document') | 334 arguments.append('document') |
| 329 | 335 |
| 330 arguments.extend([argument.name for argument in constructor.arguments]) | 336 arguments.extend([argument.name for argument in constructor.arguments]) |
| 331 | 337 |
| 332 # [RaisesException=Constructor] | 338 # [RaisesException=Constructor] |
| 333 if interface.extended_attributes.get('RaisesException') == 'Constructor': | 339 if interface.extended_attributes.get('RaisesException') == 'Constructor': |
| 334 arguments.append('exceptionState') | 340 arguments.append('exceptionState') |
| 335 | 341 |
| 336 return arguments | 342 return arguments |
| 337 | 343 |
| 338 | 344 |
| 339 def constructor_arguments(interface): | |
| 340 if not interface.constructors: | |
| 341 return [] | |
| 342 constructor = interface.constructors[0] # FIXME: support overloading | |
| 343 return [constructor_argument(argument, index) | |
| 344 for index, argument in enumerate(constructor.arguments)] | |
| 345 | |
| 346 | |
| 347 def constructor_argument(argument, index): | 345 def constructor_argument(argument, index): |
| 348 return { | 346 return { |
| 347 'has_default': 'Default' in argument.extended_attributes, |
| 349 'idl_type': argument.idl_type, | 348 'idl_type': argument.idl_type, |
| 350 'index': index, | 349 'index': index, |
| 350 'is_nullable': False, # Required for overload resolution |
| 351 'is_optional': argument.is_optional, |
| 352 'is_strict_type_checking': False, # Required for overload resolution |
| 351 'name': argument.name, | 353 'name': argument.name, |
| 352 'v8_value_to_local_cpp_value': | 354 'v8_value_to_local_cpp_value': |
| 353 v8_methods.v8_value_to_local_cpp_value(argument, index), | 355 v8_methods.v8_value_to_local_cpp_value(argument, index), |
| 354 } | 356 } |
| 355 | 357 |
| 356 | 358 |
| 357 def interface_length(interface): | 359 def generate_constructor_overloads(constructors): |
| 360 if len(constructors) <= 1: |
| 361 return |
| 362 for overload_index, constructor in enumerate(constructors): |
| 363 constructor.update({ |
| 364 'overload_index': overload_index + 1, |
| 365 'overload_resolution_expression': |
| 366 overload_resolution_expression(constructor), |
| 367 }) |
| 368 |
| 369 |
| 370 def interface_length(interface, constructors): |
| 358 # Docs: http://heycam.github.io/webidl/#es-interface-call | 371 # Docs: http://heycam.github.io/webidl/#es-interface-call |
| 359 if 'EventConstructor' in interface.extended_attributes: | 372 if 'EventConstructor' in interface.extended_attributes: |
| 360 return 1 | 373 return 1 |
| 361 if not interface.constructors: | 374 if not constructors: |
| 362 return 0 | 375 return 0 |
| 363 constructor = interface.constructors[0] # FIXME: support overloading | 376 return min(constructor['number_of_required_arguments'] |
| 364 return len([argument | 377 for constructor in constructors) |
| 365 for argument in constructor.arguments | |
| 366 if not argument.is_optional]) | |
| OLD | NEW |