Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 FIXME: Not currently used in build. | 31 FIXME: Not currently used in build. |
| 32 This is a rewrite of the Perl IDL compiler in Python, but is not complete. | 32 This is a rewrite of the Perl IDL compiler in Python, but is not complete. |
| 33 Once it is complete, we will switch all IDL files over to Python at once. | 33 Once it is complete, we will switch all IDL files over to Python at once. |
| 34 Until then, please work on the Perl IDL compiler. | 34 Until then, please work on the Perl IDL compiler. |
| 35 For details, see bug http://crbug.com/239771 | 35 For details, see bug http://crbug.com/239771 |
| 36 """ | 36 """ |
| 37 | 37 |
| 38 import v8_types | 38 import v8_types |
| 39 import v8_utilities | 39 import v8_utilities |
| 40 from v8_utilities import capitalize, cpp_name, has_extended_attribute, uncapital ize | 40 from v8_utilities import capitalize, cpp_name, has_extended_attribute, strip_suf fix, uncapitalize |
| 41 | 41 |
| 42 | 42 |
| 43 def generate_attributes(interface): | 43 def generate_attributes(interface): |
| 44 def generate_attribute(attribute): | 44 def generate_attribute(attribute): |
| 45 attribute_contents, attribute_includes = generate_attribute_and_includes (interface, attribute) | 45 attribute_contents, attribute_includes = generate_attribute_and_includes (interface, attribute) |
| 46 includes.update(attribute_includes) | 46 includes.update(attribute_includes) |
| 47 return attribute_contents | 47 return attribute_contents |
| 48 | 48 |
| 49 includes = set() | 49 includes = set() |
| 50 attributes = [generate_attribute(attribute) for attribute in interface.attri butes] | 50 attributes = [generate_attribute(attribute) for attribute in interface.attri butes] |
| 51 contents = {'attributes': attributes} | 51 contents = {'attributes': attributes} |
| 52 contents.update(generate_attributes_common(interface, attributes)) | 52 contents.update(generate_attributes_common(interface, attributes)) |
| 53 return contents, includes | 53 return contents, includes |
| 54 | 54 |
| 55 | 55 |
| 56 def generate_attributes_common(interface, attributes): | 56 def generate_attributes_common(interface, attributes): |
| 57 v8_class_name = v8_utilities.v8_class_name(interface) | 57 v8_class_name = v8_utilities.v8_class_name(interface) |
| 58 return { | 58 return { |
| 59 'has_per_context_enabled_attributes': any(attribute['per_context_enabled _function_name'] for attribute in attributes), | 59 'has_per_context_enabled_attributes': any(attribute['per_context_enabled _function_name'] for attribute in attributes), |
| 60 'has_constructor_getter': any(attribute['is_constructor'] for attribute in attributes), | |
| 60 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes), | 61 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes), |
| 61 'has_runtime_enabled_attributes': any(attribute['runtime_enabled_functio n_name'] for attribute in attributes), | 62 'has_runtime_enabled_attributes': any(attribute['runtime_enabled_functio n_name'] for attribute in attributes), |
| 62 'installed_attributes': '%sAttributes' % v8_class_name if attributes els e '0', | 63 'installed_attributes': '%sAttributes' % v8_class_name if attributes els e '0', |
| 63 # Size 0 constant array is not allowed in VC++ | 64 # Size 0 constant array is not allowed in VC++ |
| 64 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name if attributes else '0', | 65 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name if attributes else '0', |
| 65 } | 66 } |
| 66 | 67 |
| 67 | 68 |
| 68 def generate_attribute_and_includes(interface, attribute): | 69 def generate_attribute_and_includes(interface, attribute): |
| 69 idl_type = attribute.data_type | 70 idl_type = attribute.data_type |
| 70 extended_attributes = attribute.extended_attributes | 71 extended_attributes = attribute.extended_attributes |
| 71 | 72 |
| 72 has_custom_getter = has_extended_attribute(attribute, ('Custom', 'CustomGett er')) | 73 has_custom_getter = has_extended_attribute(attribute, ('Custom', 'CustomGett er')) |
| 73 is_replaceable = 'Replaceable' in attribute.extended_attributes | 74 is_replaceable = 'Replaceable' in attribute.extended_attributes |
| 74 has_custom_setter = ( | 75 has_custom_setter = ( |
| 75 (not attribute.is_read_only or is_replaceable) and | 76 (not attribute.is_read_only or is_replaceable) and |
| 76 has_extended_attribute(attribute, ('Custom', 'CustomSetter'))) | 77 has_extended_attribute(attribute, ('Custom', 'CustomSetter'))) |
| 77 includes = set() | 78 includes = set() |
| 78 contents = { | 79 contents = { |
| 79 'access_control_list': access_control_list(attribute), | 80 'access_control_list': access_control_list(attribute), |
| 80 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_ world_list(attribute, includes, 'Getter'), # [ActivityLogging] | 81 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_ world_list(attribute, includes, 'Getter'), # [ActivityLogging] |
| 81 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_ world_list(attribute, includes, 'Setter'), # [ActivityLogging] | 82 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_ world_list(attribute, includes, 'Setter'), # [ActivityLogging] |
| 82 'cached_attribute_validation_method': extended_attributes.get('CachedAtt ribute'), | 83 'cached_attribute_validation_method': extended_attributes.get('CachedAtt ribute'), |
| 83 'conditional_string': v8_utilities.generate_conditional_string(attribute ), | 84 'conditional_string': v8_utilities.generate_conditional_string(attribute ), |
| 84 'cpp_type': v8_types.cpp_type(idl_type), | 85 'cpp_type': v8_types.cpp_type(idl_type), |
| 86 'data': installation_data(attribute), | |
| 85 'getter_callback_name': getter_callback_name(interface, attribute), | 87 'getter_callback_name': getter_callback_name(interface, attribute), |
| 86 'getter_callback_name_for_main_world': getter_callback_name_for_main_wor ld(interface, attribute), | 88 'getter_callback_name_for_main_world': getter_callback_name_for_main_wor ld(interface, attribute), |
| 87 'has_custom_getter': has_custom_getter, | 89 'has_custom_getter': has_custom_getter, |
| 88 'has_custom_setter': has_custom_setter, | 90 'has_custom_setter': has_custom_setter, |
| 89 'idl_type': idl_type, | 91 'idl_type': idl_type, |
| 92 'is_constructor': is_constructor(attribute), | |
| 90 'is_getter_raises_exception': has_extended_attribute(attribute, ('Getter RaisesException', 'RaisesException')), | 93 'is_getter_raises_exception': has_extended_attribute(attribute, ('Getter RaisesException', 'RaisesException')), |
| 91 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), | 94 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), |
| 92 'is_nullable': attribute.is_nullable, | 95 'is_nullable': attribute.is_nullable, |
| 93 'is_read_only': attribute.is_read_only, | 96 'is_read_only': attribute.is_read_only, |
| 94 'is_replaceable': is_replaceable, | 97 'is_replaceable': is_replaceable, |
| 95 'is_setter_raises_exception': has_extended_attribute(attribute, ('Raises Exception', 'SetterRaisesException')), | 98 'is_setter_raises_exception': has_extended_attribute(attribute, ('Raises Exception', 'SetterRaisesException')), |
| 96 'is_static': attribute.is_static, | 99 'is_static': attribute.is_static, |
| 97 'name': attribute.name, | 100 'name': attribute.name, |
| 98 'per_context_enabled_function_name': v8_utilities.per_context_enabled_fu nction_name(attribute), # [PerContextEnabled] | 101 'per_context_enabled_function_name': v8_utilities.per_context_enabled_fu nction_name(attribute), # [PerContextEnabled] |
| 99 'property_attributes': property_attributes(attribute), | 102 'property_attributes': property_attributes(attribute), |
| 100 'setter_callback_name': setter_callback_name(interface, attribute), | 103 'setter_callback_name': setter_callback_name(interface, attribute), |
| 101 'setter_callback_name_for_main_world': setter_callback_name_for_main_wor ld(interface, attribute), | 104 'setter_callback_name_for_main_world': setter_callback_name_for_main_wor ld(interface, attribute), |
| 102 'v8_type': v8_types.v8_type(idl_type), | 105 'v8_type': v8_types.v8_type(idl_type), |
| 103 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_n ame(attribute), # [RuntimeEnabled] | 106 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_n ame(attribute), # [RuntimeEnabled] |
| 104 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings] | 107 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings] |
| 105 } | 108 } |
| 109 if is_constructor(attribute): | |
| 110 includes.update(v8_types.includes_for_type(idl_type)) | |
| 111 return contents, includes | |
| 106 if not has_custom_getter: | 112 if not has_custom_getter: |
| 107 generate_getter(interface, attribute, contents, includes) | 113 generate_getter(interface, attribute, contents, includes) |
| 108 if not (attribute.is_read_only or has_custom_setter): | 114 if not (attribute.is_read_only or has_custom_setter): |
| 109 generate_setter(interface, attribute, contents, includes) | 115 generate_setter(interface, attribute, contents, includes) |
| 110 | 116 |
| 111 return contents, includes | 117 return contents, includes |
| 112 | 118 |
| 113 | 119 |
| 120 # Getter | |
| 121 | |
| 114 def generate_getter(interface, attribute, contents, includes): | 122 def generate_getter(interface, attribute, contents, includes): |
| 115 idl_type = attribute.data_type | 123 idl_type = attribute.data_type |
| 116 includes.update(v8_types.includes_for_type(idl_type)) | 124 includes.update(v8_types.includes_for_type(idl_type)) |
| 117 extended_attributes = attribute.extended_attributes | 125 extended_attributes = attribute.extended_attributes |
| 118 | 126 |
| 119 cpp_value = getter_expression(interface, attribute, contents, includes) | 127 cpp_value = getter_expression(interface, attribute, contents, includes) |
| 120 # Normally we can inline the function call into the return statement to | 128 # Normally we can inline the function call into the return statement to |
| 121 # avoid the overhead of using a Ref<> temporary, but for some cases | 129 # avoid the overhead of using a Ref<> temporary, but for some cases |
| 122 # (nullable types, EventHandler, [CachedAttribute], or if there are | 130 # (nullable types, EventHandler, [CachedAttribute], or if there are |
| 123 # exceptions), we need to use a local variable. | 131 # exceptions), we need to use a local variable. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 not( | 226 not( |
| 219 # Node lifetime is managed by object grouping. | 227 # Node lifetime is managed by object grouping. |
| 220 v8_types.is_dom_node_type(idl_type) or | 228 v8_types.is_dom_node_type(idl_type) or |
| 221 # A self-reference is unnecessary. | 229 # A self-reference is unnecessary. |
| 222 attribute.name == 'self' or | 230 attribute.name == 'self' or |
| 223 # FIXME: Remove these hard-coded hacks. | 231 # FIXME: Remove these hard-coded hacks. |
| 224 idl_type in ['EventHandler', 'Promise', 'Window'] or | 232 idl_type in ['EventHandler', 'Promise', 'Window'] or |
| 225 idl_type.startswith('HTML')))) | 233 idl_type.startswith('HTML')))) |
| 226 | 234 |
| 227 | 235 |
| 236 # Setter | |
| 237 | |
| 228 def generate_setter(interface, attribute, contents, includes): | 238 def generate_setter(interface, attribute, contents, includes): |
| 229 idl_type = attribute.data_type | 239 idl_type = attribute.data_type |
| 230 extended_attributes = attribute.extended_attributes | 240 extended_attributes = attribute.extended_attributes |
| 231 if v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type ): | 241 if v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type ): |
| 232 cpp_value = 'WTF::getPtr(cppValue)' | 242 cpp_value = 'WTF::getPtr(cppValue)' |
| 233 else: | 243 else: |
| 234 cpp_value = 'cppValue' | 244 cpp_value = 'cppValue' |
| 235 is_reflect = 'Reflect' in extended_attributes | 245 is_reflect = 'Reflect' in extended_attributes |
| 236 if is_reflect: | 246 if is_reflect: |
| 237 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') | 247 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 includes.add('%s.h' % namespace) | 311 includes.add('%s.h' % namespace) |
| 302 return '%s::%sAttr' % (namespace, content_attribute_name) | 312 return '%s::%sAttr' % (namespace, content_attribute_name) |
| 303 | 313 |
| 304 | 314 |
| 305 def scoped_name(interface, attribute, base_name): | 315 def scoped_name(interface, attribute, base_name): |
| 306 if attribute.is_static: | 316 if attribute.is_static: |
| 307 return '%s::%s' % (interface.name, base_name) | 317 return '%s::%s' % (interface.name, base_name) |
| 308 return 'imp->%s' % base_name | 318 return 'imp->%s' % base_name |
| 309 | 319 |
| 310 | 320 |
| 321 # Attribute configuration | |
|
Nils Barth (inactive)
2013/10/23 11:31:34
(Reordered in order of the configuration line.)
| |
| 322 | |
| 311 def getter_callback_name(interface, attribute): | 323 def getter_callback_name(interface, attribute): |
| 324 if attribute.data_type.endswith('Constructor'): | |
| 325 return '{0}V8Internal::{0}ConstructorGetter'.format(cpp_name(interface)) | |
| 312 return '%sV8Internal::%sAttributeGetterCallback' % (cpp_name(interface), att ribute.name) | 326 return '%sV8Internal::%sAttributeGetterCallback' % (cpp_name(interface), att ribute.name) |
| 313 | 327 |
| 314 | 328 |
| 329 # [Replaceable] | |
| 315 def setter_callback_name(interface, attribute): | 330 def setter_callback_name(interface, attribute): |
| 316 if (attribute.is_read_only and | 331 if (attribute.is_read_only and |
| 317 'Replaceable' not in attribute.extended_attributes): | 332 'Replaceable' not in attribute.extended_attributes): |
| 318 # FIXME: support [PutForwards] | 333 # FIXME: support [PutForwards] |
| 319 return '0' | 334 return '0' |
| 320 cpp_class_name = cpp_name(interface) | 335 cpp_class_name = cpp_name(interface) |
| 321 if ('Replaceable' in attribute.extended_attributes and | 336 if (('Replaceable' in attribute.extended_attributes and |
| 322 not has_extended_attribute(attribute, ('Custom', 'CustomSetter'))): | 337 not has_extended_attribute(attribute, ('Custom', 'CustomSetter'))) or |
| 338 attribute.data_type.endswith('Constructor')): | |
| 323 # Non-custom replaceable attributes have a single interface-level | 339 # Non-custom replaceable attributes have a single interface-level |
| 324 # setter callback (rather than individual attribute-level callbacks), | 340 # setter callback (rather than individual attribute-level callbacks), |
| 325 # but custom replaceable attributes have individual callbacks, as usual. | 341 # but custom replaceable attributes have individual callbacks, as usual. |
| 326 return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp _class_name) | 342 return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp _class_name) |
| 327 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut e.name) | 343 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut e.name) |
| 328 | 344 |
| 329 | 345 |
| 346 # [PerWorldBindings] | |
| 347 def getter_callback_name_for_main_world(interface, attribute): | |
| 348 if 'PerWorldBindings' not in attribute.extended_attributes: | |
| 349 return '0' | |
| 350 return '%sV8Internal::%sAttributeGetterCallbackForMainWorld' % (cpp_name(int erface), attribute.name) | |
| 351 | |
| 352 | |
| 353 def setter_callback_name_for_main_world(interface, attribute): | |
| 354 if ('PerWorldBindings' not in attribute.extended_attributes or | |
| 355 attribute.is_read_only): | |
| 356 return '0' | |
| 357 return '%sV8Internal::%sAttributeSetterCallbackForMainWorld' % (cpp_name(int erface), attribute.name) | |
| 358 | |
| 359 | |
| 360 def installation_data(attribute): | |
| 361 if not is_constructor(attribute): | |
| 362 return '0' | |
| 363 return '&V8%s::info' % v8_types.constructor_type(attribute.data_type) | |
| 364 | |
| 365 | |
| 330 # [DoNotCheckSecurity], [DoNotCheckSecurityOnGetter], [DoNotCheckSecurityOnSette r], [Unforgeable] | 366 # [DoNotCheckSecurity], [DoNotCheckSecurityOnGetter], [DoNotCheckSecurityOnSette r], [Unforgeable] |
| 331 def access_control_list(attribute): | 367 def access_control_list(attribute): |
| 332 extended_attributes = attribute.extended_attributes | 368 extended_attributes = attribute.extended_attributes |
| 333 access_control = [] | 369 access_control = [] |
| 334 if 'DoNotCheckSecurity' in extended_attributes: | 370 if 'DoNotCheckSecurity' in extended_attributes: |
| 335 access_control.append('v8::ALL_CAN_READ') | 371 access_control.append('v8::ALL_CAN_READ') |
| 336 if not attribute.is_read_only: | 372 if not attribute.is_read_only: |
| 337 access_control.append('v8::ALL_CAN_WRITE') | 373 access_control.append('v8::ALL_CAN_WRITE') |
| 338 if 'DoNotCheckSecurityOnSetter' in extended_attributes: | 374 if 'DoNotCheckSecurityOnSetter' in extended_attributes: |
| 339 access_control.append('v8::ALL_CAN_WRITE') | 375 access_control.append('v8::ALL_CAN_WRITE') |
| 340 if 'DoNotCheckSecurityOnGetter' in extended_attributes: | 376 if 'DoNotCheckSecurityOnGetter' in extended_attributes: |
| 341 access_control.append('v8::ALL_CAN_READ') | 377 access_control.append('v8::ALL_CAN_READ') |
| 342 if 'Unforgeable' in extended_attributes: | 378 if 'Unforgeable' in extended_attributes: |
| 343 access_control.append('v8::PROHIBITS_OVERWRITING') | 379 access_control.append('v8::PROHIBITS_OVERWRITING') |
| 344 return access_control or ['v8::DEFAULT'] | 380 return access_control or ['v8::DEFAULT'] |
| 345 | 381 |
| 346 | 382 |
| 347 # [NotEnumerable], [Unforgeable] | 383 # [NotEnumerable], [Unforgeable] |
| 348 def property_attributes(attribute): | 384 def property_attributes(attribute): |
| 349 extended_attributes = attribute.extended_attributes | 385 extended_attributes = attribute.extended_attributes |
| 350 property_attributes_list = [] | 386 property_attributes_list = [] |
| 351 if 'NotEnumerable' in extended_attributes: | 387 if ('NotEnumerable' in extended_attributes or |
| 388 is_constructor(attribute)): | |
| 352 property_attributes_list.append('v8::DontEnum') | 389 property_attributes_list.append('v8::DontEnum') |
| 353 if 'Unforgeable' in extended_attributes: | 390 if 'Unforgeable' in extended_attributes: |
| 354 property_attributes_list.append('v8::DontDelete') | 391 property_attributes_list.append('v8::DontDelete') |
| 355 return property_attributes_list or ['v8::None'] | 392 return property_attributes_list or ['v8::None'] |
| 356 | 393 |
| 357 | 394 |
| 358 # [PerWorldBindings] | 395 def is_constructor(attribute): |
| 359 def getter_callback_name_for_main_world(interface, attribute): | 396 return attribute.data_type.endswith('Constructor') |
| 360 if 'PerWorldBindings' not in attribute.extended_attributes: | |
| 361 return '0' | |
| 362 return '%sV8Internal::%sAttributeGetterCallbackForMainWorld' % (cpp_name(int erface), attribute.name) | |
| 363 | |
| 364 | |
| 365 def setter_callback_name_for_main_world(interface, attribute): | |
| 366 if ('PerWorldBindings' not in attribute.extended_attributes or | |
| 367 attribute.is_read_only): | |
| 368 return '0' | |
| 369 return '%sV8Internal::%sAttributeSetterCallbackForMainWorld' % (cpp_name(int erface), attribute.name) | |
| OLD | NEW |