 Chromium Code Reviews
 Chromium Code Reviews Issue 27003002:
  IDL compiler: [Reflect] for getters (+ remove unnecessary WebCore::)  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 27003002:
  IDL compiler: [Reflect] for getters (+ remove unnecessary WebCore::)  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 'is_keep_alive_for_gc': this_is_keep_alive_for_gc, | 74 'is_keep_alive_for_gc': this_is_keep_alive_for_gc, | 
| 75 'is_nullable': attribute.is_nullable, | 75 'is_nullable': attribute.is_nullable, | 
| 76 'is_static': attribute.is_static, | 76 'is_static': attribute.is_static, | 
| 77 'name': attribute.name, | 77 'name': attribute.name, | 
| 78 'v8_type': v8_types.v8_type(idl_type), | 78 'v8_type': v8_types.v8_type(idl_type), | 
| 79 } | 79 } | 
| 80 if has_extended_attribute(attribute, ('Custom', 'CustomGetter')): | 80 if has_extended_attribute(attribute, ('Custom', 'CustomGetter')): | 
| 81 contents['is_custom_getter'] = True | 81 contents['is_custom_getter'] = True | 
| 82 return contents, set() | 82 return contents, set() | 
| 83 | 83 | 
| 84 cpp_value = getter_expression(interface, attribute, contents) | 84 includes = set() | 
| 85 cpp_value = getter_expression(interface, attribute, contents, includes) | |
| 85 # Normally we can inline the function call into the return statement to | 86 # Normally we can inline the function call into the return statement to | 
| 86 # avoid the overhead of using a Ref<> temporary, but for some cases | 87 # avoid the overhead of using a Ref<> temporary, but for some cases | 
| 87 # (nullable types, EventHandler, CachedAttribute, or if there are | 88 # (nullable types, EventHandler, CachedAttribute, or if there are | 
| 88 # exceptions), we need to use a local variable. | 89 # exceptions), we need to use a local variable. | 
| 89 # FIXME: check if compilers are smart enough to inline this, and if so, | 90 # FIXME: check if compilers are smart enough to inline this, and if so, | 
| 90 # always use a local variable (for readability and CG simplicity). | 91 # always use a local variable (for readability and CG simplicity). | 
| 91 if (attribute.is_nullable or | 92 if (attribute.is_nullable or | 
| 92 idl_type == 'EventHandler' or | 93 idl_type == 'EventHandler' or | 
| 93 'CachedAttribute' in extended_attributes): | 94 'CachedAttribute' in extended_attributes): | 
| 94 contents['cpp_value_original'] = cpp_value | 95 contents['cpp_value_original'] = cpp_value | 
| 95 cpp_value = 'value' | 96 cpp_value = 'value' | 
| 96 contents['cpp_value'] = cpp_value | 97 contents['cpp_value'] = cpp_value | 
| 97 | 98 | 
| 98 if this_is_keep_alive_for_gc: | 99 if this_is_keep_alive_for_gc: | 
| 99 return_v8_value_statement = 'v8SetReturnValue(info, wrapper);' | 100 return_v8_value_statement = 'v8SetReturnValue(info, wrapper);' | 
| 100 includes = v8_types.includes_for_type(idl_type) | 101 type_includes = v8_types.includes_for_type(idl_type) | 
| 101 includes.add('bindings/v8/V8HiddenPropertyName.h') | 102 includes.add('bindings/v8/V8HiddenPropertyName.h') | 
| 102 else: | 103 else: | 
| 103 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') | 104 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') | 
| 105 includes.update(type_includes) | |
| 104 contents['return_v8_value_statement'] = return_v8_value_statement | 106 contents['return_v8_value_statement'] = return_v8_value_statement | 
| 105 | 107 | 
| 106 if (idl_type == 'EventHandler' and | 108 if (idl_type == 'EventHandler' and | 
| 107 interface.name in ['Window', 'WorkerGlobalScope'] and | 109 interface.name in ['Window', 'WorkerGlobalScope'] and | 
| 108 attribute.name == 'onerror'): | 110 attribute.name == 'onerror'): | 
| 109 includes.add('bindings/v8/V8ErrorHandler.h') | 111 includes.add('bindings/v8/V8ErrorHandler.h') | 
| 110 | 112 | 
| 111 # [CheckSecurityForNode] | 113 # [CheckSecurityForNode] | 
| 112 is_check_security_for_node = 'CheckSecurityForNode' in extended_attributes | 114 is_check_security_for_node = 'CheckSecurityForNode' in extended_attributes | 
| 113 if is_check_security_for_node: | 115 if is_check_security_for_node: | 
| 114 includes.update(set(['bindings/v8/BindingSecurity.h', | 116 includes.update(set(['bindings/v8/BindingSecurity.h', | 
| 115 # FIXME: these should be added if [CheckSecurityForNode], [GetterRaisesE xception], or [RaisesException] | 117 # FIXME: these should be added if [CheckSecurityForNode], [GetterRaisesE xception], or [RaisesException] | 
| 116 'bindings/v8/ExceptionMessages.h', | 118 'bindings/v8/ExceptionMessages.h', | 
| 117 'bindings/v8/ExceptionState.h'])) | 119 'bindings/v8/ExceptionState.h'])) | 
| 118 | 120 | 
| 119 includes.add('bindings/v8/BindingSecurity.h') | 121 includes.add('bindings/v8/BindingSecurity.h') | 
| 120 # [DeprecateAs] | 122 # [DeprecateAs] | 
| 121 v8_utilities.generate_deprecate_as(attribute, contents, includes) | 123 v8_utilities.generate_deprecate_as(attribute, contents, includes) | 
| 122 | 124 | 
| 123 contents.update({ | 125 contents.update({ | 
| 124 'is_activity_logging_getter': v8_utilities.has_activity_logging(attribut e, includes, 'Getter'), # [ActivityLogging=Access|Getter] | 126 'is_activity_logging_getter': v8_utilities.has_activity_logging(attribut e, includes, 'Getter'), # [ActivityLogging=Access|Getter] | 
| 125 'is_check_security_for_node': is_check_security_for_node, | 127 'is_check_security_for_node': is_check_security_for_node, | 
| 126 }) | 128 }) | 
| 127 | 129 | 
| 128 return contents, includes | 130 return contents, includes | 
| 129 | 131 | 
| 130 | 132 | 
| 131 def getter_expression(interface, attribute, contents): | 133 def getter_expression(interface, attribute, contents, includes): | 
| 132 this_getter_name = getter_name(interface, attribute) | 134 arguments = [] | 
| 133 arguments = v8_utilities.call_with_arguments(attribute, contents) | 135 if 'Reflect' in attribute.extended_attributes: | 
| 136 getter_base_name = content_attribute_getter_base_name(attribute, include s, arguments) | |
| 137 else: | |
| 138 getter_base_name = uncapitalize(attribute.name) | |
| 139 | |
| 140 if attribute.is_static: | |
| 141 getter_name = '%s::%s' % (interface.name, getter_base_name) | |
| 142 else: | |
| 143 getter_name = 'imp->%s' % getter_base_name | |
| 144 | |
| 145 arguments.extend(v8_utilities.call_with_arguments(attribute, contents)) | |
| 134 if attribute.is_nullable: | 146 if attribute.is_nullable: | 
| 135 arguments.append('isNull') | 147 arguments.append('isNull') | 
| 136 if attribute.data_type == 'EventHandler': | 148 if attribute.data_type == 'EventHandler': | 
| 137 arguments.append('isolatedWorldForIsolate(info.GetIsolate())') | 149 arguments.append('isolatedWorldForIsolate(info.GetIsolate())') | 
| 138 return '%s(%s)' % (this_getter_name, ', '.join(arguments)) | 150 return '%s(%s)' % (getter_name, ', '.join(arguments)) | 
| 139 | 151 | 
| 140 | 152 | 
| 141 def getter_name(interface, attribute): | 153 CONTENT_ATTRIBUTE_GETTER_NAMES = { | 
| 
haraken
2013/10/15 02:14:30
I don't fully understand what "content" means.
CO
 
Nils Barth (inactive)
2013/10/15 09:48:15
The IDL attribute is reflecting an HTML attribute
 | |
| 142 getter_method_name = uncapitalize(attribute.name) | 154 'boolean': 'fastHasAttribute', | 
| 143 if attribute.is_static: | 155 'long': 'getIntegralAttribute', | 
| 144 return '%s::%s' % (interface.name, getter_method_name) | 156 'unsigned long': 'getUnsignedIntegralAttribute', | 
| 145 return 'imp->%s' % getter_method_name | 157 } | 
| 158 | |
| 159 | |
| 160 def content_attribute_getter_base_name(attribute, includes, arguments): | |
| 
haraken
2013/10/15 02:14:30
content_attribute_getter_base_name => cpp_attribut
 | |
