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