Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: Source/bindings/scripts/v8_attributes.py

Issue 353973002: IDL: fix code generation for attributes with [PutForwards] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: the fix Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/bindings/tests/idls/TestNode.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 'Custom' in extended_attributes and 59 'Custom' in extended_attributes and
60 extended_attributes['Custom'] in [None, 'Setter']) 60 extended_attributes['Custom'] in [None, 'Setter'])
61 # [CustomElementCallbacks], [Reflect] 61 # [CustomElementCallbacks], [Reflect]
62 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s 62 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s
63 is_reflect = 'Reflect' in extended_attributes 63 is_reflect = 'Reflect' in extended_attributes
64 if is_custom_element_callbacks or is_reflect: 64 if is_custom_element_callbacks or is_reflect:
65 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') 65 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
66 # [PerWorldBindings] 66 # [PerWorldBindings]
67 if 'PerWorldBindings' in extended_attributes: 67 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) 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)
69 # [RaisesException], [RaisesException=Setter]
70 is_setter_raises_exception = (
71 'RaisesException' in extended_attributes and
72 extended_attributes['RaisesException'] in [None, 'Setter'])
73 # [TypeChecking] 69 # [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 = ( 70 has_type_checking_nullable = (
79 (has_extended_attribute_value(interface, 'TypeChecking', 'Nullable') or 71 (has_extended_attribute_value(interface, 'TypeChecking', 'Nullable') or
80 has_extended_attribute_value(attribute, 'TypeChecking', 'Nullable')) an d 72 has_extended_attribute_value(attribute, 'TypeChecking', 'Nullable')) an d
81 idl_type.is_wrapper_type) 73 idl_type.is_wrapper_type)
82 has_type_checking_unrestricted = ( 74 has_type_checking_unrestricted = (
83 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or 75 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or
84 has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted') ) and 76 has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted') ) and
85 idl_type.name in ('Float', 'Double')) 77 idl_type.name in ('Float', 'Double'))
86 78
87 if (base_idl_type == 'EventHandler' and 79 if (base_idl_type == 'EventHandler' and
(...skipping 11 matching lines...) Expand all
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_value_to_v8_value': idl_type.cpp_value_to_v8_value(cpp_value='origi nal', creation_context='info.Holder()'),
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 'has_custom_getter': has_custom_getter,
108 'has_custom_setter': has_custom_setter, 100 'has_custom_setter': has_custom_setter,
109 'has_setter_exception_state':
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.may_raise_exception_on_conversion,
113 'has_type_checking_interface': has_type_checking_interface,
114 'has_type_checking_nullable': has_type_checking_nullable, 101 'has_type_checking_nullable': has_type_checking_nullable,
115 'has_type_checking_unrestricted': has_type_checking_unrestricted, 102 'has_type_checking_unrestricted': has_type_checking_unrestricted,
116 '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
117 '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'),
118 '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'),
119 'is_check_security_for_node': is_check_security_for_node, 106 'is_check_security_for_node': is_check_security_for_node,
120 'is_custom_element_callbacks': is_custom_element_callbacks, 107 'is_custom_element_callbacks': is_custom_element_callbacks,
121 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 108 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes,
122 'is_getter_raises_exception': # [RaisesException] 109 'is_getter_raises_exception': # [RaisesException]
123 'RaisesException' in extended_attributes and 110 'RaisesException' in extended_attributes and
124 extended_attributes['RaisesException'] in (None, 'Getter'), 111 extended_attributes['RaisesException'] in (None, 'Getter'),
125 'is_initialized_by_event_constructor': 112 'is_initialized_by_event_constructor':
126 'InitializedByEventConstructor' in extended_attributes, 113 'InitializedByEventConstructor' in extended_attributes,
127 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), 114 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute),
128 'is_nullable': attribute.idl_type.is_nullable, 115 'is_nullable': attribute.idl_type.is_nullable,
129 'is_partial_interface_member': 116 'is_partial_interface_member':
130 'PartialInterfaceImplementedAs' in extended_attributes, 117 'PartialInterfaceImplementedAs' in extended_attributes,
131 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 118 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
132 'is_read_only': attribute.is_read_only, 119 'is_read_only': attribute.is_read_only,
133 'is_reflect': is_reflect, 120 'is_reflect': is_reflect,
134 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 121 'is_replaceable': 'Replaceable' in attribute.extended_attributes,
135 'is_setter_call_with_execution_context': v8_utilities.has_extended_attri bute_value(attribute, 'SetterCallWith', 'ExecutionContext'),
136 'is_setter_raises_exception': is_setter_raises_exception,
137 'is_static': attribute.is_static, 122 'is_static': attribute.is_static,
138 'is_url': 'URL' in extended_attributes, 123 'is_url': 'URL' in extended_attributes,
139 'is_unforgeable': 'Unforgeable' in extended_attributes, 124 'is_unforgeable': 'Unforgeable' in extended_attributes,
140 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 125 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs]
141 'name': attribute.name, 126 'name': attribute.name,
142 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(attribute), # [PerContextEnabled] 127 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(attribute), # [PerContextEnabled]
143 'property_attributes': property_attributes(attribute), 128 'property_attributes': property_attributes(attribute),
144 'put_forwards': 'PutForwards' in extended_attributes, 129 'put_forwards': 'PutForwards' in extended_attributes,
145 'reflect_empty': extended_attributes.get('ReflectEmpty'), 130 'reflect_empty': extended_attributes.get('ReflectEmpty'),
146 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), 131 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 # FIXME: Remove these hard-coded hacks. 260 # FIXME: Remove these hard-coded hacks.
276 base_idl_type in ['EventTarget', 'Window'] or 261 base_idl_type in ['EventTarget', 'Window'] or
277 base_idl_type.startswith(('HTML', 'SVG'))))) 262 base_idl_type.startswith(('HTML', 'SVG')))))
278 263
279 264
280 ################################################################################ 265 ################################################################################
281 # Setter 266 # Setter
282 ################################################################################ 267 ################################################################################
283 268
284 def setter_context(interface, attribute, context): 269 def setter_context(interface, attribute, context):
285 def target_attribute(): 270 if 'PutForwards' in attribute.extended_attributes:
271 # Use target interface and attribute in place of original interface and
272 # attribute from this point onwards.
286 target_interface_name = attribute.idl_type.base_type 273 target_interface_name = attribute.idl_type.base_type
287 target_attribute_name = extended_attributes['PutForwards'] 274 target_attribute_name = attribute.extended_attributes['PutForwards']
288 target_interface = interfaces[target_interface_name] 275 interface = interfaces[target_interface_name]
289 try: 276 try:
290 return next(attribute 277 attribute = next(candidate
291 for attribute in target_interface.attributes 278 for candidate in interface.attributes
292 if attribute.name == target_attribute_name) 279 if candidate.name == target_attribute_name)
293 except StopIteration: 280 except StopIteration:
294 raise Exception('[PutForward] target not found:\n' 281 raise Exception('[PutForward] target not found:\n'
295 'Attribute "%s" is not present in interface "%s"' % 282 'Attribute "%s" is not present in interface "%s"' %
296 (target_attribute_name, target_interface_name)) 283 (target_attribute_name, target_interface_name))
297 284
298 extended_attributes = attribute.extended_attributes 285 extended_attributes = attribute.extended_attributes
286 idl_type = attribute.idl_type
299 287
300 if 'PutForwards' in extended_attributes: 288 # [RaisesException], [RaisesException=Setter]
301 # Use target attribute in place of original attribute 289 is_setter_raises_exception = (
302 attribute = target_attribute() 290 'RaisesException' in extended_attributes and
291 extended_attributes['RaisesException'] in [None, 'Setter'])
292 # [TypeChecking=Interface]
293 has_type_checking_interface = (
294 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or
295 has_extended_attribute_value(attribute, 'TypeChecking', 'Interface')) a nd
296 idl_type.is_wrapper_type)
303 297
304 context.update({ 298 context.update({
305 'cpp_setter': setter_expression(interface, attribute, context), 299 'has_setter_exception_state':
306 'v8_value_to_local_cpp_value': attribute.idl_type.v8_value_to_local_cpp_ value(extended_attributes, 'v8Value', 'cppValue'), 300 is_setter_raises_exception or has_type_checking_interface or
301 context['has_type_checking_nullable'] or
302 context['has_type_checking_unrestricted'] or
303 idl_type.may_raise_exception_on_conversion,
304 'has_type_checking_interface': has_type_checking_interface,
305 'is_setter_call_with_execution_context': v8_utilities.has_extended_attri bute_value(
306 attribute, 'SetterCallWith', 'ExecutionContext'),
307 'is_setter_raises_exception': is_setter_raises_exception,
308 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value(
309 extended_attributes, 'v8Value', 'cppValue'),
307 }) 310 })
308 311
312 # setter_expression() depends on context values we set above.
313 context['cpp_setter'] = setter_expression(interface, attribute, context)
haraken 2014/06/26 12:02:24 Shall we put this into the above context.update()
Jens Widell 2014/06/26 12:11:47 setter_expression() uses context['is_setter_raises
314
309 315
310 def setter_expression(interface, attribute, context): 316 def setter_expression(interface, attribute, context):
311 extended_attributes = attribute.extended_attributes 317 extended_attributes = attribute.extended_attributes
312 arguments = v8_utilities.call_with_arguments( 318 arguments = v8_utilities.call_with_arguments(
313 extended_attributes.get('SetterCallWith') or 319 extended_attributes.get('SetterCallWith') or
314 extended_attributes.get('CallWith')) 320 extended_attributes.get('CallWith'))
315 321
316 this_setter_base_name = setter_base_name(interface, attribute, arguments) 322 this_setter_base_name = setter_base_name(interface, attribute, arguments)
317 setter_name = scoped_name(interface, attribute, this_setter_base_name) 323 setter_name = scoped_name(interface, attribute, this_setter_base_name)
318 324
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 lambda self: strip_suffix(self.base_type, 'Constructor')) 431 lambda self: strip_suffix(self.base_type, 'Constructor'))
426 432
427 433
428 def is_constructor_attribute(attribute): 434 def is_constructor_attribute(attribute):
429 # FIXME: replace this with [ConstructorAttribute] extended attribute 435 # FIXME: replace this with [ConstructorAttribute] extended attribute
430 return attribute.idl_type.base_type.endswith('Constructor') 436 return attribute.idl_type.base_type.endswith('Constructor')
431 437
432 438
433 def constructor_getter_context(interface, attribute, context): 439 def constructor_getter_context(interface, attribute, context):
434 context['needs_constructor_getter_callback'] = context['measure_as'] or cont ext['deprecate_as'] 440 context['needs_constructor_getter_callback'] = context['measure_as'] or cont ext['deprecate_as']
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/tests/idls/TestNode.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698