| 161 default_content_attribute_name = attribute.name.lower() | |
| 162 content_attribute_name = attribute.extended_attributes['Reflect'] or default _content_attribute_name | |
| 
haraken
2013/10/15 02:14:30
Nit: default_content_attribute_name is not necessa
 
Nils Barth (inactive)
2013/10/15 09:48:15
Removed.
 | |
| 163 | |
| 164 namespace = 'HTMLNames' # FIXME: can be SVG too | |
| 165 includes.add('%s.h' % namespace) | |
| 166 | |
| 167 if content_attribute_name in ['class', 'id', 'name']: | |
| 
haraken
2013/10/15 02:14:30
Add a comment:
  # For performance optimization.
 
Nils Barth (inactive)
2013/10/15 09:48:15
Done.
 | |
| 168 return 'get%sAttribute' % content_attribute_name.capitalize() | |
| 169 | |
| 170 scoped_name = 'WebCore::%s::%sAttr' % (namespace, content_attribute_name) | |
| 
haraken
2013/10/15 02:14:30
Is WebCore:: necessary?
 
Nils Barth (inactive)
2013/10/15 09:48:15
Doesn't look like it!
Removed here and in Perl.
 | |
| 171 arguments.append(scoped_name) | |
| 172 | |
| 173 idl_type = attribute.data_type | |
| 174 if idl_type in CONTENT_ATTRIBUTE_GETTER_NAMES: | |
| 175 return CONTENT_ATTRIBUTE_GETTER_NAMES[idl_type] | |
| 176 return 'fastGetAttribute' | |
| 146 | 177 | 
| 147 | 178 | 
| 148 def is_keep_alive_for_gc(attribute): | 179 def is_keep_alive_for_gc(attribute): | 
| 149 idl_type = attribute.data_type | 180 idl_type = attribute.data_type | 
| 150 extended_attributes = attribute.extended_attributes | 181 extended_attributes = attribute.extended_attributes | 
| 151 return ( | 182 return ( | 
| 152 'KeepAttributeAliveForGC' in extended_attributes or | 183 'KeepAttributeAliveForGC' in extended_attributes or | 
| 153 # For readonly attributes, for performance reasons we keep the attribute | 184 # For readonly attributes, for performance reasons we keep the attribute | 
| 154 # wrapper alive while the owner wrapper is alive, because the attribute | 185 # wrapper alive while the owner wrapper is alive, because the attribute | 
| 155 # never changes. | 186 # never changes. | 
| 156 (attribute.is_read_only and | 187 (attribute.is_read_only and | 
| 157 v8_types.wrapper_type(idl_type) and | 188 v8_types.wrapper_type(idl_type) and | 
| 158 # There are some exceptions, however: | 189 # There are some exceptions, however: | 
| 159 not( | 190 not( | 
| 160 # Node lifetime is managed by object grouping. | 191 # Node lifetime is managed by object grouping. | 
| 161 v8_types.dom_node_type(idl_type) or | 192 v8_types.dom_node_type(idl_type) or | 
| 162 # A self-reference is unnecessary. | 193 # A self-reference is unnecessary. | 
| 163 attribute.name == 'self' or | 194 attribute.name == 'self' or | 
| 164 # FIXME: Remove these hard-coded hacks. | 195 # FIXME: Remove these hard-coded hacks. | 
| 165 idl_type in ['EventHandler', 'Promise', 'Window'] or | 196 idl_type in ['EventHandler', 'Promise', 'Window'] or | 
| 166 idl_type.startswith('HTML')))) | 197 idl_type.startswith('HTML')))) | 
| OLD | NEW |