| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 uncapitalize, extended_attribute_value_as_list) | 43 uncapitalize, extended_attribute_value_as_list) |
| 44 | 44 |
| 45 | 45 |
| 46 def attribute_context(interface, attribute): | 46 def attribute_context(interface, attribute): |
| 47 idl_type = attribute.idl_type | 47 idl_type = attribute.idl_type |
| 48 base_idl_type = idl_type.base_type | 48 base_idl_type = idl_type.base_type |
| 49 extended_attributes = attribute.extended_attributes | 49 extended_attributes = attribute.extended_attributes |
| 50 | 50 |
| 51 idl_type.add_includes_for_type() | 51 idl_type.add_includes_for_type() |
| 52 | 52 |
| 53 # [CheckSecurity] | |
| 54 is_check_security_for_node = 'CheckSecurity' in extended_attributes | |
| 55 if is_check_security_for_node: | |
| 56 includes.add('bindings/core/v8/BindingSecurity.h') | |
| 57 # [CustomElementCallbacks], [Reflect] | 53 # [CustomElementCallbacks], [Reflect] |
| 58 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s | 54 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s |
| 59 is_reflect = 'Reflect' in extended_attributes | 55 is_reflect = 'Reflect' in extended_attributes |
| 60 if is_custom_element_callbacks or is_reflect: | 56 if is_custom_element_callbacks or is_reflect: |
| 61 includes.add('core/dom/custom/CustomElementProcessingStack.h') | 57 includes.add('core/dom/custom/CustomElementProcessingStack.h') |
| 62 # [PerWorldBindings] | |
| 63 if 'PerWorldBindings' in extended_attributes: | |
| 64 assert idl_type.is_wrapper_type or 'LogActivity' in extended_attributes,
'[PerWorldBindings] should only be used with wrapper types: %s.%s' % (interface
.name, attribute.name) | |
| 65 # [TypeChecking] | 58 # [TypeChecking] |
| 66 has_type_checking_unrestricted = ( | 59 has_type_checking_unrestricted = ( |
| 67 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted')
or | 60 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted')
or |
| 68 has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')
) and | 61 has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')
) and |
| 69 idl_type.name in ('Float', 'Double')) | 62 idl_type.name in ('Float', 'Double')) |
| 70 # [ImplementedInPrivateScript] | |
| 71 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes | |
| 72 if is_implemented_in_private_script: | |
| 73 includes.add('bindings/core/v8/PrivateScriptRunner.h') | |
| 74 includes.add('core/frame/LocalFrame.h') | |
| 75 includes.add('platform/ScriptForbiddenScope.h') | |
| 76 | |
| 77 # [OnlyExposedToPrivateScript] | |
| 78 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended
_attributes | |
| 79 | 63 |
| 80 if (base_idl_type == 'EventHandler' and | 64 if (base_idl_type == 'EventHandler' and |
| 81 interface.name in ['Window'] and | 65 interface.name in ['Window'] and |
| 82 attribute.name == 'onerror'): | 66 attribute.name == 'onerror'): |
| 83 includes.add('bindings/core/v8/V8ErrorHandler.h') | 67 includes.add('bindings/core/v8/V8ErrorHandler.h') |
| 84 | 68 |
| 85 context = { | 69 context = { |
| 86 'access_control_list': access_control_list(attribute), | |
| 87 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_
world_list(attribute, 'Getter'), # [ActivityLogging] | |
| 88 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_
world_list(attribute, 'Setter'), # [ActivityLogging] | |
| 89 'activity_logging_include_old_value_for_setter': 'LogPreviousValue' in e
xtended_attributes, # [ActivityLogging] | |
| 90 'activity_logging_world_check': v8_utilities.activity_logging_world_chec
k(attribute), # [ActivityLogging] | |
| 91 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 70 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
| 92 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), | 71 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), |
| 93 'conditional_string': v8_utilities.conditional_string(attribute), | |
| 94 'constructor_type': idl_type.constructor_type_name | 72 'constructor_type': idl_type.constructor_type_name |
| 95 if is_constructor_attribute(attribute) else None, | 73 if is_constructor_attribute(attribute) else None, |
| 96 'cpp_name': cpp_name(attribute), | 74 'cpp_name': cpp_name(attribute), |
| 97 'cpp_type': idl_type.cpp_type, | 75 'cpp_type': idl_type.cpp_type, |
| 98 'cpp_type_initializer': idl_type.cpp_type_initializer, | 76 'cpp_type_initializer': idl_type.cpp_type_initializer, |
| 99 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] | |
| 100 'enum_validation_expression': idl_type.enum_validation_expression, | 77 'enum_validation_expression': idl_type.enum_validation_expression, |
| 101 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] | 78 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] |
| 102 'has_custom_getter': has_custom_getter(attribute), | 79 'has_custom_getter': has_custom_getter(attribute), |
| 103 'has_custom_setter': has_custom_setter(attribute), | 80 'has_custom_setter': has_custom_setter(attribute), |
| 104 'has_type_checking_unrestricted': has_type_checking_unrestricted, | 81 'has_type_checking_unrestricted': has_type_checking_unrestricted, |
| 105 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::
ConversionContext::setConversionType | 82 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::
ConversionContext::setConversionType |
| 106 'is_call_with_execution_context': v8_utilities.has_extended_attribute_va
lue(attribute, 'CallWith', 'ExecutionContext'), | 83 'is_call_with_execution_context': v8_utilities.has_extended_attribute_va
lue(attribute, 'CallWith', 'ExecutionContext'), |
| 107 'is_call_with_script_state': v8_utilities.has_extended_attribute_value(a
ttribute, 'CallWith', 'ScriptState'), | 84 'is_call_with_script_state': v8_utilities.has_extended_attribute_value(a
ttribute, 'CallWith', 'ScriptState'), |
| 108 'is_check_security_for_node': is_check_security_for_node, | |
| 109 'is_custom_element_callbacks': is_custom_element_callbacks, | 85 'is_custom_element_callbacks': is_custom_element_callbacks, |
| 110 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, | |
| 111 'is_getter_raises_exception': # [RaisesException] | 86 'is_getter_raises_exception': # [RaisesException] |
| 112 'RaisesException' in extended_attributes and | 87 'RaisesException' in extended_attributes and |
| 113 extended_attributes['RaisesException'] in (None, 'Getter'), | 88 extended_attributes['RaisesException'] in (None, 'Getter'), |
| 114 'is_implemented_in_private_script': is_implemented_in_private_script, | |
| 115 'is_initialized_by_event_constructor': | 89 'is_initialized_by_event_constructor': |
| 116 'InitializedByEventConstructor' in extended_attributes, | 90 'InitializedByEventConstructor' in extended_attributes, |
| 117 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), | 91 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), |
| 118 'is_nullable': idl_type.is_nullable, | 92 'is_nullable': idl_type.is_nullable, |
| 119 'is_explicit_nullable': idl_type.is_explicit_nullable, | 93 'is_explicit_nullable': idl_type.is_explicit_nullable, |
| 120 'is_partial_interface_member': | 94 'is_partial_interface_member': |
| 121 'PartialInterfaceImplementedAs' in extended_attributes, | 95 'PartialInterfaceImplementedAs' in extended_attributes, |
| 122 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, | |
| 123 'is_read_only': attribute.is_read_only, | 96 'is_read_only': attribute.is_read_only, |
| 124 'is_reflect': is_reflect, | 97 'is_reflect': is_reflect, |
| 125 'is_replaceable': 'Replaceable' in attribute.extended_attributes, | 98 'is_replaceable': 'Replaceable' in attribute.extended_attributes, |
| 126 'is_static': attribute.is_static, | 99 'is_static': attribute.is_static, |
| 127 'is_url': 'URL' in extended_attributes, | 100 'is_url': 'URL' in extended_attributes, |
| 128 'is_unforgeable': 'Unforgeable' in extended_attributes, | |
| 129 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] | |
| 130 'name': attribute.name, | 101 'name': attribute.name, |
| 131 'only_exposed_to_private_script': is_only_exposed_to_private_script, | |
| 132 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local
_cpp_value( | |
| 133 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is
olate()', used_in_private_script=True), | |
| 134 'property_attributes': property_attributes(attribute), | |
| 135 'put_forwards': 'PutForwards' in extended_attributes, | 102 'put_forwards': 'PutForwards' in extended_attributes, |
| 136 'reflect_empty': extended_attributes.get('ReflectEmpty'), | 103 'reflect_empty': extended_attributes.get('ReflectEmpty'), |
| 137 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), | 104 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), |
| 138 'reflect_missing': extended_attributes.get('ReflectMissing'), | 105 'reflect_missing': extended_attributes.get('ReflectMissing'), |
| 139 'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly
'), | 106 'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly
'), |
| 140 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(a
ttribute), # [RuntimeEnabled] | |
| 141 'setter_callback': setter_callback_name(interface, attribute), | 107 'setter_callback': setter_callback_name(interface, attribute), |
| 142 'should_be_exposed_to_script': not (is_implemented_in_private_script and
is_only_exposed_to_private_script), | |
| 143 'world_suffixes': ['', 'ForMainWorld'] | |
| 144 if 'PerWorldBindings' in extended_attributes | |
| 145 else [''], # [PerWorldBindings] | |
| 146 } | 108 } |
| 147 | 109 |
| 148 if is_constructor_attribute(attribute): | 110 if is_constructor_attribute(attribute): |
| 149 constructor_getter_context(interface, attribute, context) | 111 constructor_getter_context(interface, attribute, context) |
| 150 return context | 112 return context |
| 151 if not has_custom_getter(attribute): | 113 if not has_custom_getter(attribute): |
| 152 getter_context(interface, attribute, context) | 114 getter_context(interface, attribute, context) |
| 153 if (not has_custom_setter(attribute) and | 115 if (not has_custom_setter(attribute) and |
| 154 (not attribute.is_read_only or 'PutForwards' in extended_attributes)): | 116 (not attribute.is_read_only or 'PutForwards' in extended_attributes)): |
| 155 setter_context(interface, attribute, context) | 117 setter_context(interface, attribute, context) |
| 156 | 118 |
| 157 return context | 119 return context |
| 158 | 120 |
| 159 | 121 |
| 160 ################################################################################ | 122 ################################################################################ |
| 161 # Getter | 123 # Getter |
| 162 ################################################################################ | 124 ################################################################################ |
| 163 | 125 |
| 164 def getter_context(interface, attribute, context): | 126 def getter_context(interface, attribute, context): |
| 165 idl_type = attribute.idl_type | |
| 166 base_idl_type = idl_type.base_type | |
| 167 extended_attributes = attribute.extended_attributes | |
| 168 | |
| 169 cpp_value = getter_expression(interface, attribute, context) | 127 cpp_value = getter_expression(interface, attribute, context) |
| 170 # Normally we can inline the function call into the return statement to | |
| 171 # avoid the overhead of using a Ref<> temporary, but for some cases | |
| 172 # (nullable types, EventHandler, [CachedAttribute], or if there are | |
| 173 # exceptions), we need to use a local variable. | |
| 174 # FIXME: check if compilers are smart enough to inline this, and if so, | |
| 175 # always use a local variable (for readability and CG simplicity). | |
| 176 release = False | |
| 177 if 'ImplementedInPrivateScript' in extended_attributes: | |
| 178 if (not idl_type.is_wrapper_type and | |
| 179 not idl_type.is_basic_type and | |
| 180 not idl_type.is_enum): | |
| 181 raise Exception('Private scripts supports only primitive types and D
OM wrappers.') | |
| 182 | |
| 183 context['cpp_value_original'] = cpp_value | |
| 184 cpp_value = 'result' | |
| 185 # EventHandler has special handling | |
| 186 if base_idl_type != 'EventHandler': | |
| 187 release = idl_type.release | |
| 188 elif (idl_type.is_explicit_nullable or | |
| 189 base_idl_type == 'EventHandler' or | |
| 190 'CachedAttribute' in extended_attributes or | |
| 191 'LogPreviousValue' in extended_attributes or | |
| 192 'ReflectOnly' in extended_attributes or | |
| 193 context['is_keep_alive_for_gc'] or | |
| 194 context['is_getter_raises_exception']): | |
| 195 context['cpp_value_original'] = cpp_value | |
| 196 cpp_value = 'cppValue' | |
| 197 # EventHandler has special handling | |
| 198 if base_idl_type != 'EventHandler': | |
| 199 release = idl_type.release | |
| 200 | |
| 201 def v8_set_return_value_statement(for_main_world=False): | |
| 202 if context['is_keep_alive_for_gc']: | |
| 203 return 'v8SetReturnValue(info, wrapper)' | |
| 204 return idl_type.v8_set_return_value(cpp_value, extended_attributes=exten
ded_attributes, script_wrappable='impl', release=release, for_main_world=for_mai
n_world) | |
| 205 | 128 |
| 206 context.update({ | 129 context.update({ |
| 207 'cpp_value': cpp_value, | 130 'cpp_value': cpp_value, |
| 208 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | |
| 209 cpp_value=cpp_value, creation_context='info.Holder()', | |
| 210 extended_attributes=extended_attributes), | |
| 211 'v8_set_return_value_for_main_world': v8_set_return_value_statement(for_
main_world=True), | |
| 212 'v8_set_return_value': v8_set_return_value_statement(), | |
| 213 }) | 131 }) |
| 214 | 132 |
| 215 | 133 |
| 216 def getter_expression(interface, attribute, context): | 134 def getter_expression(interface, attribute, context): |
| 217 arguments = [] | 135 arguments = [] |
| 218 this_getter_base_name = getter_base_name(interface, attribute, arguments) | 136 this_getter_base_name = getter_base_name(interface, attribute, arguments) |
| 219 getter_name = scoped_name(interface, attribute, this_getter_base_name) | 137 getter_name = scoped_name(interface, attribute, this_getter_base_name) |
| 220 | 138 |
| 221 if 'ImplementedInPrivateScript' in attribute.extended_attributes: | |
| 222 arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentCont
ext())') | |
| 223 arguments.append('impl') | |
| 224 arguments.append('&result') | |
| 225 arguments.extend(v8_utilities.call_with_arguments( | 139 arguments.extend(v8_utilities.call_with_arguments( |
| 226 attribute.extended_attributes.get('CallWith'))) | 140 attribute.extended_attributes.get('CallWith'))) |
| 227 # Members of IDL partial interface definitions are implemented in C++ as | 141 # Members of IDL partial interface definitions are implemented in C++ as |
| 228 # static member functions, which for instance members (non-static members) | 142 # static member functions, which for instance members (non-static members) |
| 229 # take *impl as their first argument | 143 # take *impl as their first argument |
| 230 if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and | 144 if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and |
| 231 not 'ImplementedInPrivateScript' in attribute.extended_attributes and | |
| 232 not attribute.is_static): | 145 not attribute.is_static): |
| 233 arguments.append('*impl') | 146 arguments.append('*impl') |
| 234 if attribute.idl_type.is_explicit_nullable: | 147 if attribute.idl_type.is_explicit_nullable: |
| 235 arguments.append('isNull') | 148 arguments.append('isNull') |
| 236 if context['is_getter_raises_exception']: | 149 if context['is_getter_raises_exception']: |
| 237 arguments.append('exceptionState') | 150 arguments.append('exceptionState') |
| 238 return '%s(%s)' % (getter_name, ', '.join(arguments)) | 151 return '%s(%s)' % (getter_name, ', '.join(arguments)) |
| 239 | 152 |
| 240 | 153 |
| 241 CONTENT_ATTRIBUTE_GETTER_NAMES = { | 154 CONTENT_ATTRIBUTE_GETTER_NAMES = { |
| 242 'boolean': 'hasAttribute', | 155 'boolean': 'hasAttribute', |
| 243 'long': 'getIntegralAttribute', | 156 'long': 'getIntegralAttribute', |
| 244 'unsigned long': 'getUnsignedIntegralAttribute', | 157 'unsigned long': 'getUnsignedIntegralAttribute', |
| 245 } | 158 } |
| 246 | 159 |
| 247 | 160 |
| 248 def getter_base_name(interface, attribute, arguments): | 161 def getter_base_name(interface, attribute, arguments): |
| 249 extended_attributes = attribute.extended_attributes | 162 extended_attributes = attribute.extended_attributes |
| 250 | 163 |
| 251 if 'ImplementedInPrivateScript' in extended_attributes: | |
| 252 return '%sAttributeGetter' % uncapitalize(cpp_name(attribute)) | |
| 253 | |
| 254 if 'Reflect' not in extended_attributes: | 164 if 'Reflect' not in extended_attributes: |
| 255 return uncapitalize(cpp_name(attribute)) | 165 return uncapitalize(cpp_name(attribute)) |
| 256 | 166 |
| 257 content_attribute_name = extended_attributes['Reflect'] or attribute.name.lo
wer() | 167 content_attribute_name = extended_attributes['Reflect'] or attribute.name.lo
wer() |
| 258 if content_attribute_name in ['class', 'id']: | 168 if content_attribute_name in ['class', 'id']: |
| 259 # Special-case for performance optimization. | 169 # Special-case for performance optimization. |
| 260 return 'get%sAttribute' % content_attribute_name.capitalize() | 170 return 'get%sAttribute' % content_attribute_name.capitalize() |
| 261 | 171 |
| 262 arguments.append(scoped_content_attribute_name(interface, attribute)) | 172 arguments.append(scoped_content_attribute_name(interface, attribute)) |
| 263 | 173 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 281 idl_type.is_wrapper_type and | 191 idl_type.is_wrapper_type and |
| 282 # There are some exceptions, however: | 192 # There are some exceptions, however: |
| 283 not( | 193 not( |
| 284 # Node lifetime is managed by object grouping. | 194 # Node lifetime is managed by object grouping. |
| 285 inherits_interface(interface.name, 'Node') or | 195 inherits_interface(interface.name, 'Node') or |
| 286 inherits_interface(base_idl_type, 'Node') or | 196 inherits_interface(base_idl_type, 'Node') or |
| 287 # A self-reference is unnecessary. | 197 # A self-reference is unnecessary. |
| 288 attribute.name == 'self' or | 198 attribute.name == 'self' or |
| 289 # FIXME: Remove these hard-coded hacks. | 199 # FIXME: Remove these hard-coded hacks. |
| 290 base_idl_type in ['EventTarget', 'Window'] or | 200 base_idl_type in ['EventTarget', 'Window'] or |
| 291 base_idl_type.startswith(('HTML', 'SVG'))))) | 201 base_idl_type.startswith('HTML')))) |
| 292 | 202 |
| 293 | 203 |
| 294 ################################################################################ | 204 ################################################################################ |
| 295 # Setter | 205 # Setter |
| 296 ################################################################################ | 206 ################################################################################ |
| 297 | 207 |
| 298 def setter_context(interface, attribute, context): | 208 def setter_context(interface, attribute, context): |
| 299 if 'PutForwards' in attribute.extended_attributes: | 209 if 'PutForwards' in attribute.extended_attributes: |
| 300 # Use target interface and attribute in place of original interface and | 210 # Use target interface and attribute in place of original interface and |
| 301 # attribute from this point onwards. | 211 # attribute from this point onwards. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 326 | 236 |
| 327 context.update({ | 237 context.update({ |
| 328 'has_setter_exception_state': | 238 'has_setter_exception_state': |
| 329 is_setter_raises_exception or has_type_checking_interface or | 239 is_setter_raises_exception or has_type_checking_interface or |
| 330 context['has_type_checking_unrestricted'] or | 240 context['has_type_checking_unrestricted'] or |
| 331 idl_type.may_raise_exception_on_conversion, | 241 idl_type.may_raise_exception_on_conversion, |
| 332 'has_type_checking_interface': has_type_checking_interface, | 242 'has_type_checking_interface': has_type_checking_interface, |
| 333 'is_setter_call_with_execution_context': v8_utilities.has_extended_attri
bute_value( | 243 'is_setter_call_with_execution_context': v8_utilities.has_extended_attri
bute_value( |
| 334 attribute, 'SetterCallWith', 'ExecutionContext'), | 244 attribute, 'SetterCallWith', 'ExecutionContext'), |
| 335 'is_setter_raises_exception': is_setter_raises_exception, | 245 'is_setter_raises_exception': is_setter_raises_exception, |
| 336 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | |
| 337 'cppValue', isolate='scriptState->isolate()', | |
| 338 creation_context='scriptState->context()->Global()'), | |
| 339 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( | |
| 340 extended_attributes, 'v8Value', 'cppValue'), | |
| 341 }) | 246 }) |
| 342 | 247 |
| 343 # setter_expression() depends on context values we set above. | |
| 344 context['cpp_setter'] = setter_expression(interface, attribute, context) | |
| 345 | |
| 346 | |
| 347 def setter_expression(interface, attribute, context): | |
| 348 extended_attributes = attribute.extended_attributes | |
| 349 arguments = v8_utilities.call_with_arguments( | |
| 350 extended_attributes.get('SetterCallWith') or | |
| 351 extended_attributes.get('CallWith')) | |
| 352 | |
| 353 this_setter_base_name = setter_base_name(interface, attribute, arguments) | |
| 354 setter_name = scoped_name(interface, attribute, this_setter_base_name) | |
| 355 | |
| 356 # Members of IDL partial interface definitions are implemented in C++ as | |
| 357 # static member functions, which for instance members (non-static members) | |
| 358 # take *impl as their first argument | |
| 359 if ('PartialInterfaceImplementedAs' in extended_attributes and | |
| 360 not 'ImplementedInPrivateScript' in extended_attributes and | |
| 361 not attribute.is_static): | |
| 362 arguments.append('*impl') | |
| 363 idl_type = attribute.idl_type | |
| 364 if 'ImplementedInPrivateScript' in extended_attributes: | |
| 365 arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentCont
ext())') | |
| 366 arguments.append('impl') | |
| 367 arguments.append('cppValue') | |
| 368 elif idl_type.base_type == 'EventHandler': | |
| 369 getter_name = scoped_name(interface, attribute, cpp_name(attribute)) | |
| 370 context['event_handler_getter_expression'] = '%s(%s)' % ( | |
| 371 getter_name, ', '.join(arguments)) | |
| 372 if (interface.name in ['Window'] and | |
| 373 attribute.name == 'onerror'): | |
| 374 includes.add('bindings/core/v8/V8ErrorHandler.h') | |
| 375 arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHa
ndler>(v8Value, ScriptState::current(info.GetIsolate()))') | |
| 376 else: | |
| 377 arguments.append('V8EventListenerList::getEventListener(ScriptState:
:current(info.GetIsolate()), v8Value, ListenerFindOrCreate)') | |
| 378 elif idl_type.is_interface_type: | |
| 379 # FIXME: should be able to eliminate WTF::getPtr in most or all cases | |
| 380 arguments.append('WTF::getPtr(cppValue)') | |
| 381 else: | |
| 382 arguments.append('cppValue') | |
| 383 if context['is_setter_raises_exception']: | |
| 384 arguments.append('exceptionState') | |
| 385 | |
| 386 return '%s(%s)' % (setter_name, ', '.join(arguments)) | |
| 387 | |
| 388 | 248 |
| 389 CONTENT_ATTRIBUTE_SETTER_NAMES = { | 249 CONTENT_ATTRIBUTE_SETTER_NAMES = { |
| 390 'boolean': 'setBooleanAttribute', | 250 'boolean': 'setBooleanAttribute', |
| 391 'long': 'setIntegralAttribute', | 251 'long': 'setIntegralAttribute', |
| 392 'unsigned long': 'setUnsignedIntegralAttribute', | 252 'unsigned long': 'setUnsignedIntegralAttribute', |
| 393 } | 253 } |
| 394 | 254 |
| 395 | 255 |
| 396 def setter_base_name(interface, attribute, arguments): | 256 def setter_base_name(interface, attribute, arguments): |
| 397 if 'ImplementedInPrivateScript' in attribute.extended_attributes: | |
| 398 return '%sAttributeSetter' % uncapitalize(cpp_name(attribute)) | |
| 399 | |
| 400 if 'Reflect' not in attribute.extended_attributes: | 257 if 'Reflect' not in attribute.extended_attributes: |
| 401 return 'set%s' % capitalize(cpp_name(attribute)) | 258 return 'set%s' % capitalize(cpp_name(attribute)) |
| 402 arguments.append(scoped_content_attribute_name(interface, attribute)) | 259 arguments.append(scoped_content_attribute_name(interface, attribute)) |
| 403 | 260 |
| 404 base_idl_type = attribute.idl_type.base_type | 261 base_idl_type = attribute.idl_type.base_type |
| 405 if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES: | 262 if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES: |
| 406 return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type] | 263 return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type] |
| 407 return 'setAttribute' | 264 return 'setAttribute' |
| 408 | 265 |
| 409 | 266 |
| 410 def scoped_content_attribute_name(interface, attribute): | 267 def scoped_content_attribute_name(interface, attribute): |
| 411 content_attribute_name = attribute.extended_attributes['Reflect'] or attribu
te.name.lower() | 268 content_attribute_name = attribute.extended_attributes['Reflect'] or attribu
te.name.lower() |
| 412 namespace = 'HTMLNames' | 269 namespace = 'HTMLNames' |
| 413 includes.add('core/%s.h' % namespace) | 270 includes.add('gen/sky/core/%s.h' % namespace) |
| 414 return '%s::%sAttr' % (namespace, content_attribute_name) | 271 return '%s::%sAttr' % (namespace, content_attribute_name) |
| 415 | 272 |
| 416 | 273 |
| 417 ################################################################################ | 274 ################################################################################ |
| 418 # Attribute configuration | 275 # Attribute configuration |
| 419 ################################################################################ | 276 ################################################################################ |
| 420 | 277 |
| 421 # [Replaceable] | 278 # [Replaceable] |
| 422 def setter_callback_name(interface, attribute): | 279 def setter_callback_name(interface, attribute): |
| 423 cpp_class_name = cpp_name(interface) | 280 cpp_class_name = cpp_name(interface) |
| 424 extended_attributes = attribute.extended_attributes | 281 extended_attributes = attribute.extended_attributes |
| 425 if (('Replaceable' in extended_attributes and | 282 if (('Replaceable' in extended_attributes and |
| 426 'PutForwards' not in extended_attributes) or | 283 'PutForwards' not in extended_attributes) or |
| 427 is_constructor_attribute(attribute)): | 284 is_constructor_attribute(attribute)): |
| 428 return '{0}V8Internal::{0}ForceSetAttributeOnThisCallback'.format(cpp_cl
ass_name) | 285 return '{0}V8Internal::{0}ForceSetAttributeOnThisCallback'.format(cpp_cl
ass_name) |
| 429 if attribute.is_read_only and 'PutForwards' not in extended_attributes: | 286 if attribute.is_read_only and 'PutForwards' not in extended_attributes: |
| 430 return '0' | 287 return '0' |
| 431 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut
e.name) | 288 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut
e.name) |
| 432 | 289 |
| 433 | 290 |
| 434 # [DoNotCheckSecurity], [Unforgeable] | |
| 435 def access_control_list(attribute): | |
| 436 extended_attributes = attribute.extended_attributes | |
| 437 access_control = [] | |
| 438 if 'DoNotCheckSecurity' in extended_attributes: | |
| 439 do_not_check_security = extended_attributes['DoNotCheckSecurity'] | |
| 440 if do_not_check_security == 'Setter': | |
| 441 access_control.append('v8::ALL_CAN_WRITE') | |
| 442 else: | |
| 443 access_control.append('v8::ALL_CAN_READ') | |
| 444 if (not attribute.is_read_only or | |
| 445 'Replaceable' in extended_attributes): | |
| 446 access_control.append('v8::ALL_CAN_WRITE') | |
| 447 if 'Unforgeable' in extended_attributes: | |
| 448 access_control.append('v8::PROHIBITS_OVERWRITING') | |
| 449 return access_control or ['v8::DEFAULT'] | |
| 450 | |
| 451 | |
| 452 # [NotEnumerable], [Unforgeable] | |
| 453 def property_attributes(attribute): | |
| 454 extended_attributes = attribute.extended_attributes | |
| 455 property_attributes_list = [] | |
| 456 if ('NotEnumerable' in extended_attributes or | |
| 457 is_constructor_attribute(attribute)): | |
| 458 property_attributes_list.append('v8::DontEnum') | |
| 459 if 'Unforgeable' in extended_attributes: | |
| 460 property_attributes_list.append('v8::DontDelete') | |
| 461 return property_attributes_list or ['v8::None'] | |
| 462 | |
| 463 | |
| 464 # [Custom], [Custom=Getter] | 291 # [Custom], [Custom=Getter] |
| 465 def has_custom_getter(attribute): | 292 def has_custom_getter(attribute): |
| 466 extended_attributes = attribute.extended_attributes | 293 extended_attributes = attribute.extended_attributes |
| 467 return ('Custom' in extended_attributes and | 294 return ('Custom' in extended_attributes and |
| 468 extended_attributes['Custom'] in [None, 'Getter']) | 295 extended_attributes['Custom'] in [None, 'Getter']) |
| 469 | 296 |
| 470 | 297 |
| 471 # [Custom], [Custom=Setter] | 298 # [Custom], [Custom=Setter] |
| 472 def has_custom_setter(attribute): | 299 def has_custom_setter(attribute): |
| 473 extended_attributes = attribute.extended_attributes | 300 extended_attributes = attribute.extended_attributes |
| 474 return (not attribute.is_read_only and | 301 return (not attribute.is_read_only and |
| 475 'Custom' in extended_attributes and | 302 'Custom' in extended_attributes and |
| 476 extended_attributes['Custom'] in [None, 'Setter']) | 303 extended_attributes['Custom'] in [None, 'Setter']) |
| 477 | 304 |
| 478 | 305 |
| 479 ################################################################################ | 306 ################################################################################ |
| 480 # Constructors | 307 # Constructors |
| 481 ################################################################################ | 308 ################################################################################ |
| 482 | 309 |
| 483 idl_types.IdlType.constructor_type_name = property( | 310 idl_types.IdlType.constructor_type_name = property( |
| 484 # FIXME: replace this with a [ConstructorAttribute] extended attribute | 311 # FIXME: replace this with a [ConstructorAttribute] extended attribute |
| 485 lambda self: strip_suffix(self.base_type, 'Constructor')) | 312 lambda self: strip_suffix(self.base_type, 'Constructor')) |
| 486 | 313 |
| 487 | 314 |
| 488 def is_constructor_attribute(attribute): | 315 def is_constructor_attribute(attribute): |
| 489 # FIXME: replace this with [ConstructorAttribute] extended attribute | 316 # FIXME: replace this with [ConstructorAttribute] extended attribute |
| 490 return attribute.idl_type.name.endswith('Constructor') | 317 return attribute.idl_type.name.endswith('Constructor') |
| 491 | |
| 492 | |
| 493 def constructor_getter_context(interface, attribute, context): | |
| 494 context['needs_constructor_getter_callback'] = context['measure_as'] or cont
ext['deprecate_as'] | |
| OLD | NEW |