| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 for attribute in interface.attributes] | 46 for attribute in interface.attributes] |
| 47 contents = {'attributes': attributes} | 47 contents = {'attributes': attributes} |
| 48 contents.update(generate_attributes_common(interface, attributes)) | 48 contents.update(generate_attributes_common(interface, attributes)) |
| 49 return contents | 49 return contents |
| 50 | 50 |
| 51 | 51 |
| 52 def generate_attributes_common(interface, attributes): | 52 def generate_attributes_common(interface, attributes): |
| 53 v8_class_name = v8_utilities.v8_class_name(interface) | 53 v8_class_name = v8_utilities.v8_class_name(interface) |
| 54 return { | 54 return { |
| 55 'has_per_context_enabled_attributes': any(attribute['per_context_enabled
_function_name'] for attribute in attributes), | 55 'has_per_context_enabled_attributes': any(attribute['per_context_enabled
_function_name'] for attribute in attributes), |
| 56 'has_constructor_attributes': any(attribute['is_constructor'] for attrib
ute in attributes), |
| 56 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib
ute in attributes), | 57 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib
ute in attributes), |
| 57 'has_runtime_enabled_attributes': any(attribute['runtime_enabled_functio
n_name'] for attribute in attributes), | 58 'has_runtime_enabled_attributes': any(attribute['runtime_enabled_functio
n_name'] for attribute in attributes), |
| 58 'installed_attributes': '%sAttributes' % v8_class_name if attributes els
e '0', | 59 'installed_attributes': '%sAttributes' % v8_class_name if attributes els
e '0', |
| 59 # Size 0 constant array is not allowed in VC++ | 60 # Size 0 constant array is not allowed in VC++ |
| 60 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name
if attributes else '0', | 61 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name
if attributes else '0', |
| 61 } | 62 } |
| 62 | 63 |
| 63 | 64 |
| 64 def generate_attribute(interface, attribute): | 65 def generate_attribute(interface, attribute): |
| 65 idl_type = attribute.data_type | 66 idl_type = attribute.data_type |
| 66 extended_attributes = attribute.extended_attributes | 67 extended_attributes = attribute.extended_attributes |
| 67 | 68 |
| 68 has_custom_getter = has_extended_attribute(attribute, ('Custom', 'CustomGett
er')) | 69 has_custom_getter = has_extended_attribute(attribute, ('Custom', 'CustomGett
er')) |
| 69 has_custom_setter = not attribute.is_read_only and has_extended_attribute(at
tribute, ('Custom', 'CustomSetter')) | 70 has_custom_setter = not attribute.is_read_only and has_extended_attribute(at
tribute, ('Custom', 'CustomSetter')) |
| 70 contents = { | 71 contents = { |
| 71 'access_control_list': access_control_list(attribute), | 72 'access_control_list': access_control_list(attribute), |
| 72 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_
world_list(attribute, 'Getter'), # [ActivityLogging] | 73 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_
world_list(attribute, 'Getter'), # [ActivityLogging] |
| 73 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_
world_list(attribute, 'Setter'), # [ActivityLogging] | 74 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_
world_list(attribute, 'Setter'), # [ActivityLogging] |
| 74 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), | 75 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), |
| 75 'conditional_string': v8_utilities.generate_conditional_string(attribute
), | 76 'conditional_string': v8_utilities.generate_conditional_string(attribute
), |
| 76 'cpp_type': v8_types.cpp_type(idl_type), | 77 'cpp_type': v8_types.cpp_type(idl_type), |
| 77 'getter_callback_name': getter_callback_name(interface, attribute), | 78 'getter_callback_name': getter_callback_name(interface, attribute), |
| 78 'getter_callback_name_for_main_world': getter_callback_name_for_main_wor
ld(interface, attribute), | 79 'getter_callback_name_for_main_world': getter_callback_name_for_main_wor
ld(interface, attribute), |
| 79 'has_custom_getter': has_custom_getter, | 80 'has_custom_getter': has_custom_getter, |
| 80 'has_custom_setter': has_custom_setter, | 81 'has_custom_setter': has_custom_setter, |
| 81 'idl_type': idl_type, | 82 'idl_type': idl_type, |
| 83 'is_constructor': is_constructor_attribute(attribute), |
| 82 'is_getter_raises_exception': has_extended_attribute(attribute, ('Getter
RaisesException', 'RaisesException')), | 84 'is_getter_raises_exception': has_extended_attribute(attribute, ('Getter
RaisesException', 'RaisesException')), |
| 83 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), | 85 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), |
| 84 'is_nullable': attribute.is_nullable, | 86 'is_nullable': attribute.is_nullable, |
| 85 'is_read_only': attribute.is_read_only, | 87 'is_read_only': attribute.is_read_only, |
| 86 'is_replaceable': 'Replaceable' in attribute.extended_attributes, | 88 'is_replaceable': 'Replaceable' in attribute.extended_attributes, |
| 87 'is_setter_raises_exception': has_extended_attribute(attribute, ('Raises
Exception', 'SetterRaisesException')), | 89 'is_setter_raises_exception': has_extended_attribute(attribute, ('Raises
Exception', 'SetterRaisesException')), |
| 88 'is_static': attribute.is_static, | 90 'is_static': attribute.is_static, |
| 89 'name': attribute.name, | 91 'name': attribute.name, |
| 90 'per_context_enabled_function_name': v8_utilities.per_context_enabled_fu
nction_name(attribute), # [PerContextEnabled] | 92 'per_context_enabled_function_name': v8_utilities.per_context_enabled_fu
nction_name(attribute), # [PerContextEnabled] |
| 91 'property_attributes': property_attributes(attribute), | 93 'property_attributes': property_attributes(attribute), |
| 92 'setter_callback_name': setter_callback_name(interface, attribute), | 94 'setter_callback_name': setter_callback_name(interface, attribute), |
| 93 'setter_callback_name_for_main_world': setter_callback_name_for_main_wor
ld(interface, attribute), | 95 'setter_callback_name_for_main_world': setter_callback_name_for_main_wor
ld(interface, attribute), |
| 94 'v8_type': v8_types.v8_type(idl_type), | 96 'v8_type': v8_types.v8_type(idl_type), |
| 95 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_n
ame(attribute), # [RuntimeEnabled] | 97 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_n
ame(attribute), # [RuntimeEnabled] |
| 96 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings] | 98 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings] |
| 99 'wrapper_type_info': wrapper_type_info(attribute), |
| 97 } | 100 } |
| 101 if is_constructor_attribute(attribute): |
| 102 includes.update(v8_types.includes_for_type(idl_type)) |
| 103 return contents, includes |
| 98 if not has_custom_getter: | 104 if not has_custom_getter: |
| 99 generate_getter(interface, attribute, contents) | 105 generate_getter(interface, attribute, contents) |
| 100 if not attribute.is_read_only and not has_custom_setter: | 106 if not attribute.is_read_only and not has_custom_setter: |
| 101 generate_setter(interface, attribute, contents) | 107 generate_setter(interface, attribute, contents) |
| 102 | 108 |
| 103 return contents | 109 return contents |
| 104 | 110 |
| 105 | 111 |
| 112 # Getter |
| 113 |
| 106 def generate_getter(interface, attribute, contents): | 114 def generate_getter(interface, attribute, contents): |
| 107 idl_type = attribute.data_type | 115 idl_type = attribute.data_type |
| 108 v8_types.add_includes_for_type(idl_type) | 116 v8_types.add_includes_for_type(idl_type) |
| 109 extended_attributes = attribute.extended_attributes | 117 extended_attributes = attribute.extended_attributes |
| 110 | 118 |
| 111 cpp_value = getter_expression(interface, attribute, contents) | 119 cpp_value = getter_expression(interface, attribute, contents) |
| 112 # Normally we can inline the function call into the return statement to | 120 # Normally we can inline the function call into the return statement to |
| 113 # avoid the overhead of using a Ref<> temporary, but for some cases | 121 # avoid the overhead of using a Ref<> temporary, but for some cases |
| 114 # (nullable types, EventHandler, [CachedAttribute], or if there are | 122 # (nullable types, EventHandler, [CachedAttribute], or if there are |
| 115 # exceptions), we need to use a local variable. | 123 # exceptions), we need to use a local variable. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 not( | 216 not( |
| 209 # Node lifetime is managed by object grouping. | 217 # Node lifetime is managed by object grouping. |
| 210 v8_types.is_dom_node_type(idl_type) or | 218 v8_types.is_dom_node_type(idl_type) or |
| 211 # A self-reference is unnecessary. | 219 # A self-reference is unnecessary. |
| 212 attribute.name == 'self' or | 220 attribute.name == 'self' or |
| 213 # FIXME: Remove these hard-coded hacks. | 221 # FIXME: Remove these hard-coded hacks. |
| 214 idl_type in ['EventHandler', 'Promise', 'Window'] or | 222 idl_type in ['EventHandler', 'Promise', 'Window'] or |
| 215 idl_type.startswith('HTML')))) | 223 idl_type.startswith('HTML')))) |
| 216 | 224 |
| 217 | 225 |
| 226 # Setter |
| 227 |
| 218 def generate_setter(interface, attribute, contents): | 228 def generate_setter(interface, attribute, contents): |
| 219 idl_type = attribute.data_type | 229 idl_type = attribute.data_type |
| 220 extended_attributes = attribute.extended_attributes | 230 extended_attributes = attribute.extended_attributes |
| 221 if v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type
): | 231 if v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type
): |
| 222 cpp_value = 'WTF::getPtr(cppValue)' | 232 cpp_value = 'WTF::getPtr(cppValue)' |
| 223 else: | 233 else: |
| 224 cpp_value = 'cppValue' | 234 cpp_value = 'cppValue' |
| 225 is_reflect = 'Reflect' in extended_attributes | 235 is_reflect = 'Reflect' in extended_attributes |
| 226 if is_reflect: | 236 if is_reflect: |
| 227 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') | 237 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 includes.add('%s.h' % namespace) | 301 includes.add('%s.h' % namespace) |
| 292 return '%s::%sAttr' % (namespace, content_attribute_name) | 302 return '%s::%sAttr' % (namespace, content_attribute_name) |
| 293 | 303 |
| 294 | 304 |
| 295 def scoped_name(interface, attribute, base_name): | 305 def scoped_name(interface, attribute, base_name): |
| 296 if attribute.is_static: | 306 if attribute.is_static: |
| 297 return '%s::%s' % (interface.name, base_name) | 307 return '%s::%s' % (interface.name, base_name) |
| 298 return 'imp->%s' % base_name | 308 return 'imp->%s' % base_name |
| 299 | 309 |
| 300 | 310 |
| 311 # Attribute configuration |
| 312 |
| 301 def getter_callback_name(interface, attribute): | 313 def getter_callback_name(interface, attribute): |
| 314 if attribute.data_type.endswith('Constructor'): |
| 315 return '{0}V8Internal::{0}ConstructorGetter'.format(cpp_name(interface)) |
| 302 return '%sV8Internal::%sAttributeGetterCallback' % (cpp_name(interface), att
ribute.name) | 316 return '%sV8Internal::%sAttributeGetterCallback' % (cpp_name(interface), att
ribute.name) |
| 303 | 317 |
| 304 | 318 |
| 305 # [Replaceable] | 319 # [Replaceable] |
| 306 def setter_callback_name(interface, attribute): | 320 def setter_callback_name(interface, attribute): |
| 307 cpp_class_name = cpp_name(interface) | 321 cpp_class_name = cpp_name(interface) |
| 308 if 'Replaceable' in attribute.extended_attributes: | 322 if ('Replaceable' in attribute.extended_attributes or |
| 323 attribute.data_type.endswith('Constructor')): |
| 324 # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for
Constructors |
| 309 return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp
_class_name) | 325 return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp
_class_name) |
| 310 # FIXME: support [PutForwards] | 326 # FIXME: support [PutForwards] |
| 311 if attribute.is_read_only: | 327 if attribute.is_read_only: |
| 312 return '0' | 328 return '0' |
| 313 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut
e.name) | 329 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut
e.name) |
| 314 | 330 |
| 315 | 331 |
| 332 # [PerWorldBindings] |
| 333 def getter_callback_name_for_main_world(interface, attribute): |
| 334 if 'PerWorldBindings' not in attribute.extended_attributes: |
| 335 return '0' |
| 336 return '%sV8Internal::%sAttributeGetterCallbackForMainWorld' % (cpp_name(int
erface), attribute.name) |
| 337 |
| 338 |
| 339 def setter_callback_name_for_main_world(interface, attribute): |
| 340 if ('PerWorldBindings' not in attribute.extended_attributes or |
| 341 attribute.is_read_only): |
| 342 return '0' |
| 343 return '%sV8Internal::%sAttributeSetterCallbackForMainWorld' % (cpp_name(int
erface), attribute.name) |
| 344 |
| 345 |
| 346 def wrapper_type_info(attribute): |
| 347 if not is_constructor_attribute(attribute): |
| 348 return '0' |
| 349 return '&V8%s::info' % v8_types.constructor_type(attribute.data_type) |
| 350 |
| 351 |
| 316 # [DoNotCheckSecurity], [DoNotCheckSecurityOnGetter], [DoNotCheckSecurityOnSette
r], [Unforgeable] | 352 # [DoNotCheckSecurity], [DoNotCheckSecurityOnGetter], [DoNotCheckSecurityOnSette
r], [Unforgeable] |
| 317 def access_control_list(attribute): | 353 def access_control_list(attribute): |
| 318 extended_attributes = attribute.extended_attributes | 354 extended_attributes = attribute.extended_attributes |
| 319 access_control = [] | 355 access_control = [] |
| 320 if 'DoNotCheckSecurity' in extended_attributes: | 356 if 'DoNotCheckSecurity' in extended_attributes: |
| 321 access_control.append('v8::ALL_CAN_READ') | 357 access_control.append('v8::ALL_CAN_READ') |
| 322 if not attribute.is_read_only: | 358 if not attribute.is_read_only: |
| 323 access_control.append('v8::ALL_CAN_WRITE') | 359 access_control.append('v8::ALL_CAN_WRITE') |
| 324 if 'DoNotCheckSecurityOnSetter' in extended_attributes: | 360 if 'DoNotCheckSecurityOnSetter' in extended_attributes: |
| 325 access_control.append('v8::ALL_CAN_WRITE') | 361 access_control.append('v8::ALL_CAN_WRITE') |
| 326 if 'DoNotCheckSecurityOnGetter' in extended_attributes: | 362 if 'DoNotCheckSecurityOnGetter' in extended_attributes: |
| 327 access_control.append('v8::ALL_CAN_READ') | 363 access_control.append('v8::ALL_CAN_READ') |
| 328 if 'Unforgeable' in extended_attributes: | 364 if 'Unforgeable' in extended_attributes: |
| 329 access_control.append('v8::PROHIBITS_OVERWRITING') | 365 access_control.append('v8::PROHIBITS_OVERWRITING') |
| 330 return access_control or ['v8::DEFAULT'] | 366 return access_control or ['v8::DEFAULT'] |
| 331 | 367 |
| 332 | 368 |
| 333 # [NotEnumerable], [Unforgeable] | 369 # [NotEnumerable], [Unforgeable] |
| 334 def property_attributes(attribute): | 370 def property_attributes(attribute): |
| 335 extended_attributes = attribute.extended_attributes | 371 extended_attributes = attribute.extended_attributes |
| 336 property_attributes_list = [] | 372 property_attributes_list = [] |
| 337 if 'NotEnumerable' in extended_attributes: | 373 if ('NotEnumerable' in extended_attributes or |
| 374 is_constructor_attribute(attribute)): |
| 338 property_attributes_list.append('v8::DontEnum') | 375 property_attributes_list.append('v8::DontEnum') |
| 339 if 'Unforgeable' in extended_attributes: | 376 if 'Unforgeable' in extended_attributes: |
| 340 property_attributes_list.append('v8::DontDelete') | 377 property_attributes_list.append('v8::DontDelete') |
| 341 return property_attributes_list or ['v8::None'] | 378 return property_attributes_list or ['v8::None'] |
| 342 | 379 |
| 343 | 380 |
| 344 # [PerWorldBindings] | 381 def is_constructor_attribute(attribute): |
| 345 def getter_callback_name_for_main_world(interface, attribute): | 382 return attribute.data_type.endswith('Constructor') |
| 346 if 'PerWorldBindings' not in attribute.extended_attributes: | |
| 347 return '0' | |
| 348 return '%sV8Internal::%sAttributeGetterCallbackForMainWorld' % (cpp_name(int
erface), attribute.name) | |
| 349 | |
| 350 | |
| 351 def setter_callback_name_for_main_world(interface, attribute): | |
| 352 if ('PerWorldBindings' not in attribute.extended_attributes or | |
| 353 attribute.is_read_only): | |
| 354 return '0' | |
| 355 return '%sV8Internal::%sAttributeSetterCallbackForMainWorld' % (cpp_name(int
erface), attribute.name) | |
| OLD | NEW |