| 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 cpp_name, has_extended_attribute, uncapitalize | 40 from v8_utilities import capitalize, cpp_name, has_extended_attribute, uncapital
ize |
| 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 contents = generate_attributes_common(interface) | 50 contents = generate_attributes_common(interface) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 # Size 0 constant array is not allowed in VC++ | 61 # Size 0 constant array is not allowed in VC++ |
| 62 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name
if attributes else '0', | 62 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name
if attributes else '0', |
| 63 'attribute_templates': '%sAttributes' % v8_class_name if attributes else
'0', | 63 'attribute_templates': '%sAttributes' % v8_class_name if attributes else
'0', |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| 67 def generate_attribute_and_includes(interface, attribute): | 67 def generate_attribute_and_includes(interface, attribute): |
| 68 idl_type = attribute.data_type | 68 idl_type = attribute.data_type |
| 69 extended_attributes = attribute.extended_attributes | 69 extended_attributes = attribute.extended_attributes |
| 70 this_is_keep_alive_for_gc = is_keep_alive_for_gc(attribute) | 70 this_is_keep_alive_for_gc = is_keep_alive_for_gc(attribute) |
| 71 has_setter = not attribute.is_read_only # FIXME: need to check [Reflect] an
d [PutForwards] |
| 71 contents = { | 72 contents = { |
| 72 'access_control_list': access_control_list(attribute), | 73 'access_control_list': access_control_list(attribute), |
| 73 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), | 74 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), |
| 74 'conditional_string': v8_utilities.generate_conditional_string(attribute
), | 75 'conditional_string': v8_utilities.generate_conditional_string(attribute
), |
| 75 'cpp_type': v8_types.cpp_type(idl_type), | 76 'cpp_type': v8_types.cpp_type(idl_type), |
| 77 'getter_callback_name': getter_callback_name(interface, attribute), |
| 78 'getter_callback_name_for_main_world': getter_callback_name_for_main_wor
ld(interface, attribute), |
| 76 'idl_type': idl_type, | 79 'idl_type': idl_type, |
| 80 'has_setter': has_setter, |
| 77 'is_keep_alive_for_gc': this_is_keep_alive_for_gc, | 81 'is_keep_alive_for_gc': this_is_keep_alive_for_gc, |
| 78 'is_nullable': attribute.is_nullable, | 82 'is_nullable': attribute.is_nullable, |
| 79 'is_static': attribute.is_static, | 83 'is_static': attribute.is_static, |
| 80 'name': attribute.name, | 84 'name': attribute.name, |
| 85 'per_context_enabled_function_name': v8_utilities.per_context_enabled_fu
nction_name(attribute), # [PerContextEnabled] |
| 81 'property_attributes': property_attributes(attribute), | 86 'property_attributes': property_attributes(attribute), |
| 87 'setter_callback_name': setter_callback_name(interface, attribute), |
| 88 'setter_callback_name_for_main_world': setter_callback_name_for_main_wor
ld(interface, attribute), |
| 82 'v8_type': v8_types.v8_type(idl_type), | 89 'v8_type': v8_types.v8_type(idl_type), |
| 83 'per_context_enabled_function_name': v8_utilities.per_context_enabled_fu
nction_name(attribute), # [PerContextEnabled] | |
| 84 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_n
ame(attribute), # [RuntimeEnabled] | 90 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_n
ame(attribute), # [RuntimeEnabled] |
| 85 # [PerWorldBindings] | 91 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in attribut
e.extended_attributes else [''], # [PerWorldBindings] |
| 86 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in attribut
e.extended_attributes else [''], | |
| 87 'getter_for_main_world': getter_for_main_world(interface, attribute), | |
| 88 'setter_for_main_world': setter_for_main_world(interface, attribute), | |
| 89 } | 92 } |
| 90 if has_extended_attribute(attribute, ('Custom', 'CustomGetter')): | 93 if has_extended_attribute(attribute, ('Custom', 'CustomGetter')): |
| 91 contents['is_custom_getter'] = True | 94 contents['has_custom_getter'] = True |
| 92 return contents, set() | 95 return contents, set() |
| 93 | 96 |
| 94 includes = set() | 97 includes = set() |
| 95 cpp_value = getter_expression(interface, attribute, contents, includes) | 98 cpp_value = getter_expression(interface, attribute, contents, includes) |
| 96 # [GetterRaisesException], [RaisesException] | 99 # [GetterRaisesException], [RaisesException] |
| 97 is_getter_raises_exception = has_extended_attribute(attribute, ('GetterRaise
sException', 'RaisesException')) | 100 is_getter_raises_exception = has_extended_attribute(attribute, ('GetterRaise
sException', 'RaisesException')) |
| 98 # Normally we can inline the function call into the return statement to | 101 # Normally we can inline the function call into the return statement to |
| 99 # avoid the overhead of using a Ref<> temporary, but for some cases | 102 # avoid the overhead of using a Ref<> temporary, but for some cases |
| 100 # (nullable types, EventHandler, [CachedAttribute], or if there are | 103 # (nullable types, EventHandler, [CachedAttribute], or if there are |
| 101 # exceptions), we need to use a local variable. | 104 # exceptions), we need to use a local variable. |
| 102 # FIXME: check if compilers are smart enough to inline this, and if so, | 105 # FIXME: check if compilers are smart enough to inline this, and if so, |
| 103 # always use a local variable (for readability and CG simplicity). | 106 # always use a local variable (for readability and CG simplicity). |
| 104 if (attribute.is_nullable or | 107 if (attribute.is_nullable or |
| 105 idl_type == 'EventHandler' or | 108 idl_type == 'EventHandler' or |
| 106 'CachedAttribute' in extended_attributes or | 109 'CachedAttribute' in extended_attributes or |
| 107 is_getter_raises_exception): | 110 is_getter_raises_exception): |
| 108 contents['cpp_value_original'] = cpp_value | 111 contents['cpp_value_original'] = cpp_value |
| 109 cpp_value = 'value' | 112 cpp_value = 'value' |
| 110 contents['cpp_value'] = cpp_value | 113 contents['cpp_value'] = cpp_value |
| 111 | 114 |
| 112 if this_is_keep_alive_for_gc: | 115 if this_is_keep_alive_for_gc: |
| 113 return_v8_value_statement = 'v8SetReturnValue(info, wrapper);' | 116 v8_set_return_value_statement = 'v8SetReturnValue(info, wrapper)' |
| 114 includes.update(v8_types.includes_for_type(idl_type)) | 117 includes.update(v8_types.includes_for_type(idl_type)) |
| 115 includes.add('bindings/v8/V8HiddenPropertyName.h') | 118 includes.add('bindings/v8/V8HiddenPropertyName.h') |
| 116 else: | 119 else: |
| 117 return_v8_value_statement = v8_types.v8_set_return_value(idl_type, cpp_v
alue, includes, callback_info='info', isolate='info.GetIsolate()', extended_attr
ibutes=extended_attributes, script_wrappable='imp') | 120 v8_set_return_value_statement = v8_types.v8_set_return_value(idl_type, c
pp_value, includes, callback_info='info', isolate='info.GetIsolate()', extended_
attributes=extended_attributes, script_wrappable='imp') |
| 118 contents['return_v8_value_statement'] = return_v8_value_statement | 121 contents['v8_set_return_value'] = v8_set_return_value_statement |
| 119 | 122 |
| 120 if (idl_type == 'EventHandler' and | 123 if (idl_type == 'EventHandler' and |
| 121 interface.name in ['Window', 'WorkerGlobalScope'] and | 124 interface.name in ['Window', 'WorkerGlobalScope'] and |
| 122 attribute.name == 'onerror'): | 125 attribute.name == 'onerror'): |
| 123 includes.add('bindings/v8/V8ErrorHandler.h') | 126 includes.add('bindings/v8/V8ErrorHandler.h') |
| 124 | 127 |
| 125 # [CheckSecurityForNode] | 128 # [CheckSecurityForNode] |
| 126 is_check_security_for_node = 'CheckSecurityForNode' in extended_attributes | 129 is_check_security_for_node = 'CheckSecurityForNode' in extended_attributes |
| 127 if is_check_security_for_node: | 130 if is_check_security_for_node: |
| 128 includes.add('bindings/v8/BindingSecurity.h') | 131 includes.add('bindings/v8/BindingSecurity.h') |
| 129 v8_utilities.generate_measure_as(attribute, contents, includes) # [MeasureA
s] | 132 v8_utilities.generate_measure_as(attribute, contents, includes) # [MeasureA
s] |
| 130 | 133 |
| 131 # [DeprecateAs] | 134 # [DeprecateAs] |
| 132 v8_utilities.generate_deprecate_as(attribute, contents, includes) | 135 v8_utilities.generate_deprecate_as(attribute, contents, includes) |
| 133 if is_check_security_for_node or is_getter_raises_exception: | 136 if is_check_security_for_node or is_getter_raises_exception: |
| 134 includes.update(set(['bindings/v8/ExceptionMessages.h', | 137 includes.update(set(['bindings/v8/ExceptionMessages.h', |
| 135 'bindings/v8/ExceptionState.h'])) | 138 'bindings/v8/ExceptionState.h'])) |
| 136 | 139 |
| 137 contents.update({ | 140 contents.update({ |
| 138 'activity_logging_getter': v8_utilities.has_activity_logging(attribute,
includes, 'Getter'), # [ActivityLogging] | 141 'activity_logging_getter': v8_utilities.has_activity_logging(attribute,
includes, 'Getter'), # [ActivityLogging] |
| 139 'is_check_security_for_node': is_check_security_for_node, | 142 'is_check_security_for_node': is_check_security_for_node, |
| 140 'is_getter_raises_exception': is_getter_raises_exception, | 143 'is_getter_raises_exception': is_getter_raises_exception, |
| 141 'is_unforgeable': 'Unforgeable' in extended_attributes, | 144 'is_unforgeable': 'Unforgeable' in extended_attributes, |
| 142 }) | 145 }) |
| 143 | 146 |
| 147 # Setter |
| 148 if not has_setter: |
| 149 return contents, includes |
| 150 |
| 151 contents.update({ |
| 152 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(idl_
type, attribute.extended_attributes, 'value', 'v', includes, 'info.GetIsolate()'
), |
| 153 'cpp_setter': 'imp->set%s(v)' % capitalize(cpp_name(attribute)), |
| 154 }) |
| 155 |
| 144 return contents, includes | 156 return contents, includes |
| 145 | 157 |
| 146 | 158 |
| 147 def getter_expression(interface, attribute, contents, includes): | 159 def getter_expression(interface, attribute, contents, includes): |
| 148 arguments = [] | 160 arguments = [] |
| 149 if 'Reflect' in attribute.extended_attributes: | 161 if 'Reflect' in attribute.extended_attributes: |
| 150 getter_base_name = content_attribute_getter_base_name(attribute, include
s, arguments) | 162 getter_base_name = content_attribute_getter_base_name(attribute, include
s, arguments) |
| 151 else: | 163 else: |
| 152 getter_base_name = uncapitalize(cpp_name(attribute)) | 164 getter_base_name = uncapitalize(cpp_name(attribute)) |
| 153 | 165 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 not( | 219 not( |
| 208 # Node lifetime is managed by object grouping. | 220 # Node lifetime is managed by object grouping. |
| 209 v8_types.dom_node_type(idl_type) or | 221 v8_types.dom_node_type(idl_type) or |
| 210 # A self-reference is unnecessary. | 222 # A self-reference is unnecessary. |
| 211 attribute.name == 'self' or | 223 attribute.name == 'self' or |
| 212 # FIXME: Remove these hard-coded hacks. | 224 # FIXME: Remove these hard-coded hacks. |
| 213 idl_type in ['EventHandler', 'Promise', 'Window'] or | 225 idl_type in ['EventHandler', 'Promise', 'Window'] or |
| 214 idl_type.startswith('HTML')))) | 226 idl_type.startswith('HTML')))) |
| 215 | 227 |
| 216 | 228 |
| 229 def getter_callback_name(interface, attribute): |
| 230 return '%sV8Internal::%sAttributeGetterCallback' % (cpp_name(interface), att
ribute.name) |
| 231 |
| 232 |
| 233 def setter_callback_name(interface, attribute): |
| 234 if attribute.is_read_only: |
| 235 return '0' |
| 236 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_name(interface), att
ribute.name) |
| 237 |
| 238 |
| 217 # [DoNotCheckSecurity], [DoNotCheckSecurityOnGetter], [DoNotCheckSecurityOnSette
r], [Unforgeable] | 239 # [DoNotCheckSecurity], [DoNotCheckSecurityOnGetter], [DoNotCheckSecurityOnSette
r], [Unforgeable] |
| 218 def access_control_list(attribute): | 240 def access_control_list(attribute): |
| 219 extended_attributes = attribute.extended_attributes | 241 extended_attributes = attribute.extended_attributes |
| 220 access_control = [] | 242 access_control = [] |
| 221 if 'DoNotCheckSecurity' in extended_attributes: | 243 if 'DoNotCheckSecurity' in extended_attributes: |
| 222 access_control.append('v8::ALL_CAN_READ') | 244 access_control.append('v8::ALL_CAN_READ') |
| 223 if not attribute.is_read_only: | 245 if not attribute.is_read_only: |
| 224 access_control.append('v8::ALL_CAN_WRITE') | 246 access_control.append('v8::ALL_CAN_WRITE') |
| 225 if 'DoNotCheckSecurityOnSetter' in extended_attributes: | 247 if 'DoNotCheckSecurityOnSetter' in extended_attributes: |
| 226 access_control.append('v8::ALL_CAN_WRITE') | 248 access_control.append('v8::ALL_CAN_WRITE') |
| 227 if 'DoNotCheckSecurityOnGetter' in extended_attributes: | 249 if 'DoNotCheckSecurityOnGetter' in extended_attributes: |
| 228 access_control.append('v8::ALL_CAN_READ') | 250 access_control.append('v8::ALL_CAN_READ') |
| 229 if 'Unforgeable' in extended_attributes: | 251 if 'Unforgeable' in extended_attributes: |
| 230 access_control.append('v8::PROHIBITS_OVERWRITING') | 252 access_control.append('v8::PROHIBITS_OVERWRITING') |
| 231 return access_control or ['v8::DEFAULT'] | 253 return access_control or ['v8::DEFAULT'] |
| 232 | 254 |
| 233 | 255 |
| 234 # [NotEnumerable], [Unforgeable] | 256 # [NotEnumerable], [Unforgeable] |
| 235 def property_attributes(attribute): | 257 def property_attributes(attribute): |
| 236 extended_attributes = attribute.extended_attributes | 258 extended_attributes = attribute.extended_attributes |
| 237 property_attributes_list = [] | 259 property_attributes_list = [] |
| 238 if 'NotEnumerable' in extended_attributes: | 260 if 'NotEnumerable' in extended_attributes: |
| 239 property_attributes_list.append('v8::DontEnum') | 261 property_attributes_list.append('v8::DontEnum') |
| 240 if 'Unforgeable' in extended_attributes: | 262 if 'Unforgeable' in extended_attributes: |
| 241 property_attributes_list.append('v8::DontDelete') | 263 property_attributes_list.append('v8::DontDelete') |
| 242 return property_attributes_list or ['v8::None'] | 264 return property_attributes_list or ['v8::None'] |
| 243 | 265 |
| 244 | 266 |
| 245 # [PerWorldBindings] | 267 # [PerWorldBindings] |
| 246 def getter_for_main_world(interface, attribute): | 268 def getter_callback_name_for_main_world(interface, attribute): |
| 247 if 'PerWorldBindings' not in attribute.extended_attributes: | 269 if 'PerWorldBindings' not in attribute.extended_attributes: |
| 248 return '0' | 270 return '0' |
| 249 return '%sV8Internal::%sAttributeGetterCallbackForMainWorld' % (cpp_name(int
erface), attribute.name) | 271 return '%sV8Internal::%sAttributeGetterCallbackForMainWorld' % (cpp_name(int
erface), attribute.name) |
| 250 | 272 |
| 251 | 273 |
| 252 def setter_for_main_world(interface, attribute): | 274 def setter_callback_name_for_main_world(interface, attribute): |
| 253 if ('PerWorldBindings' not in attribute.extended_attributes or | 275 if ('PerWorldBindings' not in attribute.extended_attributes or |
| 254 attribute.is_read_only): | 276 attribute.is_read_only): |
| 255 return '0' | 277 return '0' |
| 256 return '%sV8Internal::%sAttributeSetterCallbackForMainWorld' % (cpp_name(int
erface), attribute.name) | 278 return '%sV8Internal::%sAttributeSetterCallbackForMainWorld' % (cpp_name(int
erface), attribute.name) |
| OLD | NEW |