| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 78         'is_nullable': attribute.is_nullable, | 78         'is_nullable': attribute.is_nullable, | 
| 79         'is_static': attribute.is_static, | 79         'is_static': attribute.is_static, | 
| 80         'name': attribute.name, | 80         'name': attribute.name, | 
| 81         'property_attributes': property_attributes(attribute), | 81         'property_attributes': property_attributes(attribute), | 
| 82         'v8_type': v8_types.v8_type(idl_type), | 82         'v8_type': v8_types.v8_type(idl_type), | 
| 83     } | 83     } | 
| 84     if has_extended_attribute(attribute, ('Custom', 'CustomGetter')): | 84     if has_extended_attribute(attribute, ('Custom', 'CustomGetter')): | 
| 85         contents['is_custom_getter'] = True | 85         contents['is_custom_getter'] = True | 
| 86         return contents, set() | 86         return contents, set() | 
| 87 | 87 | 
| 88     cpp_value = getter_expression(interface, attribute, contents) | 88     includes = set() | 
|  | 89     cpp_value = getter_expression(interface, attribute, contents, includes) | 
| 89     # [GetterRaisesException], [RaisesException] | 90     # [GetterRaisesException], [RaisesException] | 
| 90     is_getter_raises_exception = has_extended_attribute(attribute, ('GetterRaise
     sException', 'RaisesException')) | 91     is_getter_raises_exception = has_extended_attribute(attribute, ('GetterRaise
     sException', 'RaisesException')) | 
| 91     # Normally we can inline the function call into the return statement to | 92     # Normally we can inline the function call into the return statement to | 
| 92     # avoid the overhead of using a Ref<> temporary, but for some cases | 93     # avoid the overhead of using a Ref<> temporary, but for some cases | 
| 93     # (nullable types, EventHandler, [CachedAttribute], or if there are | 94     # (nullable types, EventHandler, [CachedAttribute], or if there are | 
| 94     # exceptions), we need to use a local variable. | 95     # exceptions), we need to use a local variable. | 
| 95     # FIXME: check if compilers are smart enough to inline this, and if so, | 96     # FIXME: check if compilers are smart enough to inline this, and if so, | 
| 96     # always use a local variable (for readability and CG simplicity). | 97     # always use a local variable (for readability and CG simplicity). | 
| 97     if (attribute.is_nullable or | 98     if (attribute.is_nullable or | 
| 98         idl_type == 'EventHandler' or | 99         idl_type == 'EventHandler' or | 
| 99         'CachedAttribute' in extended_attributes or | 100         'CachedAttribute' in extended_attributes or | 
| 100         is_getter_raises_exception): | 101         is_getter_raises_exception): | 
| 101         contents['cpp_value_original'] = cpp_value | 102         contents['cpp_value_original'] = cpp_value | 
| 102         cpp_value = 'value' | 103         cpp_value = 'value' | 
| 103     contents['cpp_value'] = cpp_value | 104     contents['cpp_value'] = cpp_value | 
| 104 | 105 | 
| 105     if this_is_keep_alive_for_gc: | 106     if this_is_keep_alive_for_gc: | 
| 106         return_v8_value_statement = 'v8SetReturnValue(info, wrapper);' | 107         return_v8_value_statement = 'v8SetReturnValue(info, wrapper);' | 
| 107         includes = v8_types.includes_for_type(idl_type) | 108         type_includes = v8_types.includes_for_type(idl_type) | 
| 108         includes.add('bindings/v8/V8HiddenPropertyName.h') | 109         includes.add('bindings/v8/V8HiddenPropertyName.h') | 
| 109     else: | 110     else: | 
| 110         return_v8_value_statement, includes = v8_types.v8_set_return_value(idl_t
     ype, cpp_value, callback_info='info', isolate='info.GetIsolate()', extended_attr
     ibutes=extended_attributes, script_wrappable='imp') | 111         return_v8_value_statement, type_includes = v8_types.v8_set_return_value(
     idl_type, cpp_value, callback_info='info', isolate='info.GetIsolate()', extended
     _attributes=extended_attributes, script_wrappable='imp') | 
|  | 112     includes.update(type_includes) | 
| 111     contents['return_v8_value_statement'] = return_v8_value_statement | 113     contents['return_v8_value_statement'] = return_v8_value_statement | 
| 112 | 114 | 
| 113     if (idl_type == 'EventHandler' and | 115     if (idl_type == 'EventHandler' and | 
| 114         interface.name in ['Window', 'WorkerGlobalScope'] and | 116         interface.name in ['Window', 'WorkerGlobalScope'] and | 
| 115         attribute.name == 'onerror'): | 117         attribute.name == 'onerror'): | 
| 116             includes.add('bindings/v8/V8ErrorHandler.h') | 118             includes.add('bindings/v8/V8ErrorHandler.h') | 
| 117 | 119 | 
| 118     # [CheckSecurityForNode] | 120     # [CheckSecurityForNode] | 
| 119     is_check_security_for_node = 'CheckSecurityForNode' in extended_attributes | 121     is_check_security_for_node = 'CheckSecurityForNode' in extended_attributes | 
| 120     if is_check_security_for_node: | 122     if is_check_security_for_node: | 
| 121         includes.add('bindings/v8/BindingSecurity.h') | 123         includes.add('bindings/v8/BindingSecurity.h') | 
| 122     v8_utilities.generate_measure_as(attribute, contents, includes)  # [MeasureA
     s] | 124     v8_utilities.generate_measure_as(attribute, contents, includes)  # [MeasureA
     s] | 
