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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 idl_type = attribute.idl_type | 48 idl_type = attribute.idl_type |
49 base_idl_type = idl_type.base_type | 49 base_idl_type = idl_type.base_type |
50 extended_attributes = attribute.extended_attributes | 50 extended_attributes = attribute.extended_attributes |
51 | 51 |
52 idl_type.add_includes_for_type(extended_attributes) | 52 idl_type.add_includes_for_type(extended_attributes) |
53 if idl_type.enum_values: | 53 if idl_type.enum_values: |
54 includes.add('core/inspector/ConsoleMessage.h') | 54 includes.add('core/inspector/ConsoleMessage.h') |
55 | 55 |
56 # [CheckSecurity] | 56 # [CheckSecurity] |
57 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes | 57 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes |
58 is_check_security_for_frame = ( | 58 is_check_security_for_receiver = ( |
59 has_extended_attribute_value(interface, 'CheckSecurity', 'Frame') and | 59 has_extended_attribute_value(interface, 'CheckSecurity', 'Receiver') and |
60 not is_do_not_check_security) | 60 not is_do_not_check_security) |
61 is_check_security_for_node = ( | 61 is_check_security_for_return_value = ( |
62 has_extended_attribute_value(attribute, 'CheckSecurity', 'Node')) | 62 has_extended_attribute_value(attribute, 'CheckSecurity', 'ReturnValue')) |
63 is_check_security_for_window = ( | 63 if is_check_security_for_receiver or is_check_security_for_return_value: |
64 has_extended_attribute_value(interface, 'CheckSecurity', 'Window') and | |
65 not is_do_not_check_security) | |
66 if is_check_security_for_frame or is_check_security_for_node or is_check_sec
urity_for_window: | |
67 includes.add('bindings/core/v8/BindingSecurity.h') | 64 includes.add('bindings/core/v8/BindingSecurity.h') |
| 65 # [Constructor] |
| 66 # TODO(yukishiino): Constructors are much like methods although constructors |
| 67 # are not methods. Constructors must be data-type properties, and we can |
| 68 # support them as a kind of methods. |
| 69 constructor_type = idl_type.constructor_type_name if is_constructor_attribut
e(attribute) else None |
68 # [CustomElementCallbacks], [Reflect] | 70 # [CustomElementCallbacks], [Reflect] |
69 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s | 71 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s |
70 is_reflect = 'Reflect' in extended_attributes | 72 is_reflect = 'Reflect' in extended_attributes |
71 if is_custom_element_callbacks or is_reflect: | 73 if is_custom_element_callbacks or is_reflect: |
72 includes.add('core/dom/custom/CustomElementProcessingStack.h') | 74 includes.add('core/dom/custom/CustomElementProcessingStack.h') |
73 # [ImplementedInPrivateScript] | 75 # [ImplementedInPrivateScript] |
74 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes | 76 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes |
75 if is_implemented_in_private_script: | 77 if is_implemented_in_private_script: |
76 includes.add('bindings/core/v8/PrivateScriptRunner.h') | 78 includes.add('bindings/core/v8/PrivateScriptRunner.h') |
77 includes.add('core/frame/LocalFrame.h') | 79 includes.add('core/frame/LocalFrame.h') |
78 includes.add('platform/ScriptForbiddenScope.h') | 80 includes.add('platform/ScriptForbiddenScope.h') |
79 # [OnlyExposedToPrivateScript] | 81 # [OnlyExposedToPrivateScript] |
80 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended
_attributes | 82 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended
_attributes |
81 # [PerWorldBindings] | 83 # [PerWorldBindings] |
82 if 'PerWorldBindings' in extended_attributes: | 84 if 'PerWorldBindings' in extended_attributes: |
83 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) | 85 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) |
84 | 86 |
85 if (base_idl_type == 'EventHandler' and | 87 if (base_idl_type == 'EventHandler' and |
86 interface.name in ['Window', 'WorkerGlobalScope'] and | 88 interface.name in ['Window', 'WorkerGlobalScope'] and |
87 attribute.name == 'onerror'): | 89 attribute.name == 'onerror'): |
88 includes.add('bindings/core/v8/V8ErrorHandler.h') | 90 includes.add('bindings/core/v8/V8ErrorHandler.h') |
89 | 91 |
90 cached_attribute_validation_method = extended_attributes.get('CachedAttribut
e') | 92 cached_attribute_validation_method = extended_attributes.get('CachedAttribut
e') |
91 keep_alive_for_gc = is_keep_alive_for_gc(interface, attribute) | 93 keep_alive_for_gc = is_keep_alive_for_gc(interface, attribute) |
92 if cached_attribute_validation_method or keep_alive_for_gc: | 94 if cached_attribute_validation_method or keep_alive_for_gc: |
93 includes.add('bindings/core/v8/V8HiddenValue.h') | 95 includes.add('bindings/core/v8/V8HiddenValue.h') |
94 | 96 |
| 97 if 'RuntimeEnabled' in extended_attributes: |
| 98 includes.add('platform/RuntimeEnabledFeatures.h') |
| 99 |
| 100 if 'OriginTrialEnabled' in extended_attributes: |
| 101 includes.add('core/inspector/ConsoleMessage.h') |
| 102 includes.add('core/origin_trials/OriginTrials.h') |
| 103 |
95 context = { | 104 context = { |
96 'access_control_list': access_control_list(interface, attribute), | 105 'access_control_list': access_control_list(interface, attribute), |
97 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_
world_list(attribute, 'Getter'), # [ActivityLogging] | 106 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_
world_list(attribute, 'Getter'), # [ActivityLogging] |
98 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_
world_list(attribute, 'Setter'), # [ActivityLogging] | 107 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_
world_list(attribute, 'Setter'), # [ActivityLogging] |
99 'activity_logging_world_check': v8_utilities.activity_logging_world_chec
k(attribute), # [ActivityLogging] | 108 'activity_logging_world_check': v8_utilities.activity_logging_world_chec
k(attribute), # [ActivityLogging] |
100 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 109 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
101 'cached_attribute_validation_method': cached_attribute_validation_method
, | 110 'cached_attribute_validation_method': cached_attribute_validation_method
, |
102 'conditional_string': v8_utilities.conditional_string(attribute), | 111 'constructor_type': constructor_type, |
103 'constructor_type': idl_type.constructor_type_name | |
104 if is_constructor_attribute(attribute) else None, | |
105 'cpp_name': cpp_name(attribute), | 112 'cpp_name': cpp_name(attribute), |
106 'cpp_type': idl_type.cpp_type, | 113 'cpp_type': idl_type.cpp_type, |
107 'cpp_type_initializer': idl_type.cpp_type_initializer, | 114 'cpp_type_initializer': idl_type.cpp_type_initializer, |
108 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] | 115 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] |
109 'enum_type': idl_type.enum_type, | 116 'enum_type': idl_type.enum_type, |
110 'enum_values': idl_type.enum_values, | 117 'enum_values': idl_type.enum_values, |
111 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] | 118 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] |
112 'has_custom_getter': has_custom_getter(attribute), | 119 'has_custom_getter': has_custom_getter(attribute), |
113 'has_custom_setter': has_custom_setter(attribute), | 120 'has_custom_setter': has_custom_setter(attribute), |
114 'has_setter': has_setter(attribute), | 121 'has_setter': has_setter(attribute), |
115 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::
ConversionContext::setConversionType | 122 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::
ConversionContext::setConversionType |
| 123 'is_origin_trial_enabled': v8_utilities.origin_trial_enabled_function(at
tribute) or v8_utilities.origin_trial_enabled_function(interface), # [OriginTri
alEnabled] |
116 'is_call_with_execution_context': has_extended_attribute_value(attribute
, 'CallWith', 'ExecutionContext'), | 124 'is_call_with_execution_context': has_extended_attribute_value(attribute
, 'CallWith', 'ExecutionContext'), |
117 'is_call_with_script_state': has_extended_attribute_value(attribute, 'Ca
llWith', 'ScriptState'), | 125 'is_call_with_script_state': has_extended_attribute_value(attribute, 'Ca
llWith', 'ScriptState'), |
118 'is_check_security_for_frame': is_check_security_for_frame, | 126 'is_check_security_for_receiver': is_check_security_for_receiver, |
119 'is_check_security_for_node': is_check_security_for_node, | 127 'is_check_security_for_return_value': is_check_security_for_return_value
, |
120 'is_check_security_for_window': is_check_security_for_window, | |
121 'is_custom_element_callbacks': is_custom_element_callbacks, | 128 'is_custom_element_callbacks': is_custom_element_callbacks, |
122 'is_expose_js_accessors': is_expose_js_accessors(interface, attribute), | 129 # TODO(yukishiino): Make all DOM attributes accessor-type properties. |
| 130 'is_data_type_property': constructor_type or interface.name == 'Window'
or interface.name == 'Location', |
123 'is_getter_raises_exception': # [RaisesException] | 131 'is_getter_raises_exception': # [RaisesException] |
124 'RaisesException' in extended_attributes and | 132 'RaisesException' in extended_attributes and |
125 extended_attributes['RaisesException'] in (None, 'Getter'), | 133 extended_attributes['RaisesException'] in (None, 'Getter'), |
126 'is_implemented_in_private_script': is_implemented_in_private_script, | 134 'is_implemented_in_private_script': is_implemented_in_private_script, |
127 'is_keep_alive_for_gc': keep_alive_for_gc, | 135 'is_keep_alive_for_gc': keep_alive_for_gc, |
128 'is_lenient_this': 'LenientThis' in extended_attributes, | 136 'is_lenient_this': 'LenientThis' in extended_attributes, |
129 'is_nullable': idl_type.is_nullable, | 137 'is_nullable': idl_type.is_nullable, |
130 'is_explicit_nullable': idl_type.is_explicit_nullable, | 138 'is_explicit_nullable': idl_type.is_explicit_nullable, |
131 'is_partial_interface_member': | 139 'is_partial_interface_member': |
132 'PartialInterfaceImplementedAs' in extended_attributes, | 140 'PartialInterfaceImplementedAs' in extended_attributes, |
133 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, | 141 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, |
134 'is_put_forwards': 'PutForwards' in extended_attributes, | 142 'is_put_forwards': 'PutForwards' in extended_attributes, |
135 'is_read_only': attribute.is_read_only, | 143 'is_read_only': attribute.is_read_only, |
136 'is_reflect': is_reflect, | 144 'is_reflect': is_reflect, |
137 'is_replaceable': 'Replaceable' in attribute.extended_attributes, | 145 'is_replaceable': 'Replaceable' in attribute.extended_attributes, |
138 'is_static': attribute.is_static, | 146 'is_static': attribute.is_static, |
139 'is_url': 'URL' in extended_attributes, | 147 'is_url': 'URL' in extended_attributes, |
140 'is_unforgeable': is_unforgeable(interface, attribute), | 148 'is_unforgeable': is_unforgeable(interface, attribute), |
141 'on_instance': v8_utilities.on_instance(interface, attribute), | 149 'on_instance': v8_utilities.on_instance(interface, attribute), |
142 'on_interface': v8_utilities.on_interface(interface, attribute), | 150 'on_interface': v8_utilities.on_interface(interface, attribute), |
143 'on_prototype': v8_utilities.on_prototype(interface, attribute), | 151 'on_prototype': v8_utilities.on_prototype(interface, attribute), |
| 152 'origin_trial_enabled': v8_utilities.origin_trial_enabled_function(attri
bute), # [OriginTrialEnabled] |
| 153 'origin_trial_enabled_per_interface': v8_utilities.origin_trial_enabled_
function(interface), # [OriginTrialEnabled] |
| 154 'origin_trial_name': extended_attributes.get('OriginTrialEnabled'), # [
OriginTrialEnabled] |
144 'use_output_parameter_for_result': idl_type.use_output_parameter_for_res
ult, | 155 'use_output_parameter_for_result': idl_type.use_output_parameter_for_res
ult, |
145 'measure_as': v8_utilities.measure_as(attribute, interface), # [Measure
As] | 156 'measure_as': v8_utilities.measure_as(attribute, interface), # [Measure
As] |
146 'name': attribute.name, | 157 'name': attribute.name, |
147 'only_exposed_to_private_script': is_only_exposed_to_private_script, | 158 'only_exposed_to_private_script': is_only_exposed_to_private_script, |
148 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local
_cpp_value( | 159 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local
_cpp_value( |
149 extended_attributes, 'v8Value', 'cppValue', bailout_return_value='fa
lse', isolate='scriptState->isolate()'), | 160 extended_attributes, 'v8Value', 'cppValue', bailout_return_value='fa
lse', isolate='scriptState->isolate()'), |
150 'property_attributes': property_attributes(interface, attribute), | 161 'property_attributes': property_attributes(interface, attribute), |
151 'reflect_empty': extended_attributes.get('ReflectEmpty'), | 162 'reflect_empty': extended_attributes.get('ReflectEmpty'), |
152 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), | 163 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), |
153 'reflect_missing': extended_attributes.get('ReflectMissing'), | 164 'reflect_missing': extended_attributes.get('ReflectMissing'), |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 context['cpp_setter'] = '%sCreateDataProperty(propertyName, v8Value, inf
o)' % cpp_name(interface) | 341 context['cpp_setter'] = '%sCreateDataProperty(propertyName, v8Value, inf
o)' % cpp_name(interface) |
331 return | 342 return |
332 | 343 |
333 extended_attributes = attribute.extended_attributes | 344 extended_attributes = attribute.extended_attributes |
334 idl_type = attribute.idl_type | 345 idl_type = attribute.idl_type |
335 | 346 |
336 # [RaisesException], [RaisesException=Setter] | 347 # [RaisesException], [RaisesException=Setter] |
337 is_setter_raises_exception = ( | 348 is_setter_raises_exception = ( |
338 'RaisesException' in extended_attributes and | 349 'RaisesException' in extended_attributes and |
339 extended_attributes['RaisesException'] in [None, 'Setter']) | 350 extended_attributes['RaisesException'] in [None, 'Setter']) |
340 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] | 351 # [LegacyInterfaceTypeChecking] |
341 has_type_checking_interface = ( | 352 has_type_checking_interface = ( |
342 not is_legacy_interface_type_checking(interface, attribute) and | 353 not is_legacy_interface_type_checking(interface, attribute) and |
343 idl_type.is_wrapper_type) | 354 idl_type.is_wrapper_type) |
344 | 355 |
345 context.update({ | 356 context.update({ |
346 'has_setter_exception_state': | 357 'has_setter_exception_state': |
347 is_setter_raises_exception or has_type_checking_interface or | 358 is_setter_raises_exception or has_type_checking_interface or |
348 idl_type.v8_conversion_needs_exception_state, | 359 idl_type.v8_conversion_needs_exception_state, |
349 'has_type_checking_interface': has_type_checking_interface, | 360 'has_type_checking_interface': has_type_checking_interface, |
350 'is_setter_call_with_execution_context': has_extended_attribute_value( | 361 'is_setter_call_with_execution_context': has_extended_attribute_value( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 493 |
483 | 494 |
484 # [Custom], [Custom=Setter] | 495 # [Custom], [Custom=Setter] |
485 def has_custom_setter(attribute): | 496 def has_custom_setter(attribute): |
486 extended_attributes = attribute.extended_attributes | 497 extended_attributes = attribute.extended_attributes |
487 return (not attribute.is_read_only and | 498 return (not attribute.is_read_only and |
488 'Custom' in extended_attributes and | 499 'Custom' in extended_attributes and |
489 extended_attributes['Custom'] in [None, 'Setter']) | 500 extended_attributes['Custom'] in [None, 'Setter']) |
490 | 501 |
491 | 502 |
492 # [ExposeJSAccessors] | |
493 def is_expose_js_accessors(interface, attribute): | |
494 # Default behavior | |
495 is_accessor = True | |
496 | |
497 if ('ExposeJSAccessors' in interface.extended_attributes and | |
498 'DoNotExposeJSAccessors' in interface.extended_attributes): | |
499 raise Exception('Both of ExposeJSAccessors and DoNotExposeJSAccessors ar
e specified at a time in an interface: ' + interface.name) | |
500 if 'ExposeJSAccessors' in interface.extended_attributes: | |
501 is_accessor = True | |
502 if 'DoNotExposeJSAccessors' in interface.extended_attributes: | |
503 is_accessor = False | |
504 | |
505 # Note that ExposeJSAccessors and DoNotExposeJSAccessors are more powerful | |
506 # than 'static', [Unforgeable] and [OverrideBuiltins]. | |
507 if ('ExposeJSAccessors' in attribute.extended_attributes and | |
508 'DoNotExposeJSAccessors' in attribute.extended_attributes): | |
509 raise Exception('Both of ExposeJSAccessors and DoNotExposeJSAccessors ar
e specified at a time on an attribute: ' + attribute.name + ' in an interface: '
+ interface.name) | |
510 if 'ExposeJSAccessors' in attribute.extended_attributes: | |
511 return True | |
512 if 'DoNotExposeJSAccessors' in attribute.extended_attributes: | |
513 return False | |
514 | |
515 # These attributes must not be accessors on prototype chains. | |
516 if (is_constructor_attribute(attribute) or | |
517 attribute.is_static or | |
518 is_unforgeable(interface, attribute) or | |
519 'OverrideBuiltins' in interface.extended_attributes): | |
520 return False | |
521 | |
522 # The members of Window interface must be placed on the instance object. | |
523 if interface.name == 'Window': | |
524 return False | |
525 | |
526 return is_accessor | |
527 | |
528 | |
529 ################################################################################ | 503 ################################################################################ |
530 # Constructors | 504 # Constructors |
531 ################################################################################ | 505 ################################################################################ |
532 | 506 |
533 idl_types.IdlType.constructor_type_name = property( | 507 idl_types.IdlType.constructor_type_name = property( |
534 # FIXME: replace this with a [ConstructorAttribute] extended attribute | 508 # FIXME: replace this with a [ConstructorAttribute] extended attribute |
535 lambda self: strip_suffix(self.base_type, 'Constructor')) | 509 lambda self: strip_suffix(self.base_type, 'Constructor')) |
536 | 510 |
537 | 511 |
538 def is_constructor_attribute(attribute): | 512 def is_constructor_attribute(attribute): |
539 # FIXME: replace this with [ConstructorAttribute] extended attribute | 513 # FIXME: replace this with [ConstructorAttribute] extended attribute |
540 return attribute.idl_type.name.endswith('Constructor') | 514 return attribute.idl_type.name.endswith('Constructor') |
541 | 515 |
542 | 516 |
543 def update_constructor_attribute_context(interface, attribute, context): | 517 def update_constructor_attribute_context(interface, attribute, context): |
544 context['needs_constructor_getter_callback'] = context['measure_as'] or cont
ext['deprecate_as'] | 518 context['needs_constructor_getter_callback'] = context['measure_as'] or cont
ext['deprecate_as'] or context['origin_trial_name'] |
545 # When the attribute name is the same as the interface name, do not generate | 519 # When the attribute name is the same as the interface name, do not generate |
546 # callback functions for each attribute and use | 520 # callback functions for each attribute and use |
547 # {{cpp_class}}ConstructorAttributeSetterCallback. Otherwise, generate | 521 # {{cpp_class}}ConstructorAttributeSetterCallback. Otherwise, generate |
548 # a callback function in order to hard-code the attribute name. | 522 # a callback function in order to hard-code the attribute name. |
549 context['needs_constructor_setter_callback'] = context['name'] != context['c
onstructor_type'] | 523 context['needs_constructor_setter_callback'] = context['name'] != context['c
onstructor_type'] |
OLD | NEW |