OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # coding=utf-8 | 2 # coding=utf-8 |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 import idl_definitions | 39 import idl_definitions |
40 from idl_definitions import IdlOperation, IdlArgument | 40 from idl_definitions import IdlOperation, IdlArgument |
41 import idl_types | 41 import idl_types |
42 from idl_types import IdlType, inherits_interface | 42 from idl_types import IdlType, inherits_interface |
43 import v8_attributes | 43 import v8_attributes |
44 from v8_globals import includes | 44 from v8_globals import includes |
45 import v8_methods | 45 import v8_methods |
46 import v8_types | 46 import v8_types |
47 from v8_types import cpp_ptr_type, cpp_template_type | 47 from v8_types import cpp_ptr_type, cpp_template_type |
48 import v8_utilities | 48 import v8_utilities |
49 from v8_utilities import (cpp_name_or_partial, capitalize, conditional_string, c
pp_name, gc_type, | 49 from v8_utilities import (origin_trial_enabled_function, cpp_name_or_partial, ca
pitalize, cpp_name, gc_type, |
50 has_extended_attribute_value, runtime_enabled_function
_name, | 50 has_extended_attribute_value, runtime_enabled_function
_name, |
51 extended_attribute_value_as_list, is_legacy_interface_
type_checking) | 51 extended_attribute_value_as_list, is_legacy_interface_
type_checking) |
52 | 52 |
53 | 53 |
54 INTERFACE_H_INCLUDES = frozenset([ | 54 INTERFACE_H_INCLUDES = frozenset([ |
55 'bindings/core/v8/ScriptWrappable.h', | 55 'bindings/core/v8/ScriptWrappable.h', |
56 'bindings/core/v8/ToV8.h', | 56 'bindings/core/v8/ToV8.h', |
57 'bindings/core/v8/V8Binding.h', | 57 'bindings/core/v8/V8Binding.h', |
58 'bindings/core/v8/V8DOMWrapper.h', | 58 'bindings/core/v8/V8DOMWrapper.h', |
59 'bindings/core/v8/WrapperTypeInfo.h', | 59 'bindings/core/v8/WrapperTypeInfo.h', |
60 'platform/heap/Handle.h', | 60 'platform/heap/Handle.h', |
61 ]) | 61 ]) |
62 INTERFACE_CPP_INCLUDES = frozenset([ | 62 INTERFACE_CPP_INCLUDES = frozenset([ |
63 'bindings/core/v8/ExceptionState.h', | 63 'bindings/core/v8/ExceptionState.h', |
64 'bindings/core/v8/V8DOMConfiguration.h', | 64 'bindings/core/v8/V8DOMConfiguration.h', |
65 'bindings/core/v8/V8ObjectConstructor.h', | 65 'bindings/core/v8/V8ObjectConstructor.h', |
66 'core/dom/ContextFeatures.h', | |
67 'core/dom/Document.h', | 66 'core/dom/Document.h', |
68 'platform/RuntimeEnabledFeatures.h', | |
69 'platform/TraceEvent.h', | |
70 'wtf/GetPtr.h', | 67 'wtf/GetPtr.h', |
71 'wtf/RefPtr.h', | 68 'wtf/RefPtr.h', |
72 ]) | 69 ]) |
73 | 70 |
74 | 71 |
75 def interface_context(interface): | 72 def interface_context(interface): |
76 includes.clear() | 73 includes.clear() |
77 includes.update(INTERFACE_CPP_INCLUDES) | 74 includes.update(INTERFACE_CPP_INCLUDES) |
78 header_includes = set(INTERFACE_H_INCLUDES) | 75 header_includes = set(INTERFACE_H_INCLUDES) |
79 | 76 |
80 if interface.is_partial: | 77 if interface.is_partial: |
81 # A partial interface definition cannot specify that the interface | 78 # A partial interface definition cannot specify that the interface |
82 # inherits from another interface. Inheritance must be specified on | 79 # inherits from another interface. Inheritance must be specified on |
83 # the original interface definition. | 80 # the original interface definition. |
84 parent_interface = None | 81 parent_interface = None |
85 is_event_target = False | 82 is_event_target = False |
86 # partial interface needs the definition of its original interface. | 83 # partial interface needs the definition of its original interface. |
87 includes.add('bindings/core/v8/V8%s.h' % interface.name) | 84 includes.add('bindings/core/v8/V8%s.h' % interface.name) |
88 else: | 85 else: |
89 parent_interface = interface.parent | 86 parent_interface = interface.parent |
90 if parent_interface: | 87 if parent_interface: |
91 header_includes.update(v8_types.includes_for_interface(parent_interf
ace)) | 88 header_includes.update(v8_types.includes_for_interface(parent_interf
ace)) |
92 is_event_target = inherits_interface(interface.name, 'EventTarget') | 89 is_event_target = inherits_interface(interface.name, 'EventTarget') |
93 | 90 |
94 extended_attributes = interface.extended_attributes | 91 extended_attributes = interface.extended_attributes |
95 | 92 |
96 is_array_buffer_or_view = interface.idl_type.is_array_buffer_or_view | 93 is_array_buffer_or_view = interface.idl_type.is_array_buffer_or_view |
97 is_typed_array_type = interface.idl_type.is_typed_array | 94 is_typed_array_type = interface.idl_type.is_typed_array |
98 if is_array_buffer_or_view: | 95 if is_array_buffer_or_view: |
99 includes.add('bindings/core/v8/V8ArrayBuffer.h') | 96 includes.update(('bindings/core/v8/V8ArrayBuffer.h', |
| 97 'bindings/core/v8/V8SharedArrayBuffer.h')) |
100 if interface.name == 'ArrayBufferView': | 98 if interface.name == 'ArrayBufferView': |
101 includes.update(( | 99 includes.update(( |
102 'bindings/core/v8/V8Int8Array.h', | 100 'bindings/core/v8/V8Int8Array.h', |
103 'bindings/core/v8/V8Int16Array.h', | 101 'bindings/core/v8/V8Int16Array.h', |
104 'bindings/core/v8/V8Int32Array.h', | 102 'bindings/core/v8/V8Int32Array.h', |
105 'bindings/core/v8/V8Uint8Array.h', | 103 'bindings/core/v8/V8Uint8Array.h', |
106 'bindings/core/v8/V8Uint8ClampedArray.h', | 104 'bindings/core/v8/V8Uint8ClampedArray.h', |
107 'bindings/core/v8/V8Uint16Array.h', | 105 'bindings/core/v8/V8Uint16Array.h', |
108 'bindings/core/v8/V8Uint32Array.h', | 106 'bindings/core/v8/V8Uint32Array.h', |
109 'bindings/core/v8/V8Float32Array.h', | 107 'bindings/core/v8/V8Float32Array.h', |
110 'bindings/core/v8/V8Float64Array.h', | 108 'bindings/core/v8/V8Float64Array.h', |
111 'bindings/core/v8/V8DataView.h')) | 109 'bindings/core/v8/V8DataView.h')) |
112 | 110 |
113 # [ActiveDOMObject] | |
114 is_active_dom_object = 'ActiveDOMObject' in extended_attributes | |
115 | |
116 # [CheckSecurity] | 111 # [CheckSecurity] |
117 is_check_security = 'CheckSecurity' in extended_attributes | 112 is_check_security = 'CheckSecurity' in extended_attributes |
118 if is_check_security: | 113 if is_check_security: |
119 includes.add('bindings/core/v8/BindingSecurity.h') | 114 includes.add('bindings/core/v8/BindingSecurity.h') |
120 | 115 |
121 # [DependentLifetime] | 116 # [DependentLifetime] |
122 is_dependent_lifetime = 'DependentLifetime' in extended_attributes | 117 is_dependent_lifetime = 'DependentLifetime' in extended_attributes |
123 | 118 |
124 # [MeasureAs] | 119 # [PrimaryGlobal] and [Global] |
125 is_measure_as = 'MeasureAs' in extended_attributes | 120 is_global = ('PrimaryGlobal' in extended_attributes or |
126 if is_measure_as: | 121 'Global' in extended_attributes) |
127 includes.add('core/frame/UseCounter.h') | |
128 | 122 |
129 # [SetWrapperReferenceFrom] | 123 # [SetWrapperReferenceFrom] |
130 set_wrapper_reference_from = extended_attributes.get('SetWrapperReferenceFro
m') | 124 set_wrapper_reference_from = extended_attributes.get('SetWrapperReferenceFro
m') |
131 if set_wrapper_reference_from: | 125 if set_wrapper_reference_from: |
132 includes.update(['bindings/core/v8/V8GCController.h', | 126 includes.update(['bindings/core/v8/V8GCController.h', |
133 'core/dom/Element.h']) | 127 'core/dom/Element.h']) |
134 | 128 |
135 # [SetWrapperReferenceTo] | 129 # [SetWrapperReferenceTo] |
136 set_wrapper_reference_to_argument = extended_attributes.get('SetWrapperRefer
enceTo') | 130 set_wrapper_reference_to_argument = extended_attributes.get('SetWrapperRefer
enceTo') |
137 set_wrapper_reference_to = None | 131 set_wrapper_reference_to = None |
(...skipping 17 matching lines...) Expand all Loading... |
155 | 149 |
156 this_gc_type = gc_type(interface) | 150 this_gc_type = gc_type(interface) |
157 | 151 |
158 wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Nod
e') else 'ObjectClassId') | 152 wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Nod
e') else 'ObjectClassId') |
159 | 153 |
160 v8_class_name = v8_utilities.v8_class_name(interface) | 154 v8_class_name = v8_utilities.v8_class_name(interface) |
161 cpp_class_name = cpp_name(interface) | 155 cpp_class_name = cpp_name(interface) |
162 cpp_class_name_or_partial = cpp_name_or_partial(interface) | 156 cpp_class_name_or_partial = cpp_name_or_partial(interface) |
163 v8_class_name_or_partial = v8_utilities.v8_class_name_or_partial(interface) | 157 v8_class_name_or_partial = v8_utilities.v8_class_name_or_partial(interface) |
164 | 158 |
| 159 if 'RuntimeEnabled' in extended_attributes: |
| 160 includes.add('platform/RuntimeEnabledFeatures.h') |
| 161 |
| 162 if 'OriginTrialEnabled' in extended_attributes: |
| 163 includes.add('core/inspector/ConsoleMessage.h') |
| 164 includes.add('core/origin_trials/OriginTrials.h') |
| 165 |
165 context = { | 166 context = { |
166 'conditional_string': conditional_string(interface), # [Conditional] | |
167 'cpp_class': cpp_class_name, | 167 'cpp_class': cpp_class_name, |
168 'cpp_class_or_partial': cpp_class_name_or_partial, | 168 'cpp_class_or_partial': cpp_class_name_or_partial, |
169 'event_target_inheritance': 'InheritFromEventTarget' if is_event_target
else 'NotInheritFromEventTarget', | 169 'event_target_inheritance': 'InheritFromEventTarget' if is_event_target
else 'NotInheritFromEventTarget', |
170 'gc_type': this_gc_type, | 170 'gc_type': this_gc_type, |
171 # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699 | 171 # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699 |
172 'has_access_check_callbacks': (is_check_security and | 172 'has_access_check_callbacks': (is_check_security and |
173 interface.name != 'Window' and | 173 interface.name != 'Window' and |
174 interface.name != 'EventTarget'), | 174 interface.name != 'EventTarget'), |
175 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter
face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] | 175 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter
face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] |
176 'has_partial_interface': len(interface.partial_interfaces) > 0, | 176 'has_partial_interface': len(interface.partial_interfaces) > 0, |
177 'has_visit_dom_wrapper': has_visit_dom_wrapper, | 177 'has_visit_dom_wrapper': has_visit_dom_wrapper, |
178 'header_includes': header_includes, | 178 'header_includes': header_includes, |
179 'interface_name': interface.name, | 179 'interface_name': interface.name, |
180 'is_active_dom_object': is_active_dom_object, | |
181 'is_array_buffer_or_view': is_array_buffer_or_view, | 180 'is_array_buffer_or_view': is_array_buffer_or_view, |
182 'is_check_security': is_check_security, | 181 'is_check_security': is_check_security, |
183 'is_event_target': is_event_target, | 182 'is_event_target': is_event_target, |
184 'is_exception': interface.is_exception, | 183 'is_exception': interface.is_exception, |
| 184 'is_global': is_global, |
185 'is_node': inherits_interface(interface.name, 'Node'), | 185 'is_node': inherits_interface(interface.name, 'Node'), |
186 'is_partial': interface.is_partial, | 186 'is_partial': interface.is_partial, |
187 'is_typed_array_type': is_typed_array_type, | 187 'is_typed_array_type': is_typed_array_type, |
188 'lifetime': 'Dependent' | 188 'lifetime': 'Dependent' if (has_visit_dom_wrapper or is_dependent_lifeti
me) else 'Independent', |
189 if (has_visit_dom_wrapper or | |
190 is_active_dom_object or | |
191 is_dependent_lifetime) | |
192 else 'Independent', | |
193 'measure_as': v8_utilities.measure_as(interface, None), # [MeasureAs] | 189 'measure_as': v8_utilities.measure_as(interface, None), # [MeasureAs] |
| 190 'origin_trial_name': v8_utilities.origin_trial_name(interface), |
194 'parent_interface': parent_interface, | 191 'parent_interface': parent_interface, |
195 'pass_cpp_type': cpp_template_type( | 192 'pass_cpp_type': cpp_template_type( |
196 cpp_ptr_type('PassRefPtr', 'RawPtr', this_gc_type), | 193 cpp_ptr_type('PassRefPtr', 'RawPtr', this_gc_type), |
197 cpp_name(interface)), | 194 cpp_name(interface)), |
198 'runtime_enabled_function': runtime_enabled_function_name(interface), #
[RuntimeEnabled] | 195 'runtime_enabled_function': runtime_enabled_function_name(interface), #
[RuntimeEnabled] |
199 'set_wrapper_reference_from': set_wrapper_reference_from, | 196 'set_wrapper_reference_from': set_wrapper_reference_from, |
200 'set_wrapper_reference_to': set_wrapper_reference_to, | 197 'set_wrapper_reference_to': set_wrapper_reference_to, |
201 'v8_class': v8_class_name, | 198 'v8_class': v8_class_name, |
202 'v8_class_or_partial': v8_class_name_or_partial, | 199 'v8_class_or_partial': v8_class_name_or_partial, |
203 'wrapper_class_id': wrapper_class_id, | 200 'wrapper_class_id': wrapper_class_id, |
(...skipping 14 matching lines...) Expand all Loading... |
218 'number_of_required_arguments': | 215 'number_of_required_arguments': |
219 number_of_required_arguments(constructor), | 216 number_of_required_arguments(constructor), |
220 } for constructor in interface.custom_constructors] | 217 } for constructor in interface.custom_constructors] |
221 | 218 |
222 # [NamedConstructor] | 219 # [NamedConstructor] |
223 named_constructor = named_constructor_context(interface) | 220 named_constructor = named_constructor_context(interface) |
224 | 221 |
225 if constructors or custom_constructors or named_constructor: | 222 if constructors or custom_constructors or named_constructor: |
226 if interface.is_partial: | 223 if interface.is_partial: |
227 raise Exception('[Constructor] and [NamedConstructor] MUST NOT be' | 224 raise Exception('[Constructor] and [NamedConstructor] MUST NOT be' |
228 ' specified on partial interface definitions:' | 225 ' specified on partial interface definitions: ' |
229 '%s' % interface.name) | 226 '%s' % interface.name) |
230 | 227 |
231 includes.add('bindings/core/v8/V8ObjectConstructor.h') | 228 includes.add('bindings/core/v8/V8ObjectConstructor.h') |
232 includes.add('core/frame/LocalDOMWindow.h') | 229 includes.add('core/frame/LocalDOMWindow.h') |
| 230 elif 'Measure' in extended_attributes or 'MeasureAs' in extended_attributes: |
| 231 raise Exception('[Measure] or [MeasureAs] specified for interface withou
t a constructor: ' |
| 232 '%s' % interface.name) |
233 | 233 |
234 # [Unscopeable] attributes and methods | 234 # [Unscopeable] attributes and methods |
235 unscopeables = [] | 235 unscopeables = [] |
236 for attribute in interface.attributes: | 236 for attribute in interface.attributes: |
237 if 'Unscopeable' in attribute.extended_attributes: | 237 if 'Unscopeable' in attribute.extended_attributes: |
238 unscopeables.append((attribute.name, v8_utilities.runtime_enabled_fu
nction_name(attribute))) | 238 unscopeables.append((attribute.name, v8_utilities.runtime_enabled_fu
nction_name(attribute))) |
239 for method in interface.operations: | 239 for method in interface.operations: |
240 if 'Unscopeable' in method.extended_attributes: | 240 if 'Unscopeable' in method.extended_attributes: |
241 unscopeables.append((method.name, v8_utilities.runtime_enabled_funct
ion_name(method))) | 241 unscopeables.append((method.name, v8_utilities.runtime_enabled_funct
ion_name(method))) |
242 | 242 |
243 context.update({ | 243 context.update({ |
244 'constructors': constructors, | 244 'constructors': constructors, |
245 'has_custom_constructor': bool(custom_constructors), | 245 'has_custom_constructor': bool(custom_constructors), |
246 'interface_length': | 246 'interface_length': |
247 interface_length(interface, constructors + custom_constructors), | 247 interface_length(interface, constructors + custom_constructors), |
248 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept
ion') == 'Constructor', # [RaisesException=Constructor] | 248 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept
ion') == 'Constructor', # [RaisesException=Constructor] |
249 'named_constructor': named_constructor, | 249 'named_constructor': named_constructor, |
250 'unscopeables': sorted(unscopeables), | 250 'unscopeables': sorted(unscopeables), |
251 }) | 251 }) |
252 | 252 |
253 constants = [constant_context(constant, interface) for constant in interface
.constants] | 253 constants = [constant_context(constant, interface) for constant in interface
.constants] |
254 | 254 |
255 special_getter_constants = [] | 255 special_getter_constants = [] |
256 runtime_enabled_constants = [] | 256 runtime_enabled_constants = dict() |
257 constant_configuration_constants = [] | 257 constant_configuration_constants = [] |
258 | 258 |
259 for constant in constants: | 259 for constant in constants: |
260 if constant['measure_as'] or constant['deprecate_as']: | 260 if constant['measure_as'] or constant['deprecate_as'] or constant['origi
n_trial_name']: |
261 special_getter_constants.append(constant) | 261 special_getter_constants.append(constant) |
262 continue | 262 continue |
263 if constant['runtime_enabled_function']: | 263 runtime_enabled_function = constant['runtime_enabled_function'] |
264 runtime_enabled_constants.append(constant) | 264 if runtime_enabled_function: |
| 265 if runtime_enabled_function not in runtime_enabled_constants: |
| 266 runtime_enabled_constants[runtime_enabled_function] = [] |
| 267 runtime_enabled_constants[runtime_enabled_function].append(constant) |
265 continue | 268 continue |
266 constant_configuration_constants.append(constant) | 269 constant_configuration_constants.append(constant) |
267 | 270 |
268 # Constants | 271 # Constants |
269 context.update({ | 272 context.update({ |
270 'constant_configuration_constants': constant_configuration_constants, | 273 'constant_configuration_constants': constant_configuration_constants, |
271 'constants': constants, | 274 'constants': constants, |
272 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, | 275 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, |
273 'has_constant_configuration': any( | 276 'has_constant_configuration': any( |
274 not constant['runtime_enabled_function'] | 277 not constant['runtime_enabled_function'] |
275 for constant in constants), | 278 for constant in constants), |
276 'runtime_enabled_constants': runtime_enabled_constants, | 279 'runtime_enabled_constants': sorted(runtime_enabled_constants.iteritems(
)), |
277 'special_getter_constants': special_getter_constants, | 280 'special_getter_constants': special_getter_constants, |
278 }) | 281 }) |
279 | 282 |
280 # Attributes | 283 # Attributes |
281 attributes = [v8_attributes.attribute_context(interface, attribute) | 284 attributes = [v8_attributes.attribute_context(interface, attribute) |
282 for attribute in interface.attributes] | 285 for attribute in interface.attributes] |
283 | 286 |
284 has_conditional_attributes = any(attribute['exposed_test'] for attribute in
attributes) | 287 has_conditional_attributes = any(attribute['exposed_test'] for attribute in
attributes) |
285 if has_conditional_attributes and interface.is_partial: | 288 if has_conditional_attributes and interface.is_partial: |
286 raise Exception('Conditional attributes between partial interfaces in mo
dules and the original interfaces(%s) in core are not allowed.' % interface.name
) | 289 raise Exception('Conditional attributes between partial interfaces in mo
dules and the original interfaces(%s) in core are not allowed.' % interface.name
) |
287 | 290 |
288 context.update({ | 291 context.update({ |
289 'attributes': attributes, | 292 'attributes': attributes, |
290 'has_accessor_configuration': any( | 293 'has_accessor_configuration': any( |
291 attribute['is_expose_js_accessors'] and | 294 not (attribute['exposed_test'] or |
292 not (attribute['is_static'] or | |
293 attribute['runtime_enabled_function']) and | 295 attribute['runtime_enabled_function']) and |
| 296 not attribute['is_data_type_property'] and |
294 attribute['should_be_exposed_to_script'] | 297 attribute['should_be_exposed_to_script'] |
295 for attribute in attributes), | 298 for attribute in attributes), |
296 'has_attribute_configuration': any( | 299 'has_attribute_configuration': any( |
297 not (attribute['is_expose_js_accessors'] or | 300 not (attribute['exposed_test'] or |
298 attribute['is_static'] or | 301 attribute['runtime_enabled_function']) and |
299 attribute['runtime_enabled_function']) | 302 attribute['is_data_type_property'] and |
300 and attribute['should_be_exposed_to_script'] | 303 attribute['should_be_exposed_to_script'] |
301 for attribute in attributes), | 304 for attribute in attributes), |
302 'has_constructor_attributes': any(attribute['constructor_type'] for attr
ibute in attributes), | 305 'has_constructor_attributes': any(attribute['constructor_type'] for attr
ibute in attributes), |
| 306 'needs_constructor_setter_callback': any(attribute['constructor_type'] =
= attribute['name'] for attribute in attributes), |
303 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib
ute in attributes), | 307 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib
ute in attributes), |
304 }) | 308 }) |
305 | 309 |
306 # Methods | 310 # Methods |
307 methods = [] | 311 methods = [] |
308 if interface.original_interface: | 312 if interface.original_interface: |
309 methods.extend([v8_methods.method_context(interface, operation, is_visib
le=False) | 313 methods.extend([v8_methods.method_context(interface, operation, is_visib
le=False) |
310 for operation in interface.original_interface.operations | 314 for operation in interface.original_interface.operations |
311 if operation.name]) | 315 if operation.name]) |
312 methods.extend([v8_methods.method_context(interface, method) | 316 methods.extend([v8_methods.method_context(interface, method) |
(...skipping 24 matching lines...) Expand all Loading... |
337 argument = IdlArgument(interface.idl_name) | 341 argument = IdlArgument(interface.idl_name) |
338 argument.idl_type = idl_type | 342 argument.idl_type = idl_type |
339 argument.name = name | 343 argument.name = name |
340 argument.is_optional = is_optional | 344 argument.is_optional = is_optional |
341 if extended_attributes: | 345 if extended_attributes: |
342 argument.extended_attributes.update(extended_attributes) | 346 argument.extended_attributes.update(extended_attributes) |
343 return argument | 347 return argument |
344 | 348 |
345 # [Iterable], iterable<>, maplike<> and setlike<> | 349 # [Iterable], iterable<>, maplike<> and setlike<> |
346 iterator_method = None | 350 iterator_method = None |
| 351 has_array_iterator = False |
| 352 |
347 # FIXME: support Iterable in partial interfaces. However, we don't | 353 # FIXME: support Iterable in partial interfaces. However, we don't |
348 # need to support iterator overloads between interface and | 354 # need to support iterator overloads between interface and |
349 # partial interface definitions. | 355 # partial interface definitions. |
350 # http://heycam.github.io/webidl/#idl-overloading | 356 # http://heycam.github.io/webidl/#idl-overloading |
351 if (not interface.is_partial | 357 if (not interface.is_partial |
352 and (interface.iterable or interface.maplike or interface.setlike | 358 and (interface.iterable or interface.maplike or interface.setlike |
353 or 'Iterable' in extended_attributes)): | 359 or interface.has_indexed_elements or 'Iterable' in extended_attribu
tes)): |
354 | 360 |
355 used_extended_attributes = {} | 361 used_extended_attributes = {} |
356 | 362 |
357 if interface.iterable: | 363 if interface.iterable: |
358 used_extended_attributes.update(interface.iterable.extended_attribut
es) | 364 used_extended_attributes.update(interface.iterable.extended_attribut
es) |
359 elif interface.maplike: | 365 elif interface.maplike: |
360 used_extended_attributes.update(interface.maplike.extended_attribute
s) | 366 used_extended_attributes.update(interface.maplike.extended_attribute
s) |
361 elif interface.setlike: | 367 elif interface.setlike: |
362 used_extended_attributes.update(interface.setlike.extended_attribute
s) | 368 used_extended_attributes.update(interface.setlike.extended_attribute
s) |
363 | 369 |
(...skipping 12 matching lines...) Expand all Loading... |
376 'CallWith': ['ScriptState', 'ThisValue'], | 382 'CallWith': ['ScriptState', 'ThisValue'], |
377 }) | 383 }) |
378 | 384 |
379 def generated_iterator_method(name, implemented_as=None): | 385 def generated_iterator_method(name, implemented_as=None): |
380 return generated_method( | 386 return generated_method( |
381 return_type=IdlType('Iterator'), | 387 return_type=IdlType('Iterator'), |
382 name=name, | 388 name=name, |
383 extended_attributes=used_extended_attributes, | 389 extended_attributes=used_extended_attributes, |
384 implemented_as=implemented_as) | 390 implemented_as=implemented_as) |
385 | 391 |
386 iterator_method = generated_iterator_method('iterator', implemented_as='
iterator') | 392 if interface.iterable or interface.maplike or interface.setlike or 'Iter
able' in extended_attributes: |
| 393 iterator_method = generated_iterator_method('iterator', implemented_
as='iterator') |
| 394 elif interface.has_indexed_elements: |
| 395 has_array_iterator = True |
387 | 396 |
388 if interface.iterable or interface.maplike or interface.setlike: | 397 if interface.iterable or interface.maplike or interface.setlike: |
389 implicit_methods = [ | 398 implicit_methods = [ |
390 generated_iterator_method('keys'), | 399 generated_iterator_method('keys'), |
391 generated_iterator_method('values'), | 400 generated_iterator_method('values'), |
392 generated_iterator_method('entries'), | 401 generated_iterator_method('entries'), |
393 | 402 |
394 # void forEach(Function callback, [Default=Undefined] optional a
ny thisArg) | 403 # void forEach(Function callback, [Default=Undefined] optional a
ny thisArg) |
395 generated_method(IdlType('void'), 'forEach', | 404 generated_method(IdlType('void'), 'forEach', |
396 arguments=[generated_argument(IdlType('Function
'), 'callback'), | 405 arguments=[generated_argument(IdlType('Function
'), 'callback'), |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 # FIXME: This calculation doesn't take into account whether runtime | 552 # FIXME: This calculation doesn't take into account whether runtime |
544 # enabled overloads are actually enabled, so length may be incorrect. | 553 # enabled overloads are actually enabled, so length may be incorrect. |
545 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); | 554 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); |
546 # should have length 1 if Foo is not enabled, but length 0 if it is. | 555 # should have length 1 if Foo is not enabled, but length 0 if it is. |
547 method['length'] = (method['overloads']['length'] if 'overloads' in meth
od else | 556 method['length'] = (method['overloads']['length'] if 'overloads' in meth
od else |
548 method['number_of_required_arguments']) | 557 method['number_of_required_arguments']) |
549 | 558 |
550 context.update({ | 559 context.update({ |
551 'conditionally_enabled_methods': conditionally_enabled_methods, | 560 'conditionally_enabled_methods': conditionally_enabled_methods, |
552 'custom_registration_methods': custom_registration_methods, | 561 'custom_registration_methods': custom_registration_methods, |
553 'has_origin_safe_method_setter': any( | 562 'has_origin_safe_method_setter': is_global and any( |
554 method['is_check_security_for_frame'] and not method['is_read_only'] | 563 method['is_check_security_for_receiver'] and not method['is_unforgea
ble'] |
555 for method in methods), | 564 for method in methods), |
556 'has_private_script': any(attribute['is_implemented_in_private_script']
for attribute in attributes) or | 565 'has_private_script': any(attribute['is_implemented_in_private_script']
for attribute in attributes) or |
557 any(method['is_implemented_in_private_script'] for method in methods
), | 566 any(method['is_implemented_in_private_script'] for method in methods
), |
558 'iterator_method': iterator_method, | 567 'iterator_method': iterator_method, |
| 568 'has_array_iterator': has_array_iterator, |
559 'method_configuration_methods': method_configuration_methods, | 569 'method_configuration_methods': method_configuration_methods, |
560 'methods': methods, | 570 'methods': methods, |
561 }) | 571 }) |
562 | 572 |
563 # Conditionally enabled members | 573 # Conditionally enabled members |
564 has_conditional_attributes_on_instance = any( | 574 has_conditional_attributes_on_instance = any( |
565 attribute['exposed_test'] and attribute['on_instance'] | 575 attribute['exposed_test'] and attribute['on_instance'] |
566 for attribute in attributes) | 576 for attribute in attributes) |
567 has_conditional_attributes_on_prototype = any( | 577 has_conditional_attributes_on_prototype = any( |
568 attribute['exposed_test'] and attribute['on_prototype'] | 578 attribute['exposed_test'] and attribute['on_prototype'] |
569 for attribute in attributes) | 579 for attribute in attributes) |
570 context.update({ | 580 context.update({ |
571 'has_conditional_attributes_on_instance': | 581 'has_conditional_attributes_on_instance': |
572 has_conditional_attributes_on_instance, | 582 has_conditional_attributes_on_instance, |
573 'has_conditional_attributes_on_prototype': | 583 'has_conditional_attributes_on_prototype': |
574 has_conditional_attributes_on_prototype, | 584 has_conditional_attributes_on_prototype, |
575 }) | 585 }) |
576 | 586 |
577 context.update({ | 587 context.update({ |
578 'indexed_property_getter': property_getter(interface.indexed_property_ge
tter, ['index']), | 588 'indexed_property_getter': property_getter(interface.indexed_property_ge
tter, ['index']), |
579 'indexed_property_setter': property_setter(interface.indexed_property_se
tter, interface), | 589 'indexed_property_setter': property_setter(interface.indexed_property_se
tter, interface), |
580 'indexed_property_deleter': property_deleter(interface.indexed_property_
deleter), | 590 'indexed_property_deleter': property_deleter(interface.indexed_property_
deleter), |
581 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, | 591 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, |
582 'named_property_getter': property_getter(interface.named_property_getter
, ['propertyName']), | 592 'named_property_getter': property_getter(interface.named_property_getter
, ['propertyName']), |
583 'named_property_setter': property_setter(interface.named_property_setter
, interface), | 593 'named_property_setter': property_setter(interface.named_property_setter
, interface), |
584 'named_property_deleter': property_deleter(interface.named_property_dele
ter), | 594 'named_property_deleter': property_deleter(interface.named_property_dele
ter), |
585 }) | 595 }) |
| 596 context.update({ |
| 597 'has_named_properties_object': is_global and context['named_property_get
ter'], |
| 598 }) |
586 | 599 |
587 return context | 600 return context |
588 | 601 |
589 | 602 |
590 # [DeprecateAs], [Reflect], [RuntimeEnabled] | 603 # [DeprecateAs], [OriginTrialEnabled], [Reflect], [RuntimeEnabled] |
591 def constant_context(constant, interface): | 604 def constant_context(constant, interface): |
592 extended_attributes = constant.extended_attributes | 605 extended_attributes = constant.extended_attributes |
| 606 |
| 607 if 'OriginTrialEnabled' in extended_attributes: |
| 608 includes.add('core/inspector/ConsoleMessage.h') |
| 609 includes.add('core/origin_trials/OriginTrials.h') |
| 610 |
593 return { | 611 return { |
594 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), | 612 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), |
595 'deprecate_as': v8_utilities.deprecate_as(constant), # [DeprecateAs] | 613 'deprecate_as': v8_utilities.deprecate_as(constant), # [DeprecateAs] |
596 'idl_type': constant.idl_type.name, | 614 'idl_type': constant.idl_type.name, |
| 615 'is_origin_trial_enabled': v8_utilities.origin_trial_enabled_function(co
nstant) or v8_utilities.origin_trial_enabled_function(interface), # [OriginTria
lEnabled] |
597 'measure_as': v8_utilities.measure_as(constant, interface), # [MeasureA
s] | 616 'measure_as': v8_utilities.measure_as(constant, interface), # [MeasureA
s] |
598 'name': constant.name, | 617 'name': constant.name, |
| 618 'origin_trial_enabled': v8_utilities.origin_trial_enabled_function(const
ant), # [OriginTrialEnabled] |
| 619 'origin_trial_enabled_per_interface': v8_utilities.origin_trial_enabled_
function(interface), # [OriginTrialEnabled] |
| 620 'origin_trial_name': extended_attributes.get('OriginTrialEnabled'), # [
OriginTrialEnabled] |
599 # FIXME: use 'reflected_name' as correct 'name' | 621 # FIXME: use 'reflected_name' as correct 'name' |
600 'reflected_name': extended_attributes.get('Reflect', constant.name), | 622 'reflected_name': extended_attributes.get('Reflect', constant.name), |
601 'runtime_enabled_function': runtime_enabled_function_name(constant), | 623 'runtime_enabled_function': runtime_enabled_function_name(constant), #
[RuntimeEnabled] |
602 'value': constant.value, | 624 'value': constant.value, |
603 } | 625 } |
604 | 626 |
605 | 627 |
606 ################################################################################ | 628 ################################################################################ |
607 # Overloads | 629 # Overloads |
608 ################################################################################ | 630 ################################################################################ |
609 | 631 |
610 def compute_method_overloads_context(interface, methods): | 632 def compute_method_overloads_context(interface, methods): |
611 # Regular methods | 633 # Regular methods |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 | 905 |
884 If there is more than one entry in an effective overload set that has a | 906 If there is more than one entry in an effective overload set that has a |
885 given type list length, then for those entries there must be an index i | 907 given type list length, then for those entries there must be an index i |
886 such that for each pair of entries the types at index i are | 908 such that for each pair of entries the types at index i are |
887 distinguishable. | 909 distinguishable. |
888 The lowest such index is termed the distinguishing argument index for the | 910 The lowest such index is termed the distinguishing argument index for the |
889 entries of the effective overload set with the given type list length. | 911 entries of the effective overload set with the given type list length. |
890 """ | 912 """ |
891 # Only applicable “If there is more than one entry” | 913 # Only applicable “If there is more than one entry” |
892 assert len(entries) > 1 | 914 assert len(entries) > 1 |
893 type_lists = [tuple(idl_type.name for idl_type in entry[1]) | 915 |
| 916 def typename_without_nullable(idl_type): |
| 917 if idl_type.is_nullable: |
| 918 return idl_type.inner_type.name |
| 919 return idl_type.name |
| 920 |
| 921 type_lists = [tuple(typename_without_nullable(idl_type) |
| 922 for idl_type in entry[1]) |
894 for entry in entries] | 923 for entry in entries] |
895 type_list_length = len(type_lists[0]) | 924 type_list_length = len(type_lists[0]) |
896 # Only applicable for entries that “[have] a given type list length” | 925 # Only applicable for entries that “[have] a given type list length” |
897 assert all(len(type_list) == type_list_length for type_list in type_lists) | 926 assert all(len(type_list) == type_list_length for type_list in type_lists) |
898 name = entries[0][0].get('name', 'Constructor') # for error reporting | 927 name = entries[0][0].get('name', 'Constructor') # for error reporting |
899 | 928 |
900 # The spec defines the distinguishing argument index by conditions it must | 929 # The spec defines the distinguishing argument index by conditions it must |
901 # satisfy, but does not give an algorithm. | 930 # satisfy, but does not give an algorithm. |
902 # | 931 # |
903 # We compute the distinguishing argument index by first computing the | 932 # We compute the distinguishing argument index by first computing the |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 ################################################################################ | 1217 ################################################################################ |
1189 # Constructors | 1218 # Constructors |
1190 ################################################################################ | 1219 ################################################################################ |
1191 | 1220 |
1192 # [Constructor] | 1221 # [Constructor] |
1193 def constructor_context(interface, constructor): | 1222 def constructor_context(interface, constructor): |
1194 # [RaisesException=Constructor] | 1223 # [RaisesException=Constructor] |
1195 is_constructor_raises_exception = \ | 1224 is_constructor_raises_exception = \ |
1196 interface.extended_attributes.get('RaisesException') == 'Constructor' | 1225 interface.extended_attributes.get('RaisesException') == 'Constructor' |
1197 | 1226 |
| 1227 argument_contexts = [ |
| 1228 v8_methods.argument_context(interface, constructor, argument, index) |
| 1229 for index, argument in enumerate(constructor.arguments)] |
| 1230 |
1198 return { | 1231 return { |
1199 'arguments': [v8_methods.argument_context(interface, constructor, argume
nt, index) | 1232 'arguments': argument_contexts, |
1200 for index, argument in enumerate(constructor.arguments)], | |
1201 'cpp_type': cpp_template_type( | 1233 'cpp_type': cpp_template_type( |
1202 cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), | 1234 cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), |
1203 cpp_name(interface)), | 1235 cpp_name(interface)), |
1204 'cpp_value': v8_methods.cpp_value( | 1236 'cpp_value': v8_methods.cpp_value( |
1205 interface, constructor, len(constructor.arguments)), | 1237 interface, constructor, len(constructor.arguments)), |
1206 'has_exception_state': | 1238 'has_exception_state': |
1207 is_constructor_raises_exception or | 1239 is_constructor_raises_exception or |
1208 any(argument for argument in constructor.arguments | 1240 any(argument for argument in constructor.arguments |
1209 if argument.idl_type.name == 'SerializedScriptValue' or | 1241 if argument.idl_type.name == 'SerializedScriptValue' or |
1210 argument.idl_type.v8_conversion_needs_exception_state), | 1242 argument.idl_type.v8_conversion_needs_exception_state), |
| 1243 'has_optional_argument_without_default_value': |
| 1244 any(True for argument_context in argument_contexts |
| 1245 if argument_context['is_optional_without_default_value']), |
1211 'is_call_with_document': | 1246 'is_call_with_document': |
1212 # [ConstructorCallWith=Document] | 1247 # [ConstructorCallWith=Document] |
1213 has_extended_attribute_value(interface, | 1248 has_extended_attribute_value(interface, |
1214 'ConstructorCallWith', 'Document'), | 1249 'ConstructorCallWith', 'Document'), |
1215 'is_call_with_execution_context': | 1250 'is_call_with_execution_context': |
1216 # [ConstructorCallWith=ExecutionContext] | 1251 # [ConstructorCallWith=ExecutionContext] |
1217 has_extended_attribute_value(interface, | 1252 has_extended_attribute_value(interface, |
1218 'ConstructorCallWith', 'ExecutionContext'), | 1253 'ConstructorCallWith', 'ExecutionContext'), |
1219 'is_call_with_script_state': | 1254 'is_call_with_script_state': |
1220 # [ConstructorCallWith=ScriptState] | 1255 # [ConstructorCallWith=ScriptState] |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 def property_setter(setter, interface): | 1358 def property_setter(setter, interface): |
1324 if not setter: | 1359 if not setter: |
1325 return None | 1360 return None |
1326 | 1361 |
1327 extended_attributes = setter.extended_attributes | 1362 extended_attributes = setter.extended_attributes |
1328 idl_type = setter.arguments[1].idl_type | 1363 idl_type = setter.arguments[1].idl_type |
1329 idl_type.add_includes_for_type(extended_attributes) | 1364 idl_type.add_includes_for_type(extended_attributes) |
1330 is_call_with_script_state = v8_utilities.has_extended_attribute_value(setter
, 'CallWith', 'ScriptState') | 1365 is_call_with_script_state = v8_utilities.has_extended_attribute_value(setter
, 'CallWith', 'ScriptState') |
1331 is_raises_exception = 'RaisesException' in extended_attributes | 1366 is_raises_exception = 'RaisesException' in extended_attributes |
1332 | 1367 |
1333 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] | 1368 # [LegacyInterfaceTypeChecking] |
1334 has_type_checking_interface = ( | 1369 has_type_checking_interface = ( |
1335 not is_legacy_interface_type_checking(interface, setter) and | 1370 not is_legacy_interface_type_checking(interface, setter) and |
1336 idl_type.is_wrapper_type) | 1371 idl_type.is_wrapper_type) |
1337 | 1372 |
1338 return { | 1373 return { |
1339 'has_exception_state': (is_raises_exception or | 1374 'has_exception_state': (is_raises_exception or |
1340 idl_type.v8_conversion_needs_exception_state), | 1375 idl_type.v8_conversion_needs_exception_state), |
1341 'has_type_checking_interface': has_type_checking_interface, | 1376 'has_type_checking_interface': has_type_checking_interface, |
1342 'idl_type': idl_type.base_type, | 1377 'idl_type': idl_type.base_type, |
1343 'is_call_with_script_state': is_call_with_script_state, | 1378 'is_call_with_script_state': is_call_with_script_state, |
(...skipping 12 matching lines...) Expand all Loading... |
1356 | 1391 |
1357 extended_attributes = deleter.extended_attributes | 1392 extended_attributes = deleter.extended_attributes |
1358 idl_type = deleter.idl_type | 1393 idl_type = deleter.idl_type |
1359 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') | 1394 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') |
1360 return { | 1395 return { |
1361 'is_call_with_script_state': is_call_with_script_state, | 1396 'is_call_with_script_state': is_call_with_script_state, |
1362 'is_custom': 'Custom' in extended_attributes, | 1397 'is_custom': 'Custom' in extended_attributes, |
1363 'is_raises_exception': 'RaisesException' in extended_attributes, | 1398 'is_raises_exception': 'RaisesException' in extended_attributes, |
1364 'name': cpp_name(deleter), | 1399 'name': cpp_name(deleter), |
1365 } | 1400 } |
OLD | NEW |