| 123 | 125 | 
| 124     # [DeprecateAs] | 126     # [DeprecateAs] | 
| 125     v8_utilities.generate_deprecate_as(attribute, contents, includes) | 127     v8_utilities.generate_deprecate_as(attribute, contents, includes) | 
| 126     if is_check_security_for_node or is_getter_raises_exception: | 128     if is_check_security_for_node or is_getter_raises_exception: | 
| 127         includes.update(set(['bindings/v8/ExceptionMessages.h', | 129         includes.update(set(['bindings/v8/ExceptionMessages.h', | 
| 128                              'bindings/v8/ExceptionState.h'])) | 130                              'bindings/v8/ExceptionState.h'])) | 
| 129 | 131 | 
| 130     contents.update({ | 132     contents.update({ | 
| 131         'is_activity_logging_getter': v8_utilities.has_activity_logging(attribut
     e, includes, 'Getter'),  # [ActivityLogging=Access|Getter] | 133         'is_activity_logging_getter': v8_utilities.has_activity_logging(attribut
     e, includes, 'Getter'),  # [ActivityLogging=Access|Getter] | 
| 132         'is_check_security_for_node': is_check_security_for_node, | 134         'is_check_security_for_node': is_check_security_for_node, | 
| 133         'is_getter_raises_exception': is_getter_raises_exception, | 135         'is_getter_raises_exception': is_getter_raises_exception, | 
| 134     }) | 136     }) | 
| 135 | 137 | 
| 136     return contents, includes | 138     return contents, includes | 
| 137 | 139 | 
| 138 | 140 | 
| 139 def getter_expression(interface, attribute, contents): | 141 def getter_expression(interface, attribute, contents, includes): | 
| 140     this_getter_name = getter_name(interface, attribute) | 142     arguments = [] | 
| 141     arguments = v8_utilities.call_with_arguments(attribute, contents) | 143     if 'Reflect' in attribute.extended_attributes: | 
|  | 144         getter_base_name = content_attribute_getter_base_name(attribute, include
     s, arguments) | 
