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 20 matching lines...) Expand all Loading... |
31 Extends IdlType with property |constructor_type_name|. | 31 Extends IdlType with property |constructor_type_name|. |
32 | 32 |
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
34 """ | 34 """ |
35 | 35 |
36 import idl_types | 36 import idl_types |
37 from idl_types import inherits_interface | 37 from idl_types import inherits_interface |
38 from v8_globals import includes, interfaces | 38 from v8_globals import includes, interfaces |
39 import v8_types | 39 import v8_types |
40 import v8_utilities | 40 import v8_utilities |
41 from v8_utilities import (capitalize, cpp_name, has_extended_attribute, | 41 from v8_utilities import (cpp_name_or_partial, capitalize, cpp_name, has_extende
d_attribute, |
42 has_extended_attribute_value, scoped_name, strip_suffi
x, | 42 has_extended_attribute_value, scoped_name, strip_suffi
x, |
43 uncapitalize, extended_attribute_value_as_list) | 43 uncapitalize, extended_attribute_value_as_list, is_unf
orgeable, |
| 44 is_legacy_interface_type_checking) |
44 | 45 |
45 | 46 |
46 def attribute_context(interface, attribute): | 47 def attribute_context(interface, attribute): |
47 idl_type = attribute.idl_type | 48 idl_type = attribute.idl_type |
48 base_idl_type = idl_type.base_type | 49 base_idl_type = idl_type.base_type |
49 extended_attributes = attribute.extended_attributes | 50 extended_attributes = attribute.extended_attributes |
50 | 51 |
51 idl_type.add_includes_for_type() | 52 idl_type.add_includes_for_type(extended_attributes) |
| 53 if idl_type.enum_values: |
| 54 includes.add('core/inspector/ConsoleMessage.h') |
52 | 55 |
53 # [CheckSecurity] | 56 # [CheckSecurity] |
54 is_check_security_for_node = 'CheckSecurity' in extended_attributes | 57 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes |
55 if is_check_security_for_node: | 58 is_check_security_for_frame = ( |
56 includes.add('bindings/common/BindingSecurity.h') | 59 has_extended_attribute_value(interface, 'CheckSecurity', 'Frame') and |
| 60 not is_do_not_check_security) |
| 61 is_check_security_for_node = ( |
| 62 has_extended_attribute_value(attribute, 'CheckSecurity', 'Node')) |
| 63 is_check_security_for_window = ( |
| 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') |
57 # [CustomElementCallbacks], [Reflect] | 68 # [CustomElementCallbacks], [Reflect] |
58 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s | 69 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s |
59 is_reflect = 'Reflect' in extended_attributes | 70 is_reflect = 'Reflect' in extended_attributes |
60 if is_custom_element_callbacks or is_reflect: | 71 if is_custom_element_callbacks or is_reflect: |
61 includes.add('core/dom/custom/CustomElementProcessingStack.h') | 72 includes.add('core/dom/custom/CustomElementProcessingStack.h') |
62 # [PerWorldBindings] | |
63 if 'PerWorldBindings' in extended_attributes: | |
64 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) | |
65 # [TypeChecking] | |
66 has_type_checking_unrestricted = ( | |
67 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted')
or | |
68 has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')
) and | |
69 idl_type.name in ('Float', 'Double')) | |
70 # [ImplementedInPrivateScript] | 73 # [ImplementedInPrivateScript] |
71 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes | 74 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes |
72 if is_implemented_in_private_script: | 75 if is_implemented_in_private_script: |
73 includes.add('bindings/core/v8/PrivateScriptRunner.h') | 76 includes.add('bindings/core/v8/PrivateScriptRunner.h') |
74 includes.add('core/frame/LocalFrame.h') | 77 includes.add('core/frame/LocalFrame.h') |
75 includes.add('platform/ScriptForbiddenScope.h') | 78 includes.add('platform/ScriptForbiddenScope.h') |
76 | |
77 # [OnlyExposedToPrivateScript] | 79 # [OnlyExposedToPrivateScript] |
78 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended
_attributes | 80 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended
_attributes |
| 81 # [PerWorldBindings] |
| 82 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) |
79 | 84 |
80 if (base_idl_type == 'EventHandler' and | 85 if (base_idl_type == 'EventHandler' and |
81 interface.name in ['Window', 'WorkerGlobalScope'] and | 86 interface.name in ['Window', 'WorkerGlobalScope'] and |
82 attribute.name == 'onerror'): | 87 attribute.name == 'onerror'): |
83 includes.add('bindings/core/v8/V8ErrorHandler.h') | 88 includes.add('bindings/core/v8/V8ErrorHandler.h') |
84 | 89 |
| 90 cached_attribute_validation_method = extended_attributes.get('CachedAttribut
e') |
| 91 keep_alive_for_gc = is_keep_alive_for_gc(interface, attribute) |
| 92 if cached_attribute_validation_method or keep_alive_for_gc: |
| 93 includes.add('bindings/core/v8/V8HiddenValue.h') |
| 94 |
85 context = { | 95 context = { |
86 'access_control_list': access_control_list(attribute), | 96 'access_control_list': access_control_list(interface, attribute), |
87 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_
world_list(attribute, 'Getter'), # [ActivityLogging] | 97 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_
world_list(attribute, 'Getter'), # [ActivityLogging] |
88 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_
world_list(attribute, 'Setter'), # [ActivityLogging] | 98 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_
world_list(attribute, 'Setter'), # [ActivityLogging] |
89 'activity_logging_world_check': v8_utilities.activity_logging_world_chec
k(attribute), # [ActivityLogging] | 99 'activity_logging_world_check': v8_utilities.activity_logging_world_chec
k(attribute), # [ActivityLogging] |
90 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 100 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
91 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), | 101 'cached_attribute_validation_method': cached_attribute_validation_method
, |
92 'conditional_string': v8_utilities.conditional_string(attribute), | 102 'conditional_string': v8_utilities.conditional_string(attribute), |
93 'constructor_type': idl_type.constructor_type_name | 103 'constructor_type': idl_type.constructor_type_name |
94 if is_constructor_attribute(attribute) else None, | 104 if is_constructor_attribute(attribute) else None, |
95 'cpp_name': cpp_name(attribute), | 105 'cpp_name': cpp_name(attribute), |
96 'cpp_type': idl_type.cpp_type, | 106 'cpp_type': idl_type.cpp_type, |
97 'cpp_type_initializer': idl_type.cpp_type_initializer, | 107 'cpp_type_initializer': idl_type.cpp_type_initializer, |
98 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] | 108 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] |
99 'enum_validation_expression': idl_type.enum_validation_expression, | 109 'enum_type': idl_type.enum_type, |
| 110 'enum_values': idl_type.enum_values, |
100 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] | 111 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] |
101 'has_custom_getter': has_custom_getter(attribute), | 112 'has_custom_getter': has_custom_getter(attribute), |
102 'has_custom_setter': has_custom_setter(attribute), | 113 'has_custom_setter': has_custom_setter(attribute), |
103 'has_type_checking_unrestricted': has_type_checking_unrestricted, | 114 'has_setter': has_setter(attribute), |
104 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::
ConversionContext::setConversionType | 115 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::
ConversionContext::setConversionType |
105 'is_call_with_execution_context': v8_utilities.has_extended_attribute_va
lue(attribute, 'CallWith', 'ExecutionContext'), | 116 'is_call_with_execution_context': has_extended_attribute_value(attribute
, 'CallWith', 'ExecutionContext'), |
106 'is_call_with_script_state': v8_utilities.has_extended_attribute_value(a
ttribute, 'CallWith', 'ScriptState'), | 117 'is_call_with_script_state': has_extended_attribute_value(attribute, 'Ca
llWith', 'ScriptState'), |
| 118 'is_check_security_for_frame': is_check_security_for_frame, |
107 'is_check_security_for_node': is_check_security_for_node, | 119 'is_check_security_for_node': is_check_security_for_node, |
| 120 'is_check_security_for_window': is_check_security_for_window, |
108 'is_custom_element_callbacks': is_custom_element_callbacks, | 121 'is_custom_element_callbacks': is_custom_element_callbacks, |
109 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, | 122 'is_expose_js_accessors': is_expose_js_accessors(interface, attribute), |
110 'is_getter_raises_exception': # [RaisesException] | 123 'is_getter_raises_exception': # [RaisesException] |
111 'RaisesException' in extended_attributes and | 124 'RaisesException' in extended_attributes and |
112 extended_attributes['RaisesException'] in (None, 'Getter'), | 125 extended_attributes['RaisesException'] in (None, 'Getter'), |
113 'is_implemented_in_private_script': is_implemented_in_private_script, | 126 'is_implemented_in_private_script': is_implemented_in_private_script, |
114 'is_initialized_by_event_constructor': | 127 'is_keep_alive_for_gc': keep_alive_for_gc, |
115 'InitializedByEventConstructor' in extended_attributes, | 128 'is_lenient_this': 'LenientThis' in extended_attributes, |
116 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), | |
117 'is_nullable': idl_type.is_nullable, | 129 'is_nullable': idl_type.is_nullable, |
118 'is_explicit_nullable': idl_type.is_explicit_nullable, | 130 'is_explicit_nullable': idl_type.is_explicit_nullable, |
119 'is_partial_interface_member': | 131 'is_partial_interface_member': |
120 'PartialInterfaceImplementedAs' in extended_attributes, | 132 'PartialInterfaceImplementedAs' in extended_attributes, |
121 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, | 133 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, |
| 134 'is_put_forwards': 'PutForwards' in extended_attributes, |
122 'is_read_only': attribute.is_read_only, | 135 'is_read_only': attribute.is_read_only, |
123 'is_reflect': is_reflect, | 136 'is_reflect': is_reflect, |
124 'is_replaceable': 'Replaceable' in attribute.extended_attributes, | 137 'is_replaceable': 'Replaceable' in attribute.extended_attributes, |
125 'is_static': attribute.is_static, | 138 'is_static': attribute.is_static, |
126 'is_url': 'URL' in extended_attributes, | 139 'is_url': 'URL' in extended_attributes, |
127 'is_unforgeable': 'Unforgeable' in extended_attributes, | 140 'is_unforgeable': is_unforgeable(interface, attribute), |
128 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] | 141 'on_instance': v8_utilities.on_instance(interface, attribute), |
| 142 'on_interface': v8_utilities.on_interface(interface, attribute), |
| 143 'on_prototype': v8_utilities.on_prototype(interface, attribute), |
| 144 'use_output_parameter_for_result': idl_type.use_output_parameter_for_res
ult, |
| 145 'measure_as': v8_utilities.measure_as(attribute, interface), # [Measure
As] |
129 'name': attribute.name, | 146 'name': attribute.name, |
130 'only_exposed_to_private_script': is_only_exposed_to_private_script, | 147 'only_exposed_to_private_script': is_only_exposed_to_private_script, |
131 'per_context_enabled_function': v8_utilities.per_context_enabled_functio
n_name(attribute), # [PerContextEnabled] | |
132 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local
_cpp_value( | 148 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local
_cpp_value( |
133 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is
olate()', used_in_private_script=True), | 149 extended_attributes, 'v8Value', 'cppValue', bailout_return_value='fa
lse', isolate='scriptState->isolate()'), |
134 'property_attributes': property_attributes(attribute), | 150 'property_attributes': property_attributes(interface, attribute), |
135 'put_forwards': 'PutForwards' in extended_attributes, | |
136 'reflect_empty': extended_attributes.get('ReflectEmpty'), | 151 'reflect_empty': extended_attributes.get('ReflectEmpty'), |
137 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), | 152 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), |
138 'reflect_missing': extended_attributes.get('ReflectMissing'), | 153 'reflect_missing': extended_attributes.get('ReflectMissing'), |
139 'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly
'), | 154 'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly
'), |
140 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(a
ttribute), # [RuntimeEnabled] | 155 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(a
ttribute), # [RuntimeEnabled] |
141 'setter_callback': setter_callback_name(interface, attribute), | |
142 'should_be_exposed_to_script': not (is_implemented_in_private_script and
is_only_exposed_to_private_script), | 156 'should_be_exposed_to_script': not (is_implemented_in_private_script and
is_only_exposed_to_private_script), |
143 'world_suffixes': ['', 'ForMainWorld'] | 157 'world_suffixes': ['', 'ForMainWorld'] |
144 if 'PerWorldBindings' in extended_attributes | 158 if 'PerWorldBindings' in extended_attributes |
145 else [''], # [PerWorldBindings] | 159 else [''], # [PerWorldBindings] |
146 } | 160 } |
147 | 161 |
148 if is_constructor_attribute(attribute): | 162 if is_constructor_attribute(attribute): |
149 constructor_getter_context(interface, attribute, context) | 163 update_constructor_attribute_context(interface, attribute, context) |
150 return context | |
151 if not has_custom_getter(attribute): | 164 if not has_custom_getter(attribute): |
152 getter_context(interface, attribute, context) | 165 getter_context(interface, attribute, context) |
153 if (not has_custom_setter(attribute) and | 166 if not has_custom_setter(attribute) and has_setter(attribute): |
154 (not attribute.is_read_only or 'PutForwards' in extended_attributes)): | |
155 setter_context(interface, attribute, context) | 167 setter_context(interface, attribute, context) |
156 | 168 |
157 return context | 169 return context |
158 | 170 |
159 | 171 |
160 ################################################################################ | 172 ################################################################################ |
161 # Getter | 173 # Getter |
162 ################################################################################ | 174 ################################################################################ |
163 | 175 |
164 def getter_context(interface, attribute, context): | 176 def getter_context(interface, attribute, context): |
(...skipping 26 matching lines...) Expand all Loading... |
191 'ReflectOnly' in extended_attributes or | 203 'ReflectOnly' in extended_attributes or |
192 context['is_keep_alive_for_gc'] or | 204 context['is_keep_alive_for_gc'] or |
193 context['is_getter_raises_exception']): | 205 context['is_getter_raises_exception']): |
194 context['cpp_value_original'] = cpp_value | 206 context['cpp_value_original'] = cpp_value |
195 cpp_value = 'cppValue' | 207 cpp_value = 'cppValue' |
196 # EventHandler has special handling | 208 # EventHandler has special handling |
197 if base_idl_type != 'EventHandler': | 209 if base_idl_type != 'EventHandler': |
198 release = idl_type.release | 210 release = idl_type.release |
199 | 211 |
200 def v8_set_return_value_statement(for_main_world=False): | 212 def v8_set_return_value_statement(for_main_world=False): |
201 if context['is_keep_alive_for_gc']: | 213 if context['is_keep_alive_for_gc'] or 'CachedAttribute' in extended_attr
ibutes: |
202 return 'v8SetReturnValue(info, wrapper)' | 214 return 'v8SetReturnValue(info, v8Value)' |
203 return idl_type.v8_set_return_value(cpp_value, extended_attributes=exten
ded_attributes, script_wrappable='impl', release=release, for_main_world=for_mai
n_world) | 215 return idl_type.v8_set_return_value( |
| 216 cpp_value, extended_attributes=extended_attributes, script_wrappable
='impl', |
| 217 release=release, for_main_world=for_main_world, is_static=attribute.
is_static) |
204 | 218 |
205 context.update({ | 219 context.update({ |
206 'cpp_value': cpp_value, | 220 'cpp_value': cpp_value, |
207 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 221 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
208 cpp_value=cpp_value, creation_context='info.Holder()', | 222 cpp_value=cpp_value, creation_context='holder', |
209 extended_attributes=extended_attributes), | 223 extended_attributes=extended_attributes), |
210 'v8_set_return_value_for_main_world': v8_set_return_value_statement(for_
main_world=True), | 224 'v8_set_return_value_for_main_world': v8_set_return_value_statement(for_
main_world=True), |
211 'v8_set_return_value': v8_set_return_value_statement(), | 225 'v8_set_return_value': v8_set_return_value_statement(), |
212 }) | 226 }) |
213 | 227 |
214 | |
215 def getter_expression(interface, attribute, context): | 228 def getter_expression(interface, attribute, context): |
216 arguments = [] | 229 arguments = [] |
217 this_getter_base_name = getter_base_name(interface, attribute, arguments) | 230 this_getter_base_name = getter_base_name(interface, attribute, arguments) |
218 getter_name = scoped_name(interface, attribute, this_getter_base_name) | 231 getter_name = scoped_name(interface, attribute, this_getter_base_name) |
219 | 232 |
220 if 'ImplementedInPrivateScript' in attribute.extended_attributes: | 233 if 'ImplementedInPrivateScript' in attribute.extended_attributes: |
221 arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentCont
ext())') | 234 arguments.append('toLocalFrame(toFrameIfNotDetached(info.GetIsolate()->G
etCurrentContext()))') |
222 arguments.append('impl') | 235 arguments.append('impl') |
223 arguments.append('&result') | 236 arguments.append('&result') |
224 arguments.extend(v8_utilities.call_with_arguments( | 237 arguments.extend(v8_utilities.call_with_arguments( |
225 attribute.extended_attributes.get('CallWith'))) | 238 attribute.extended_attributes.get('CallWith'))) |
226 # Members of IDL partial interface definitions are implemented in C++ as | 239 # Members of IDL partial interface definitions are implemented in C++ as |
227 # static member functions, which for instance members (non-static members) | 240 # static member functions, which for instance members (non-static members) |
228 # take *impl as their first argument | 241 # take *impl as their first argument |
229 if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and | 242 if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and |
230 not 'ImplementedInPrivateScript' in attribute.extended_attributes and | 243 not 'ImplementedInPrivateScript' in attribute.extended_attributes and |
231 not attribute.is_static): | 244 not attribute.is_static): |
232 arguments.append('*impl') | 245 arguments.append('*impl') |
233 if attribute.idl_type.is_explicit_nullable: | 246 if attribute.idl_type.is_explicit_nullable: |
234 arguments.append('isNull') | 247 arguments.append('isNull') |
235 if context['is_getter_raises_exception']: | 248 if context['is_getter_raises_exception']: |
236 arguments.append('exceptionState') | 249 arguments.append('exceptionState') |
| 250 if attribute.idl_type.use_output_parameter_for_result: |
| 251 arguments.append('result') |
237 return '%s(%s)' % (getter_name, ', '.join(arguments)) | 252 return '%s(%s)' % (getter_name, ', '.join(arguments)) |
238 | 253 |
239 | 254 |
240 CONTENT_ATTRIBUTE_GETTER_NAMES = { | 255 CONTENT_ATTRIBUTE_GETTER_NAMES = { |
241 'boolean': 'fastHasAttribute', | 256 'boolean': 'fastHasAttribute', |
242 'long': 'getIntegralAttribute', | 257 'long': 'getIntegralAttribute', |
243 'unsigned long': 'getUnsignedIntegralAttribute', | 258 'unsigned long': 'getUnsignedIntegralAttribute', |
244 } | 259 } |
245 | 260 |
246 | 261 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 interface = interfaces[target_interface_name] | 318 interface = interfaces[target_interface_name] |
304 try: | 319 try: |
305 attribute = next(candidate | 320 attribute = next(candidate |
306 for candidate in interface.attributes | 321 for candidate in interface.attributes |
307 if candidate.name == target_attribute_name) | 322 if candidate.name == target_attribute_name) |
308 except StopIteration: | 323 except StopIteration: |
309 raise Exception('[PutForward] target not found:\n' | 324 raise Exception('[PutForward] target not found:\n' |
310 'Attribute "%s" is not present in interface "%s"' % | 325 'Attribute "%s" is not present in interface "%s"' % |
311 (target_attribute_name, target_interface_name)) | 326 (target_attribute_name, target_interface_name)) |
312 | 327 |
| 328 if ('Replaceable' in attribute.extended_attributes or |
| 329 is_constructor_attribute(attribute)): |
| 330 context['cpp_setter'] = '%sCreateDataProperty(propertyName, v8Value, inf
o)' % cpp_name(interface) |
| 331 return |
| 332 |
313 extended_attributes = attribute.extended_attributes | 333 extended_attributes = attribute.extended_attributes |
314 idl_type = attribute.idl_type | 334 idl_type = attribute.idl_type |
315 | 335 |
316 # [RaisesException], [RaisesException=Setter] | 336 # [RaisesException], [RaisesException=Setter] |
317 is_setter_raises_exception = ( | 337 is_setter_raises_exception = ( |
318 'RaisesException' in extended_attributes and | 338 'RaisesException' in extended_attributes and |
319 extended_attributes['RaisesException'] in [None, 'Setter']) | 339 extended_attributes['RaisesException'] in [None, 'Setter']) |
320 # [TypeChecking=Interface] | 340 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] |
321 has_type_checking_interface = ( | 341 has_type_checking_interface = ( |
322 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or | 342 not is_legacy_interface_type_checking(interface, attribute) and |
323 has_extended_attribute_value(attribute, 'TypeChecking', 'Interface')) a
nd | |
324 idl_type.is_wrapper_type) | 343 idl_type.is_wrapper_type) |
325 | 344 |
326 context.update({ | 345 context.update({ |
327 'has_setter_exception_state': | 346 'has_setter_exception_state': |
328 is_setter_raises_exception or has_type_checking_interface or | 347 is_setter_raises_exception or has_type_checking_interface or |
329 context['has_type_checking_unrestricted'] or | |
330 idl_type.v8_conversion_needs_exception_state, | 348 idl_type.v8_conversion_needs_exception_state, |
331 'has_type_checking_interface': has_type_checking_interface, | 349 'has_type_checking_interface': has_type_checking_interface, |
332 'is_setter_call_with_execution_context': v8_utilities.has_extended_attri
bute_value( | 350 'is_setter_call_with_execution_context': has_extended_attribute_value( |
333 attribute, 'SetterCallWith', 'ExecutionContext'), | 351 attribute, 'SetterCallWith', 'ExecutionContext'), |
334 'is_setter_raises_exception': is_setter_raises_exception, | 352 'is_setter_raises_exception': is_setter_raises_exception, |
335 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 353 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
336 'cppValue', isolate='scriptState->isolate()', | 354 'cppValue', isolate='scriptState->isolate()', |
337 creation_context='scriptState->context()->Global()'), | 355 creation_context='scriptState->context()->Global()'), |
338 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( | 356 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( |
339 extended_attributes, 'v8Value', 'cppValue'), | 357 extended_attributes, 'v8Value', 'cppValue'), |
340 }) | 358 }) |
341 | 359 |
342 # setter_expression() depends on context values we set above. | 360 # setter_expression() depends on context values we set above. |
(...skipping 11 matching lines...) Expand all Loading... |
354 | 372 |
355 # Members of IDL partial interface definitions are implemented in C++ as | 373 # Members of IDL partial interface definitions are implemented in C++ as |
356 # static member functions, which for instance members (non-static members) | 374 # static member functions, which for instance members (non-static members) |
357 # take *impl as their first argument | 375 # take *impl as their first argument |
358 if ('PartialInterfaceImplementedAs' in extended_attributes and | 376 if ('PartialInterfaceImplementedAs' in extended_attributes and |
359 not 'ImplementedInPrivateScript' in extended_attributes and | 377 not 'ImplementedInPrivateScript' in extended_attributes and |
360 not attribute.is_static): | 378 not attribute.is_static): |
361 arguments.append('*impl') | 379 arguments.append('*impl') |
362 idl_type = attribute.idl_type | 380 idl_type = attribute.idl_type |
363 if 'ImplementedInPrivateScript' in extended_attributes: | 381 if 'ImplementedInPrivateScript' in extended_attributes: |
364 arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentCont
ext())') | 382 arguments.append('toLocalFrame(toFrameIfNotDetached(info.GetIsolate()->G
etCurrentContext()))') |
365 arguments.append('impl') | 383 arguments.append('impl') |
366 arguments.append('cppValue') | 384 arguments.append('cppValue') |
367 elif idl_type.base_type == 'EventHandler': | 385 elif idl_type.base_type == 'EventHandler': |
368 getter_name = scoped_name(interface, attribute, cpp_name(attribute)) | 386 getter_name = scoped_name(interface, attribute, cpp_name(attribute)) |
369 context['event_handler_getter_expression'] = '%s(%s)' % ( | 387 context['event_handler_getter_expression'] = '%s(%s)' % ( |
370 getter_name, ', '.join(arguments)) | 388 getter_name, ', '.join(arguments)) |
371 if (interface.name in ['Window', 'WorkerGlobalScope'] and | 389 if (interface.name in ['Window', 'WorkerGlobalScope'] and |
372 attribute.name == 'onerror'): | 390 attribute.name == 'onerror'): |
373 includes.add('bindings/core/v8/V8ErrorHandler.h') | 391 includes.add('bindings/core/v8/V8ErrorHandler.h') |
374 arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHa
ndler>(v8Value, true, V8ScriptState::current(info.GetIsolate()))') | 392 arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHa
ndler>(v8Value, true, ScriptState::current(info.GetIsolate()))') |
375 else: | 393 else: |
376 arguments.append('V8EventListenerList::getEventListener(V8ScriptStat
e::current(info.GetIsolate()), v8Value, true, ListenerFindOrCreate)') | 394 arguments.append('V8EventListenerList::getEventListener(ScriptState:
:current(info.GetIsolate()), v8Value, true, ListenerFindOrCreate)') |
377 elif idl_type.is_interface_type: | 395 elif idl_type.is_interface_type: |
378 # FIXME: should be able to eliminate WTF::getPtr in most or all cases | 396 # FIXME: should be able to eliminate WTF::getPtr in most or all cases |
379 arguments.append('WTF::getPtr(cppValue)') | 397 arguments.append('WTF::getPtr(cppValue)') |
380 else: | 398 else: |
381 arguments.append('cppValue') | 399 arguments.append('cppValue') |
382 if context['is_setter_raises_exception']: | 400 if context['is_setter_raises_exception']: |
383 arguments.append('exceptionState') | 401 arguments.append('exceptionState') |
384 | 402 |
385 return '%s(%s)' % (setter_name, ', '.join(arguments)) | 403 return '%s(%s)' % (setter_name, ', '.join(arguments)) |
386 | 404 |
(...skipping 15 matching lines...) Expand all Loading... |
402 | 420 |
403 base_idl_type = attribute.idl_type.base_type | 421 base_idl_type = attribute.idl_type.base_type |
404 if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES: | 422 if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES: |
405 return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type] | 423 return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type] |
406 return 'setAttribute' | 424 return 'setAttribute' |
407 | 425 |
408 | 426 |
409 def scoped_content_attribute_name(interface, attribute): | 427 def scoped_content_attribute_name(interface, attribute): |
410 content_attribute_name = attribute.extended_attributes['Reflect'] or attribu
te.name.lower() | 428 content_attribute_name = attribute.extended_attributes['Reflect'] or attribu
te.name.lower() |
411 if interface.name.startswith('SVG'): | 429 if interface.name.startswith('SVG'): |
412 # SVG's xmlbase/xmlspace/xmllang need special behavior, i.e. | 430 namespace = 'SVGNames' |
413 # it is in XMLNames namespace and the generated attribute has no xml pre
fix. | |
414 if attribute.name.startswith('xml'): | |
415 namespace = 'XMLNames' | |
416 content_attribute_name = content_attribute_name[3:] | |
417 else: | |
418 namespace = 'SVGNames' | |
419 else: | 431 else: |
420 namespace = 'HTMLNames' | 432 namespace = 'HTMLNames' |
421 includes.add('core/%s.h' % namespace) | 433 includes.add('core/%s.h' % namespace) |
422 return '%s::%sAttr' % (namespace, content_attribute_name) | 434 return '%s::%sAttr' % (namespace, content_attribute_name) |
423 | 435 |
424 | 436 |
425 ################################################################################ | 437 ################################################################################ |
426 # Attribute configuration | 438 # Attribute configuration |
427 ################################################################################ | 439 ################################################################################ |
428 | 440 |
429 # [Replaceable] | 441 # [PutForwards], [Replaceable] |
430 def setter_callback_name(interface, attribute): | 442 def has_setter(attribute): |
431 cpp_class_name = cpp_name(interface) | 443 return (not attribute.is_read_only or |
432 extended_attributes = attribute.extended_attributes | 444 'PutForwards' in attribute.extended_attributes or |
433 if (('Replaceable' in extended_attributes and | 445 'Replaceable' in attribute.extended_attributes) |
434 'PutForwards' not in extended_attributes) or | |
435 is_constructor_attribute(attribute)): | |
436 return '{0}V8Internal::{0}ForceSetAttributeOnThisCallback'.format(cpp_cl
ass_name) | |
437 if attribute.is_read_only and 'PutForwards' not in extended_attributes: | |
438 return '0' | |
439 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut
e.name) | |
440 | 446 |
441 | 447 |
442 # [DoNotCheckSecurity], [Unforgeable] | 448 # [DoNotCheckSecurity], [Unforgeable] |
443 def access_control_list(attribute): | 449 def access_control_list(interface, attribute): |
444 extended_attributes = attribute.extended_attributes | 450 extended_attributes = attribute.extended_attributes |
445 access_control = [] | 451 access_control = [] |
446 if 'DoNotCheckSecurity' in extended_attributes: | 452 if 'DoNotCheckSecurity' in extended_attributes: |
447 do_not_check_security = extended_attributes['DoNotCheckSecurity'] | 453 do_not_check_security = extended_attributes['DoNotCheckSecurity'] |
448 if do_not_check_security == 'Setter': | 454 if do_not_check_security == 'Setter': |
449 access_control.append('v8::ALL_CAN_WRITE') | 455 access_control.append('v8::ALL_CAN_WRITE') |
450 else: | 456 else: |
451 access_control.append('v8::ALL_CAN_READ') | 457 access_control.append('v8::ALL_CAN_READ') |
452 if (not attribute.is_read_only or | 458 if has_setter(attribute): |
453 'Replaceable' in extended_attributes): | |
454 access_control.append('v8::ALL_CAN_WRITE') | 459 access_control.append('v8::ALL_CAN_WRITE') |
455 if 'Unforgeable' in extended_attributes: | 460 if is_unforgeable(interface, attribute): |
456 access_control.append('v8::PROHIBITS_OVERWRITING') | 461 access_control.append('v8::PROHIBITS_OVERWRITING') |
457 return access_control or ['v8::DEFAULT'] | 462 return access_control or ['v8::DEFAULT'] |
458 | 463 |
459 | 464 |
460 # [NotEnumerable], [Unforgeable] | 465 # [NotEnumerable], [Unforgeable] |
461 def property_attributes(attribute): | 466 def property_attributes(interface, attribute): |
462 extended_attributes = attribute.extended_attributes | 467 extended_attributes = attribute.extended_attributes |
463 property_attributes_list = [] | 468 property_attributes_list = [] |
464 if ('NotEnumerable' in extended_attributes or | 469 if ('NotEnumerable' in extended_attributes or |
465 is_constructor_attribute(attribute)): | 470 is_constructor_attribute(attribute)): |
466 property_attributes_list.append('v8::DontEnum') | 471 property_attributes_list.append('v8::DontEnum') |
467 if 'Unforgeable' in extended_attributes: | 472 if is_unforgeable(interface, attribute): |
468 property_attributes_list.append('v8::DontDelete') | 473 property_attributes_list.append('v8::DontDelete') |
469 return property_attributes_list or ['v8::None'] | 474 return property_attributes_list or ['v8::None'] |
470 | 475 |
471 | 476 |
472 # [Custom], [Custom=Getter] | 477 # [Custom], [Custom=Getter] |
473 def has_custom_getter(attribute): | 478 def has_custom_getter(attribute): |
474 extended_attributes = attribute.extended_attributes | 479 extended_attributes = attribute.extended_attributes |
475 return ('Custom' in extended_attributes and | 480 return ('Custom' in extended_attributes and |
476 extended_attributes['Custom'] in [None, 'Getter']) | 481 extended_attributes['Custom'] in [None, 'Getter']) |
477 | 482 |
478 | 483 |
479 # [Custom], [Custom=Setter] | 484 # [Custom], [Custom=Setter] |
480 def has_custom_setter(attribute): | 485 def has_custom_setter(attribute): |
481 extended_attributes = attribute.extended_attributes | 486 extended_attributes = attribute.extended_attributes |
482 return (not attribute.is_read_only and | 487 return (not attribute.is_read_only and |
483 'Custom' in extended_attributes and | 488 'Custom' in extended_attributes and |
484 extended_attributes['Custom'] in [None, 'Setter']) | 489 extended_attributes['Custom'] in [None, 'Setter']) |
485 | 490 |
486 | 491 |
| 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 |
487 ################################################################################ | 529 ################################################################################ |
488 # Constructors | 530 # Constructors |
489 ################################################################################ | 531 ################################################################################ |
490 | 532 |
491 idl_types.IdlType.constructor_type_name = property( | 533 idl_types.IdlType.constructor_type_name = property( |
492 # FIXME: replace this with a [ConstructorAttribute] extended attribute | 534 # FIXME: replace this with a [ConstructorAttribute] extended attribute |
493 lambda self: strip_suffix(self.base_type, 'Constructor')) | 535 lambda self: strip_suffix(self.base_type, 'Constructor')) |
494 | 536 |
495 | 537 |
496 def is_constructor_attribute(attribute): | 538 def is_constructor_attribute(attribute): |
497 # FIXME: replace this with [ConstructorAttribute] extended attribute | 539 # FIXME: replace this with [ConstructorAttribute] extended attribute |
498 return attribute.idl_type.name.endswith('Constructor') | 540 return attribute.idl_type.name.endswith('Constructor') |
499 | 541 |
500 | 542 |
501 def constructor_getter_context(interface, attribute, context): | 543 def update_constructor_attribute_context(interface, attribute, context): |
502 context['needs_constructor_getter_callback'] = context['measure_as'] or cont
ext['deprecate_as'] | 544 context['needs_constructor_getter_callback'] = context['measure_as'] or cont
ext['deprecate_as'] |
| 545 # When the attribute name is the same as the interface name, do not generate |
| 546 # callback functions for each attribute and use |
| 547 # {{cpp_class}}ConstructorAttributeSetterCallback. Otherwise, generate |
| 548 # a callback function in order to hard-code the attribute name. |
| 549 context['needs_constructor_setter_callback'] = context['name'] != context['c
onstructor_type'] |
OLD | NEW |