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

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

Issue 68733006: IDL compiler: Refactor attribute configuration from Python CG to Jinja template (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revised Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/scripts/unstable/v8_interface.py » ('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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 interface.name in ['Window', 'WorkerGlobalScope'] and 73 interface.name in ['Window', 'WorkerGlobalScope'] and
74 attribute.name == 'onerror'): 74 attribute.name == 'onerror'):
75 includes.add('bindings/v8/V8ErrorHandler.h') 75 includes.add('bindings/v8/V8ErrorHandler.h')
76 76
77 contents = { 77 contents = {
78 'access_control_list': access_control_list(attribute), 78 'access_control_list': access_control_list(attribute),
79 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_ world_list(attribute, 'Getter'), # [ActivityLogging] 79 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_ world_list(attribute, 'Getter'), # [ActivityLogging]
80 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_ world_list(attribute, 'Setter'), # [ActivityLogging] 80 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_ world_list(attribute, 'Setter'), # [ActivityLogging]
81 'cached_attribute_validation_method': extended_attributes.get('CachedAtt ribute'), 81 'cached_attribute_validation_method': extended_attributes.get('CachedAtt ribute'),
82 'conditional_string': v8_utilities.conditional_string(attribute), 82 'conditional_string': v8_utilities.conditional_string(attribute),
83 'constructor_type': v8_types.constructor_type(idl_type) if is_constructo r_attribute(attribute) else None,
83 'cpp_type': v8_types.cpp_type(idl_type), 84 'cpp_type': v8_types.cpp_type(idl_type),
84 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 85 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs]
85 'enum_validation_expression': 86 'enum_validation_expression':
86 v8_utilities.enum_validation_expression(idl_type), 87 v8_utilities.enum_validation_expression(idl_type),
87 'getter_callback_name': getter_callback_name(interface, attribute),
88 'getter_callback_name_for_main_world':
89 getter_callback_name_for_main_world(interface, attribute),
90 'has_custom_getter': has_custom_getter, 88 'has_custom_getter': has_custom_getter,
91 'has_custom_setter': has_custom_setter, 89 'has_custom_setter': has_custom_setter,
92 'has_strict_type_checking': ( 90 'has_strict_type_checking': (
93 'StrictTypeChecking' in extended_attributes and 91 'StrictTypeChecking' in extended_attributes and
94 v8_types.is_interface_type(idl_type)), 92 v8_types.is_interface_type(idl_type)),
95 'idl_type': idl_type, 93 'idl_type': idl_type,
96 'is_call_with_execution_context': v8_utilities.has_extended_attribute_va lue(attribute, 'CallWith', 'ExecutionContext'), 94 'is_call_with_execution_context': v8_utilities.has_extended_attribute_va lue(attribute, 'CallWith', 'ExecutionContext'),
97 'is_check_security_for_node': is_check_security_for_node, 95 'is_check_security_for_node': is_check_security_for_node,
98 'is_constructor': is_constructor_attribute(attribute),
99 'is_getter_raises_exception': ( 96 'is_getter_raises_exception': (
100 'RaisesException' in extended_attributes and 97 'RaisesException' in extended_attributes and
101 extended_attributes['RaisesException'] in [None, 'Getter']), 98 extended_attributes['RaisesException'] in [None, 'Getter']),
102 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), 99 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute),
103 'is_nullable': attribute.is_nullable, 100 'is_nullable': attribute.is_nullable,
101 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
104 'is_read_only': attribute.is_read_only, 102 'is_read_only': attribute.is_read_only,
105 'is_reflect': is_reflect, 103 'is_reflect': is_reflect,
106 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 104 'is_replaceable': 'Replaceable' in attribute.extended_attributes,
107 'is_setter_raises_exception': ( 105 'is_setter_raises_exception': (
108 'RaisesException' in extended_attributes and 106 'RaisesException' in extended_attributes and
109 extended_attributes['RaisesException'] in [None, 'Setter']), 107 extended_attributes['RaisesException'] in [None, 'Setter']),
110 'is_static': attribute.is_static, 108 'is_static': attribute.is_static,
111 'is_unforgeable': 'Unforgeable' in extended_attributes, 109 'is_unforgeable': 'Unforgeable' in extended_attributes,
112 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 110 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs]
113 'name': attribute.name, 111 'name': attribute.name,
114 'per_context_enabled_function_name': v8_utilities.per_context_enabled_fu nction_name(attribute), # [PerContextEnabled] 112 'per_context_enabled_function_name': v8_utilities.per_context_enabled_fu nction_name(attribute), # [PerContextEnabled]
115 'property_attributes': property_attributes(attribute), 113 'property_attributes': property_attributes(attribute),
116 'setter_callback_name': setter_callback_name(interface, attribute), 114 'setter_callback_name': setter_callback_name(interface, attribute),
117 'setter_callback_name_for_main_world': setter_callback_name_for_main_wor ld(interface, attribute),
118 'v8_type': v8_types.v8_type(idl_type), 115 'v8_type': v8_types.v8_type(idl_type),
119 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_n ame(attribute), # [RuntimeEnabled] 116 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_n ame(attribute), # [RuntimeEnabled]
120 'world_suffixes': ['', 'ForMainWorld'] 117 'world_suffixes': ['', 'ForMainWorld']
121 if 'PerWorldBindings' in extended_attributes 118 if 'PerWorldBindings' in extended_attributes
122 else [''], # [PerWorldBindings] 119 else [''], # [PerWorldBindings]
123 'wrapper_type_info': wrapper_type_info(attribute),
124 } 120 }
125 121
126 if is_constructor_attribute(attribute): 122 if is_constructor_attribute(attribute):
127 return contents 123 return contents
128 if not has_custom_getter: 124 if not has_custom_getter:
129 generate_getter(interface, attribute, contents) 125 generate_getter(interface, attribute, contents)
130 if not(attribute.is_read_only or has_custom_setter): 126 if not(attribute.is_read_only or has_custom_setter):
131 contents.update({ 127 contents.update({
132 'cpp_setter': setter_expression(interface, attribute, contents), 128 'cpp_setter': setter_expression(interface, attribute, contents),
133 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( 129 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 278
283 279
284 def scoped_name(interface, attribute, base_name): 280 def scoped_name(interface, attribute, base_name):
285 if attribute.is_static: 281 if attribute.is_static:
286 return '%s::%s' % (interface.name, base_name) 282 return '%s::%s' % (interface.name, base_name)
287 return 'imp->%s' % base_name 283 return 'imp->%s' % base_name
288 284
289 285
290 # Attribute configuration 286 # Attribute configuration
291 287
292 def getter_callback_name(interface, attribute):
293 if is_constructor_attribute(attribute):
294 return '{0}V8Internal::{0}ConstructorGetter'.format(cpp_name(interface))
295 return '%sV8Internal::%sAttributeGetterCallback' % (cpp_name(interface), att ribute.name)
296
297
298 # [Replaceable] 288 # [Replaceable]
299 def setter_callback_name(interface, attribute): 289 def setter_callback_name(interface, attribute):
300 cpp_class_name = cpp_name(interface) 290 cpp_class_name = cpp_name(interface)
301 if ('Replaceable' in attribute.extended_attributes or 291 if ('Replaceable' in attribute.extended_attributes or
302 is_constructor_attribute(attribute)): 292 is_constructor_attribute(attribute)):
303 # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors 293 # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors
304 return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp _class_name) 294 return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp _class_name)
305 # FIXME: support [PutForwards] 295 # FIXME: support [PutForwards]
306 if attribute.is_read_only: 296 if attribute.is_read_only:
307 return '0' 297 return '0'
308 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut e.name) 298 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut e.name)
309 299
310 300
311 # [PerWorldBindings]
312 def getter_callback_name_for_main_world(interface, attribute):
313 if 'PerWorldBindings' not in attribute.extended_attributes:
314 return '0'
315 return '%sV8Internal::%sAttributeGetterCallbackForMainWorld' % (cpp_name(int erface), attribute.name)
316
317
318 def setter_callback_name_for_main_world(interface, attribute):
319 if ('PerWorldBindings' not in attribute.extended_attributes or
320 attribute.is_read_only):
321 return '0'
322 return '%sV8Internal::%sAttributeSetterCallbackForMainWorld' % (cpp_name(int erface), attribute.name)
323
324
325 def wrapper_type_info(attribute):
326 if not is_constructor_attribute(attribute):
327 return '0'
328 return 'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' % v8_types.con structor_type(attribute.idl_type)
329
330
331 # [DoNotCheckSecurity], [Unforgeable] 301 # [DoNotCheckSecurity], [Unforgeable]
332 def access_control_list(attribute): 302 def access_control_list(attribute):
333 extended_attributes = attribute.extended_attributes 303 extended_attributes = attribute.extended_attributes
334 access_control = [] 304 access_control = []
335 if 'DoNotCheckSecurity' in extended_attributes: 305 if 'DoNotCheckSecurity' in extended_attributes:
336 do_not_check_security = extended_attributes['DoNotCheckSecurity'] 306 do_not_check_security = extended_attributes['DoNotCheckSecurity']
337 if do_not_check_security == 'Getter': 307 if do_not_check_security == 'Getter':
338 access_control.append('v8::ALL_CAN_READ') 308 access_control.append('v8::ALL_CAN_READ')
339 elif do_not_check_security == 'Setter': 309 elif do_not_check_security == 'Setter':
340 access_control.append('v8::ALL_CAN_WRITE') 310 access_control.append('v8::ALL_CAN_WRITE')
(...skipping 13 matching lines...) Expand all
354 if ('NotEnumerable' in extended_attributes or 324 if ('NotEnumerable' in extended_attributes or
355 is_constructor_attribute(attribute)): 325 is_constructor_attribute(attribute)):
356 property_attributes_list.append('v8::DontEnum') 326 property_attributes_list.append('v8::DontEnum')
357 if 'Unforgeable' in extended_attributes: 327 if 'Unforgeable' in extended_attributes:
358 property_attributes_list.append('v8::DontDelete') 328 property_attributes_list.append('v8::DontDelete')
359 return property_attributes_list or ['v8::None'] 329 return property_attributes_list or ['v8::None']
360 330
361 331
362 def is_constructor_attribute(attribute): 332 def is_constructor_attribute(attribute):
363 return attribute.idl_type.endswith('Constructor') 333 return attribute.idl_type.endswith('Constructor')
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/unstable/v8_interface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698