|  | 145     else: | 
|  | 146         getter_base_name = uncapitalize(cpp_name(attribute)) | 
|  | 147 | 
|  | 148     if attribute.is_static: | 
|  | 149         getter_name = '%s::%s' % (interface.name, getter_base_name) | 
|  | 150     else: | 
|  | 151         getter_name = 'imp->%s' % getter_base_name | 
|  | 152 | 
|  | 153     arguments.extend(v8_utilities.call_with_arguments(attribute, contents)) | 
| 142     if attribute.is_nullable: | 154     if attribute.is_nullable: | 
| 143         arguments.append('isNull') | 155         arguments.append('isNull') | 
| 144     if has_extended_attribute(attribute, ('GetterRaisesException', 'RaisesExcept
     ion')): | 156     if has_extended_attribute(attribute, ('GetterRaisesException', 'RaisesExcept
     ion')): | 
| 145         arguments.append('es') | 157         arguments.append('es') | 
| 146     if attribute.data_type == 'EventHandler': | 158     if attribute.data_type == 'EventHandler': | 
| 147         arguments.append('isolatedWorldForIsolate(info.GetIsolate())') | 159         arguments.append('isolatedWorldForIsolate(info.GetIsolate())') | 
| 148     return '%s(%s)' % (this_getter_name, ', '.join(arguments)) | 160     return '%s(%s)' % (getter_name, ', '.join(arguments)) | 
| 149 | 161 | 
| 150 | 162 | 
| 151 def getter_name(interface, attribute): | 163 CONTENT_ATTRIBUTE_GETTER_NAMES = { | 
| 152     getter_method_name = uncapitalize(cpp_name(attribute)) | 164     'boolean': 'fastHasAttribute', | 
| 153     if attribute.is_static: | 165     'long': 'getIntegralAttribute', | 
| 154         return '%s::%s' % (interface.name, getter_method_name) | 166     'unsigned long': 'getUnsignedIntegralAttribute', | 
| 155     return 'imp->%s' % getter_method_name | 167 } | 
|  | 168 | 
|  | 169 | 
|  | 170 def content_attribute_getter_base_name(attribute, includes, arguments): | 
|  | 171     content_attribute_name = attribute.extended_attributes['Reflect'] or attribu
     te.name.lower() | 
|  | 172     namespace = 'HTMLNames'  # FIXME: can be SVG too | 
|  | 173     includes.add('%s.h' % namespace) | 
|  | 174 | 
|  | 175     if content_attribute_name in ['class', 'id', 'name']: | 
|  | 176         # Special-case for performance optimization. | 
|  | 177         return 'get%sAttribute' % content_attribute_name.capitalize() | 
|  | 178 | 
|  | 179     scoped_name = '%s::%sAttr' % (namespace, content_attribute_name) | 
|  | 180     arguments.append(scoped_name) | 
|  | 181 | 
|  | 182     idl_type = attribute.data_type | 
|  | 183     if idl_type in CONTENT_ATTRIBUTE_GETTER_NAMES: | 
|  | 184         return CONTENT_ATTRIBUTE_GETTER_NAMES[idl_type] | 
|  | 185     return 'fastGetAttribute' | 
| 156 | 186 | 
| 157 | 187 | 
| 158 def is_keep_alive_for_gc(attribute): | 188 def is_keep_alive_for_gc(attribute): | 
| 159     idl_type = attribute.data_type | 189     idl_type = attribute.data_type | 
| 160     extended_attributes = attribute.extended_attributes | 190     extended_attributes = attribute.extended_attributes | 
| 161     return ( | 191     return ( | 
| 162         'KeepAttributeAliveForGC' in extended_attributes or | 192         'KeepAttributeAliveForGC' in extended_attributes or | 
| 163         # For readonly attributes, for performance reasons we keep the attribute | 193         # For readonly attributes, for performance reasons we keep the attribute | 
| 164         # wrapper alive while the owner wrapper is alive, because the attribute | 194         # wrapper alive while the owner wrapper is alive, because the attribute | 
| 165         # never changes. | 195         # never changes. | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 190         return ['v8::ALL_CAN_READ'] | 220         return ['v8::ALL_CAN_READ'] | 
| 191     return ['v8::DEFAULT'] | 221     return ['v8::DEFAULT'] | 
| 192 | 222 | 
| 193 | 223 | 
| 194 # [NotEnumerable] | 224 # [NotEnumerable] | 
| 195 def property_attributes(attribute): | 225 def property_attributes(attribute): | 
| 196     property_attributes_list = [] | 226     property_attributes_list = [] | 
| 197     if 'NotEnumerable' in attribute.extended_attributes: | 227     if 'NotEnumerable' in attribute.extended_attributes: | 
| 198         property_attributes_list.append('v8::DontEnum') | 228         property_attributes_list.append('v8::DontEnum') | 
| 199     return property_attributes_list or ['v8::None'] | 229     return property_attributes_list or ['v8::None'] | 
| OLD | NEW | 
|---|