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

Side by Side Diff: sky/engine/bindings2/scripts/v8_interface.py

Issue 914413004: Add a new bindings2/scripts directory for Dart bindings (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove idlrenderer.py it's not used Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/bindings2/scripts/v8_globals.py ('k') | sky/engine/bindings2/scripts/v8_methods.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 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
39 import idl_definitions 39 import idl_definitions
40 from idl_definitions import IdlOperation 40 from idl_definitions import IdlOperation
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_template_type 47 from v8_types import cpp_template_type
48 import v8_utilities 48 import v8_utilities
49 from v8_utilities import (capitalize, conditional_string, cpp_name, 49 from v8_utilities import (capitalize, cpp_name,
50 has_extended_attribute_value, runtime_enabled_function _name, 50 has_extended_attribute_value,
51 extended_attribute_value_as_list) 51 extended_attribute_value_as_list)
52 52
53 53
54 INTERFACE_H_INCLUDES = frozenset([ 54 INTERFACE_H_INCLUDES = frozenset([
55 'bindings/core/v8/ScriptWrappable.h',
56 'bindings/core/v8/V8Binding.h',
57 'bindings/core/v8/V8DOMWrapper.h',
58 'bindings/core/v8/WrapperTypeInfo.h',
59 'platform/heap/Handle.h', 55 'platform/heap/Handle.h',
60 ]) 56 ])
57
61 INTERFACE_CPP_INCLUDES = frozenset([ 58 INTERFACE_CPP_INCLUDES = frozenset([
62 'bindings/core/v8/ExceptionState.h', 59 'sky/engine/bindings2/exception_state.h',
63 'bindings/core/v8/V8DOMConfiguration.h',
64 'bindings/core/v8/V8HiddenValue.h',
65 'bindings/core/v8/V8ObjectConstructor.h',
66 'core/dom/Document.h', 60 'core/dom/Document.h',
67 'platform/RuntimeEnabledFeatures.h', 61 'base/trace_event/trace_event.h',
68 'platform/TraceEvent.h',
69 'wtf/GetPtr.h', 62 'wtf/GetPtr.h',
70 'wtf/RefPtr.h', 63 'wtf/RefPtr.h',
71 ]) 64 ])
72 65
73 66
74 def interface_context(interface): 67 def interface_context(interface):
75 includes.clear() 68 includes.clear()
76 includes.update(INTERFACE_CPP_INCLUDES) 69 includes.update(INTERFACE_CPP_INCLUDES)
77 header_includes = set(INTERFACE_H_INCLUDES) 70 header_includes = set(INTERFACE_H_INCLUDES)
78 71
79 parent_interface = interface.parent 72 parent_interface = interface.parent
80 if parent_interface: 73 if parent_interface:
81 header_includes.update(v8_types.includes_for_interface(parent_interface) ) 74 header_includes.update(v8_types.includes_for_interface(parent_interface) )
82 extended_attributes = interface.extended_attributes 75 extended_attributes = interface.extended_attributes
83 76
84 is_document = inherits_interface(interface.name, 'Document')
85 if is_document:
86 includes.update(['bindings/core/v8/ScriptController.h',
87 'bindings/core/v8/WindowProxy.h',
88 'core/frame/LocalFrame.h'])
89
90 # [ActiveDOMObject] 77 # [ActiveDOMObject]
91 is_active_dom_object = 'ActiveDOMObject' in extended_attributes 78 is_active_dom_object = 'ActiveDOMObject' in extended_attributes
92 79
93 # [CheckSecurity]
94 is_check_security = 'CheckSecurity' in extended_attributes
95 if is_check_security:
96 includes.add('bindings/core/v8/BindingSecurity.h')
97
98 # [DependentLifetime] 80 # [DependentLifetime]
99 is_dependent_lifetime = 'DependentLifetime' in extended_attributes 81 is_dependent_lifetime = 'DependentLifetime' in extended_attributes
100 82
101 # [Iterable] 83 # [Iterable]
102 iterator_method = None 84 iterator_method = None
103 if 'Iterable' in extended_attributes: 85 if 'Iterable' in extended_attributes:
104 iterator_operation = IdlOperation(interface.idl_name) 86 iterator_operation = IdlOperation(interface.idl_name)
105 iterator_operation.name = 'iterator' 87 iterator_operation.name = 'iterator'
106 iterator_operation.idl_type = IdlType('Iterator') 88 iterator_operation.idl_type = IdlType('Iterator')
107 iterator_operation.extended_attributes['RaisesException'] = None 89 iterator_operation.extended_attributes['RaisesException'] = None
108 iterator_operation.extended_attributes['CallWith'] = 'ScriptState' 90 iterator_operation.extended_attributes['CallWith'] = 'ScriptState'
109 iterator_method = v8_methods.method_context(interface, 91 iterator_method = v8_methods.method_context(interface,
110 iterator_operation) 92 iterator_operation)
111 93
112 # [MeasureAs]
113 is_measure_as = 'MeasureAs' in extended_attributes
114
115 # [SetWrapperReferenceFrom] 94 # [SetWrapperReferenceFrom]
116 reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom') 95 reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom')
117 if reachable_node_function: 96 if reachable_node_function:
118 includes.update(['bindings/core/v8/V8GCController.h', 97 includes.update(['core/dom/Element.h'])
119 'core/dom/Element.h'])
120 98
121 # [SetWrapperReferenceTo] 99 # [SetWrapperReferenceTo]
122 set_wrapper_reference_to_list = [{ 100 set_wrapper_reference_to_list = [{
123 'name': argument.name, 101 'name': argument.name,
124 # FIXME: properly should be: 102 # FIXME: properly should be:
125 # 'cpp_type': argument.idl_type.cpp_type_args(raw_type=True), 103 # 'cpp_type': argument.idl_type.cpp_type_args(raw_type=True),
126 # (if type is non-wrapper type like NodeFilter, normally RefPtr) 104 # (if type is non-wrapper type like NodeFilter, normally RefPtr)
127 # Raw pointers faster though, and NodeFilter hacky anyway. 105 # Raw pointers faster though, and NodeFilter hacky anyway.
128 'cpp_type': argument.idl_type.implemented_as + '*', 106 'cpp_type': argument.idl_type.implemented_as + '*',
129 'idl_type': argument.idl_type, 107 'idl_type': argument.idl_type,
130 'v8_type': v8_types.v8_type(argument.idl_type.name),
131 } for argument in extended_attributes.get('SetWrapperReferenceTo', [])] 108 } for argument in extended_attributes.get('SetWrapperReferenceTo', [])]
132 for set_wrapper_reference_to in set_wrapper_reference_to_list: 109 for set_wrapper_reference_to in set_wrapper_reference_to_list:
133 set_wrapper_reference_to['idl_type'].add_includes_for_type() 110 set_wrapper_reference_to['idl_type'].add_includes_for_type()
134 111
135 # [NotScriptWrappable] 112 # [NotScriptWrappable]
136 is_script_wrappable = 'NotScriptWrappable' not in extended_attributes 113 is_script_wrappable = 'NotScriptWrappable' not in extended_attributes
137 114
138 # [SpecialWrapFor] 115 # [SpecialWrapFor]
139 if 'SpecialWrapFor' in extended_attributes: 116 if 'SpecialWrapFor' in extended_attributes:
140 special_wrap_for = extended_attribute_value_as_list(interface, 'SpecialW rapFor') 117 special_wrap_for = extended_attribute_value_as_list(interface, 'SpecialW rapFor')
141 else: 118 else:
142 special_wrap_for = [] 119 special_wrap_for = []
143 for special_wrap_interface in special_wrap_for: 120 for special_wrap_interface in special_wrap_for:
144 v8_types.add_includes_for_interface(special_wrap_interface) 121 v8_types.add_includes_for_interface(special_wrap_interface)
145 122
146 # [Custom=Wrap], [SetWrapperReferenceFrom] 123 # [Custom=Wrap], [SetWrapperReferenceFrom]
147 has_visit_dom_wrapper = ( 124 has_visit_dom_wrapper = (
148 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or 125 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or
149 reachable_node_function or 126 reachable_node_function or
150 set_wrapper_reference_to_list) 127 set_wrapper_reference_to_list)
151 128
152 wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Nod e') else 'ObjectClassId') 129 wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Nod e') else 'ObjectClassId')
153 130
154 context = { 131 context = {
155 'conditional_string': conditional_string(interface), # [Conditional]
156 'cpp_class': cpp_name(interface), 132 'cpp_class': cpp_name(interface),
157 # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699
158 'has_access_check_callbacks': (is_check_security and
159 interface.name != 'Window' and
160 interface.name != 'EventTarget'),
161 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction]
162 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T oV8'), # [Custom=ToV8]
163 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr ap'), # [Custom=Wrap] 133 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr ap'), # [Custom=Wrap]
164 'has_visit_dom_wrapper': has_visit_dom_wrapper, 134 'has_visit_dom_wrapper': has_visit_dom_wrapper,
165 'header_includes': header_includes, 135 'header_includes': header_includes,
166 'interface_name': interface.name, 136 'interface_name': interface.name,
167 'is_active_dom_object': is_active_dom_object, 137 'is_active_dom_object': is_active_dom_object,
168 'is_check_security': is_check_security,
169 'is_dependent_lifetime': is_dependent_lifetime, 138 'is_dependent_lifetime': is_dependent_lifetime,
170 'is_document': is_document,
171 'is_event_target': inherits_interface(interface.name, 'EventTarget'),
172 'is_exception': interface.is_exception, 139 'is_exception': interface.is_exception,
173 'is_node': inherits_interface(interface.name, 'Node'),
174 'is_script_wrappable': is_script_wrappable, 140 'is_script_wrappable': is_script_wrappable,
175 'iterator_method': iterator_method, 141 'iterator_method': iterator_method,
176 'lifetime': 'Dependent' 142 'lifetime': 'Dependent'
177 if (has_visit_dom_wrapper or 143 if (has_visit_dom_wrapper or
178 is_active_dom_object or 144 is_active_dom_object or
179 is_dependent_lifetime) 145 is_dependent_lifetime)
180 else 'Independent', 146 else 'Independent',
181 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs]
182 'parent_interface': parent_interface, 147 'parent_interface': parent_interface,
183 'pass_cpp_type': cpp_template_type(
184 'PassRefPtr',
185 cpp_name(interface)),
186 'reachable_node_function': reachable_node_function, 148 'reachable_node_function': reachable_node_function,
187 'runtime_enabled_function': runtime_enabled_function_name(interface), # [RuntimeEnabled]
188 'set_wrapper_reference_to_list': set_wrapper_reference_to_list, 149 'set_wrapper_reference_to_list': set_wrapper_reference_to_list,
189 'special_wrap_for': special_wrap_for, 150 'special_wrap_for': special_wrap_for,
190 'v8_class': v8_utilities.v8_class_name(interface),
191 'wrapper_class_id': wrapper_class_id, 151 'wrapper_class_id': wrapper_class_id,
192 } 152 }
193 153
194 # Constructors 154 # Constructors
195 constructors = [constructor_context(interface, constructor) 155 constructors = [constructor_context(interface, constructor)
196 for constructor in interface.constructors 156 for constructor in interface.constructors
197 # FIXME: shouldn't put named constructors with constructors 157 # FIXME: shouldn't put named constructors with constructors
198 # (currently needed for Perl compatibility) 158 # (currently needed for Perl compatibility)
199 # Handle named constructors separately 159 # Handle named constructors separately
200 if constructor.name == 'Constructor'] 160 if constructor.name == 'Constructor']
201 if len(constructors) > 1: 161 if len(constructors) > 1:
202 context['constructor_overloads'] = overloads_context(constructors) 162 context['constructor_overloads'] = overloads_context(constructors)
203 163
204 # [CustomConstructor] 164 # [CustomConstructor]
205 custom_constructors = [{ # Only needed for computing interface length 165 custom_constructors = [{ # Only needed for computing interface length
206 'number_of_required_arguments': 166 'number_of_required_arguments':
207 number_of_required_arguments(constructor), 167 number_of_required_arguments(constructor),
208 } for constructor in interface.custom_constructors] 168 } for constructor in interface.custom_constructors]
209 169
210 # [EventConstructor] 170 # [EventConstructor]
211 has_event_constructor = 'EventConstructor' in extended_attributes 171 has_event_constructor = 'EventConstructor' in extended_attributes
212 any_type_attributes = [attribute for attribute in interface.attributes 172 any_type_attributes = [attribute for attribute in interface.attributes
213 if attribute.idl_type.name == 'Any'] 173 if attribute.idl_type.name == 'Any']
214 if has_event_constructor:
215 includes.add('bindings/core/v8/Dictionary.h')
216 if any_type_attributes:
217 includes.add('bindings/core/v8/SerializedScriptValue.h')
218 174
219 # [NamedConstructor] 175 # [NamedConstructor]
220 named_constructor = named_constructor_context(interface) 176 named_constructor = named_constructor_context(interface)
221 177
222 if (constructors or custom_constructors or has_event_constructor or 178 if (constructors or custom_constructors or has_event_constructor or
223 named_constructor): 179 named_constructor):
224 includes.add('bindings/core/v8/V8ObjectConstructor.h')
225 includes.add('core/frame/LocalDOMWindow.h') 180 includes.add('core/frame/LocalDOMWindow.h')
226 181
227 context.update({ 182 context.update({
228 'any_type_attributes': any_type_attributes, 183 'any_type_attributes': any_type_attributes,
229 'constructors': constructors, 184 'constructors': constructors,
230 'has_custom_constructor': bool(custom_constructors), 185 'has_custom_constructor': bool(custom_constructors),
231 'has_event_constructor': has_event_constructor, 186 'has_event_constructor': has_event_constructor,
232 'interface_length': 187 'interface_length':
233 interface_length(interface, constructors + custom_constructors), 188 interface_length(interface, constructors + custom_constructors),
234 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept ion') == 'Constructor', # [RaisesException=Constructor] 189 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept ion') == 'Constructor', # [RaisesException=Constructor]
235 'named_constructor': named_constructor, 190 'named_constructor': named_constructor,
236 }) 191 })
237 192
238 constants = [constant_context(constant) for constant in interface.constants] 193 constants = [constant_context(constant) for constant in interface.constants]
239 194
240 # Constants 195 # Constants
241 context.update({ 196 context.update({
242 'constants': constants, 197 'constants': constants,
243 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, 198 'has_constant_configuration': True,
244 'has_constant_configuration': any(
245 not constant['runtime_enabled_function']
246 for constant in constants),
247 }) 199 })
248 200
249 # Attributes 201 # Attributes
250 attributes = [v8_attributes.attribute_context(interface, attribute) 202 attributes = [v8_attributes.attribute_context(interface, attribute)
251 for attribute in interface.attributes] 203 for attribute in interface.attributes]
252 context.update({ 204 context.update({
253 'attributes': attributes, 205 'attributes': attributes,
254 'has_accessors': any(attribute['is_expose_js_accessors'] and attribute[' should_be_exposed_to_script'] for attribute in attributes),
255 'has_attribute_configuration': any(
256 not (attribute['is_expose_js_accessors'] or
257 attribute['is_static'] or
258 attribute['runtime_enabled_function'])
259 and attribute['should_be_exposed_to_script']
260 for attribute in attributes),
261 'has_conditional_attributes': any(attribute['exposed_test'] for attribut e in attributes), 206 'has_conditional_attributes': any(attribute['exposed_test'] for attribut e in attributes),
262 'has_constructor_attributes': any(attribute['constructor_type'] for attr ibute in attributes), 207 'has_constructor_attributes': any(attribute['constructor_type'] for attr ibute in attributes),
263 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes), 208 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes),
264 }) 209 })
265 210
266 # Methods 211 # Methods
267 methods = [v8_methods.method_context(interface, method) 212 methods = [v8_methods.method_context(interface, method)
268 for method in interface.operations 213 for method in interface.operations
269 if method.name] # Skip anonymous special operations (methods) 214 if method.name] # Skip anonymous special operations (methods)
270 compute_method_overloads_context(methods) 215 compute_method_overloads_context(methods)
(...skipping 16 matching lines...) Expand all
287 method_configuration_methods = [] 232 method_configuration_methods = []
288 233
289 for method in methods: 234 for method in methods:
290 # Skip all but one method in each set of overloaded methods. 235 # Skip all but one method in each set of overloaded methods.
291 if 'overload_index' in method and 'overloads' not in method: 236 if 'overload_index' in method and 'overloads' not in method:
292 continue 237 continue
293 238
294 if 'overloads' in method: 239 if 'overloads' in method:
295 overloads = method['overloads'] 240 overloads = method['overloads']
296 conditionally_exposed_function = overloads['exposed_test_all'] 241 conditionally_exposed_function = overloads['exposed_test_all']
297 runtime_enabled_function = overloads['runtime_enabled_function_all']
298 has_custom_registration = overloads['has_custom_registration_all'] 242 has_custom_registration = overloads['has_custom_registration_all']
299 else: 243 else:
300 conditionally_exposed_function = method['exposed_test'] 244 conditionally_exposed_function = method['exposed_test']
301 runtime_enabled_function = method['runtime_enabled_function']
302 has_custom_registration = method['has_custom_registration'] 245 has_custom_registration = method['has_custom_registration']
303 246
304 if conditionally_exposed_function: 247 if conditionally_exposed_function:
305 conditionally_enabled_methods.append(method) 248 conditionally_enabled_methods.append(method)
306 continue 249 continue
307 if runtime_enabled_function or has_custom_registration: 250 if has_custom_registration:
308 custom_registration_methods.append(method) 251 custom_registration_methods.append(method)
309 continue 252 continue
310 if method['should_be_exposed_to_script']: 253 method_configuration_methods.append(method)
311 method_configuration_methods.append(method)
312 254
313 for method in methods: 255 for method in methods:
314 # The value of the Function object’s “length” property is a Number 256 # The value of the Function object’s “length” property is a Number
315 # determined as follows: 257 # determined as follows:
316 # 1. Let S be the effective overload set for regular operations (if the 258 # 1. Let S be the effective overload set for regular operations (if the
317 # operation is a regular operation) or for static operations (if the 259 # operation is a regular operation) or for static operations (if the
318 # operation is a static operation) with identifier id on interface I and 260 # operation is a static operation) with identifier id on interface I and
319 # with argument count 0. 261 # with argument count 0.
320 # 2. Return the length of the shortest argument list of the entries in S . 262 # 2. Return the length of the shortest argument list of the entries in S .
321 # FIXME: This calculation doesn't take into account whether runtime 263 # FIXME: This calculation doesn't take into account whether runtime
322 # enabled overloads are actually enabled, so length may be incorrect. 264 # enabled overloads are actually enabled, so length may be incorrect.
323 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); 265 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x);
324 # should have length 1 if Foo is not enabled, but length 0 if it is. 266 # should have length 1 if Foo is not enabled, but length 0 if it is.
325 method['length'] = (method['overloads']['minarg'] if 'overloads' in meth od else 267 method['length'] = (method['overloads']['minarg'] if 'overloads' in meth od else
326 method['number_of_required_arguments']) 268 method['number_of_required_arguments'])
327 269
328 context.update({ 270 context.update({
329 'conditionally_enabled_methods': conditionally_enabled_methods, 271 'conditionally_enabled_methods': conditionally_enabled_methods,
330 'custom_registration_methods': custom_registration_methods, 272 'custom_registration_methods': custom_registration_methods,
331 'has_origin_safe_method_setter': any(
332 method['is_check_security_for_frame'] and not method['is_read_only']
333 for method in methods),
334 'has_private_script': any(attribute['is_implemented_in_private_script'] for attribute in attributes) or
335 any(method['is_implemented_in_private_script'] for method in methods ),
336 'method_configuration_methods': method_configuration_methods, 273 'method_configuration_methods': method_configuration_methods,
337 'methods': methods, 274 'methods': methods,
338 }) 275 })
339 276
340 context.update({ 277 context.update({
341 'indexed_property_getter': indexed_property_getter(interface), 278 'indexed_property_getter': indexed_property_getter(interface),
342 'indexed_property_setter': indexed_property_setter(interface), 279 'indexed_property_setter': indexed_property_setter(interface),
343 'indexed_property_deleter': indexed_property_deleter(interface), 280 'indexed_property_deleter': indexed_property_deleter(interface),
344 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, 281 'is_override_builtins': 'OverrideBuiltins' in extended_attributes,
345 'named_property_getter': named_property_getter(interface), 282 'named_property_getter': named_property_getter(interface),
346 'named_property_setter': named_property_setter(interface), 283 'named_property_setter': named_property_setter(interface),
347 'named_property_deleter': named_property_deleter(interface), 284 'named_property_deleter': named_property_deleter(interface),
348 }) 285 })
349 286
350 return context 287 return context
351 288
352 289
353 # [DeprecateAs], [Reflect], [RuntimeEnabled] 290 # [DeprecateAs], [Reflect]
354 def constant_context(constant): 291 def constant_context(constant):
355 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted 292 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted
356 # in C++. 293 # in C++.
357 if constant.idl_type.name == 'String': 294 if constant.idl_type.name == 'String':
358 value = '"%s"' % constant.value 295 value = '"%s"' % constant.value
359 else: 296 else:
360 value = constant.value 297 value = constant.value
361 298
362 extended_attributes = constant.extended_attributes 299 extended_attributes = constant.extended_attributes
363 return { 300 return {
364 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), 301 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'),
365 'idl_type': constant.idl_type.name, 302 'idl_type': constant.idl_type.name,
366 'name': constant.name, 303 'name': constant.name,
367 # FIXME: use 'reflected_name' as correct 'name' 304 # FIXME: use 'reflected_name' as correct 'name'
368 'reflected_name': extended_attributes.get('Reflect', constant.name), 305 'reflected_name': extended_attributes.get('Reflect', constant.name),
369 'runtime_enabled_function': runtime_enabled_function_name(constant),
370 'value': value, 306 'value': value,
371 } 307 }
372 308
373 309
374 ################################################################################ 310 ################################################################################
375 # Overloads 311 # Overloads
376 ################################################################################ 312 ################################################################################
377 313
378 def compute_method_overloads_context(methods): 314 def compute_method_overloads_context(methods):
379 # Regular methods 315 # Regular methods
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 lengths = [length for length, _ in effective_overloads_by_length] 366 lengths = [length for length, _ in effective_overloads_by_length]
431 name = overloads[0].get('name', '<constructor>') 367 name = overloads[0].get('name', '<constructor>')
432 368
433 # Check and fail if all overloads with the shortest acceptable arguments 369 # Check and fail if all overloads with the shortest acceptable arguments
434 # list are runtime enabled, since we would otherwise set 'length' on the 370 # list are runtime enabled, since we would otherwise set 'length' on the
435 # function object to an incorrect value when none of those overloads were 371 # function object to an incorrect value when none of those overloads were
436 # actually enabled at runtime. The exception is if all overloads are 372 # actually enabled at runtime. The exception is if all overloads are
437 # controlled by the same runtime enabled feature, in which case there would 373 # controlled by the same runtime enabled feature, in which case there would
438 # be no function object at all if it is not enabled. 374 # be no function object at all if it is not enabled.
439 shortest_overloads = effective_overloads_by_length[0][1] 375 shortest_overloads = effective_overloads_by_length[0][1]
440 if (all(method.get('runtime_enabled_function')
441 for method, _, _ in shortest_overloads) and
442 not common_value(overloads, 'runtime_enabled_function')):
443 raise ValueError('Function.length of %s depends on runtime enabled featu res' % name)
444 376
445 # Check and fail if overloads disagree on any of the extended attributes 377 # Check and fail if overloads disagree on any of the extended attributes
446 # that affect how the method should be registered. 378 # that affect how the method should be registered.
447 # Skip the check for overloaded constructors, since they don't support any 379 # Skip the check for overloaded constructors, since they don't support any
448 # of the extended attributes in question. 380 # of the extended attributes in question.
449 if not overloads[0].get('is_constructor'): 381 if not overloads[0].get('is_constructor'):
450 overload_extended_attributes = [ 382 overload_extended_attributes = [
451 method['custom_registration_extended_attributes'] 383 method['custom_registration_extended_attributes']
452 for method in overloads] 384 for method in overloads]
453 for extended_attribute in v8_methods.CUSTOM_REGISTRATION_EXTENDED_ATTRIB UTES: 385 for extended_attribute in v8_methods.CUSTOM_REGISTRATION_EXTENDED_ATTRIB UTES:
454 if common_key(overload_extended_attributes, extended_attribute) is N one: 386 if common_key(overload_extended_attributes, extended_attribute) is N one:
455 raise ValueError('Overloads of %s have conflicting extended attr ibute %s' 387 raise ValueError('Overloads of %s have conflicting extended attr ibute %s'
456 % (name, extended_attribute)) 388 % (name, extended_attribute))
457 389
458 # Check and fail if overloads disagree about whether the return type 390 # Check and fail if overloads disagree about whether the return type
459 # is a Promise or not. 391 # is a Promise or not.
460 promise_overload_count = sum(1 for method in overloads if method.get('idl_ty pe') == 'Promise') 392 promise_overload_count = sum(1 for method in overloads if method.get('idl_ty pe') == 'Promise')
461 if promise_overload_count not in (0, len(overloads)): 393 if promise_overload_count not in (0, len(overloads)):
462 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes' 394 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes'
463 % (name)) 395 % (name))
464 396
465 return { 397 return {
466 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs]
467 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ] 398 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ]
468 'has_custom_registration_all': common_value(overloads, 'has_custom_regis tration'), 399 'has_custom_registration_all': common_value(overloads, 'has_custom_regis tration'),
469 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th),
470 # 1. Let maxarg be the length of the longest type list of the 400 # 1. Let maxarg be the length of the longest type list of the
471 # entries in S. 401 # entries in S.
472 'maxarg': lengths[-1], 402 'maxarg': lengths[-1],
473 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs]
474 'minarg': lengths[0], 403 'minarg': lengths[0],
475 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled]
476 'valid_arities': lengths 404 'valid_arities': lengths
477 # Only need to report valid arities if there is a gap in the 405 # Only need to report valid arities if there is a gap in the
478 # sequence of possible lengths, otherwise invalid length means 406 # sequence of possible lengths, otherwise invalid length means
479 # "not enough arguments". 407 # "not enough arguments".
480 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, 408 if lengths[-1] - lengths[0] != len(lengths) - 1 else None,
481 } 409 }
482 410
483 411
484 def effective_overload_set(F): 412 def effective_overload_set(F):
485 """Returns the effective overload set of an overloaded function. 413 """Returns the effective overload set of an overloaded function.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 distinguishing_argument_type_names = [type_list[index] 572 distinguishing_argument_type_names = [type_list[index]
645 for type_list in type_lists] 573 for type_list in type_lists]
646 if (len(set(distinguishing_argument_type_names)) != 574 if (len(set(distinguishing_argument_type_names)) !=
647 len(distinguishing_argument_type_names)): 575 len(distinguishing_argument_type_names)):
648 raise ValueError('Types in distinguishing argument are not distinct:\n' 576 raise ValueError('Types in distinguishing argument are not distinct:\n'
649 '%s' % distinguishing_argument_type_names) 577 '%s' % distinguishing_argument_type_names)
650 578
651 return index 579 return index
652 580
653 581
654 def length_tests_methods(effective_overloads_by_length):
655 """Returns sorted list of resolution tests and associated methods, by length .
656
657 This builds the main data structure for the overload resolution loop.
658 For a given argument length, bindings test argument at distinguishing
659 argument index, in order given by spec: if it is compatible with
660 (optionality or) type required by an overloaded method, resolve to that
661 method.
662
663 Returns:
664 [(length, [(test, method)])]
665 """
666 return [(length, list(resolution_tests_methods(effective_overloads)))
667 for length, effective_overloads in effective_overloads_by_length]
668
669
670 def resolution_tests_methods(effective_overloads):
671 """Yields resolution test and associated method, in resolution order, for ef fective overloads of a given length.
672
673 This is the heart of the resolution algorithm.
674 http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
675
676 Note that a given method can be listed multiple times, with different tests!
677 This is to handle implicit type conversion.
678
679 Returns:
680 [(test, method)]
681 """
682 methods = [effective_overload[0]
683 for effective_overload in effective_overloads]
684 if len(methods) == 1:
685 # If only one method with a given length, no test needed
686 yield 'true', methods[0]
687 return
688
689 # 6. If there is more than one entry in S, then set d to be the
690 # distinguishing argument index for the entries of S.
691 index = distinguishing_argument_index(effective_overloads)
692 # (7-9 are for handling |undefined| values for optional arguments before
693 # the distinguishing argument (as “missing”), so you can specify only some
694 # optional arguments. We don’t support this, so we skip these steps.)
695 # 10. If i = d, then:
696 # (d is the distinguishing argument index)
697 # 1. Let V be argi.
698 # Note: This is the argument that will be used to resolve which
699 # overload is selected.
700 cpp_value = 'info[%s]' % index
701
702 # Extract argument and IDL type to simplify accessing these in each loop.
703 arguments = [method['arguments'][index] for method in methods]
704 arguments_methods = zip(arguments, methods)
705 idl_types = [argument['idl_type_object'] for argument in arguments]
706 idl_types_methods = zip(idl_types, methods)
707
708 # We can’t do a single loop through all methods or simply sort them, because
709 # a method may be listed in multiple steps of the resolution algorithm, and
710 # which test to apply differs depending on the step.
711 #
712 # Instead, we need to go through all methods at each step, either finding
713 # first match (if only one test is allowed) or filtering to matches (if
714 # multiple tests are allowed), and generating an appropriate tests.
715
716 # 2. If V is undefined, and there is an entry in S whose list of
717 # optionality values has “optional” at index i, then remove from S all
718 # other entries.
719 try:
720 method = next(method for argument, method in arguments_methods
721 if argument['is_optional'])
722 test = '%s->IsUndefined()' % cpp_value
723 yield test, method
724 except StopIteration:
725 pass
726
727 # 3. Otherwise: if V is null or undefined, and there is an entry in S that
728 # has one of the following types at position i of its type list,
729 # • a nullable type
730 try:
731 method = next(method for idl_type, method in idl_types_methods
732 if idl_type.is_nullable)
733 test = 'isUndefinedOrNull(%s)' % cpp_value
734 yield test, method
735 except StopIteration:
736 pass
737
738 # 4. Otherwise: if V is a platform object – but not a platform array
739 # object – and there is an entry in S that has one of the following
740 # types at position i of its type list,
741 # • an interface type that V implements
742 # (Unlike most of these tests, this can return multiple methods, since we
743 # test if it implements an interface. Thus we need a for loop, not a next.)
744 # (We distinguish wrapper types from built-in interface types.)
745 for idl_type, method in ((idl_type, method)
746 for idl_type, method in idl_types_methods
747 if idl_type.is_wrapper_type):
748 test = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'.forma t(idl_type=idl_type.base_type, cpp_value=cpp_value)
749 yield test, method
750
751 # 8. Otherwise: if V is any kind of object except for a native Date object,
752 # a native RegExp object, and there is an entry in S that has one of the
753 # following types at position i of its type list,
754 # • an array type
755 # • a sequence type
756 # ...
757 # • a dictionary
758 try:
759 idl_type, method = next((idl_type, method)
760 for idl_type, method in idl_types_methods
761 if (idl_type.native_array_element_type or
762 idl_type.is_dictionary or
763 idl_type.name == 'Dictionary'))
764 if idl_type.native_array_element_type:
765 # (We test for Array instead of generic Object to type-check.)
766 # FIXME: test for Object during resolution, then have type check for
767 # Array in overloaded method: http://crbug.com/262383
768 test = '%s->IsArray()' % cpp_value
769 else:
770 # FIXME: should be '{1}->IsObject() && !{1}->IsDate() && !{1}->IsReg Exp()'.format(cpp_value)
771 # FIXME: the IsDate and IsRegExp checks can be skipped if we've
772 # already generated tests for them.
773 test = '%s->IsObject()' % cpp_value
774 yield test, method
775 except StopIteration:
776 pass
777
778 # (Check for exact type matches before performing automatic type conversion;
779 # only needed if distinguishing between primitive types.)
780 if len([idl_type.is_primitive_type for idl_type in idl_types]) > 1:
781 # (Only needed if match in step 11, otherwise redundant.)
782 if any(idl_type.is_string_type or idl_type.is_enum
783 for idl_type in idl_types):
784 # 10. Otherwise: if V is a Number value, and there is an entry in S
785 # that has one of the following types at position i of its type
786 # list,
787 # • a numeric type
788 try:
789 method = next(method for idl_type, method in idl_types_methods
790 if idl_type.is_numeric_type)
791 test = '%s->IsNumber()' % cpp_value
792 yield test, method
793 except StopIteration:
794 pass
795
796 # (Perform automatic type conversion, in order. If any of these match,
797 # that’s the end, and no other tests are needed.) To keep this code simple,
798 # we rely on the C++ compiler's dead code elimination to deal with the
799 # redundancy if both cases below trigger.
800
801 # 11. Otherwise: if there is an entry in S that has one of the following
802 # types at position i of its type list,
803 # • DOMString
804 # • ByteString
805 # • ScalarValueString [a DOMString typedef, per definition.]
806 # • an enumeration type
807 try:
808 method = next(method for idl_type, method in idl_types_methods
809 if idl_type.is_string_type or idl_type.is_enum)
810 yield 'true', method
811 except StopIteration:
812 pass
813
814 # 12. Otherwise: if there is an entry in S that has one of the following
815 # types at position i of its type list,
816 # • a numeric type
817 try:
818 method = next(method for idl_type, method in idl_types_methods
819 if idl_type.is_numeric_type)
820 yield 'true', method
821 except StopIteration:
822 pass
823
824
825 ################################################################################ 582 ################################################################################
826 # Utility functions 583 # Utility functions
827 ################################################################################ 584 ################################################################################
828 585
829 def Counter(iterable): 586 def Counter(iterable):
830 # Once using Python 2.7, using collections.Counter 587 # Once using Python 2.7, using collections.Counter
831 counter = defaultdict(lambda: 0) 588 counter = defaultdict(lambda: 0)
832 for item in iterable: 589 for item in iterable:
833 counter[item] += 1 590 counter[item] += 1
834 return counter 591 return counter
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), 746 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')),
990 'is_custom_property_enumerator': has_extended_attribute_value( 747 'is_custom_property_enumerator': has_extended_attribute_value(
991 getter, 'Custom', 'PropertyEnumerator'), 748 getter, 'Custom', 'PropertyEnumerator'),
992 'is_custom_property_query': has_extended_attribute_value( 749 'is_custom_property_query': has_extended_attribute_value(
993 getter, 'Custom', 'PropertyQuery'), 750 getter, 'Custom', 'PropertyQuery'),
994 'is_enumerable': 'NotEnumerable' not in extended_attributes, 751 'is_enumerable': 'NotEnumerable' not in extended_attributes,
995 'is_null_expression': is_null_expression(idl_type), 752 'is_null_expression': is_null_expression(idl_type),
996 'is_raises_exception': is_raises_exception, 753 'is_raises_exception': is_raises_exception,
997 'name': cpp_name(getter), 754 'name': cpp_name(getter),
998 'union_arguments': union_arguments, 755 'union_arguments': union_arguments,
999 'v8_set_return_value': idl_type.v8_set_return_value('result', extended_a ttributes=extended_attributes, script_wrappable='impl', release=idl_type.release ),
1000 } 756 }
1001 757
1002 758
1003 def property_setter(setter): 759 def property_setter(setter):
1004 idl_type = setter.arguments[1].idl_type 760 idl_type = setter.arguments[1].idl_type
1005 extended_attributes = setter.extended_attributes 761 extended_attributes = setter.extended_attributes
1006 is_raises_exception = 'RaisesException' in extended_attributes 762 is_raises_exception = 'RaisesException' in extended_attributes
1007 return { 763 return {
1008 'has_type_checking_interface': 764 'has_type_checking_interface':
1009 has_extended_attribute_value(setter, 'TypeChecking', 'Interface') an d 765 has_extended_attribute_value(setter, 'TypeChecking', 'Interface') an d
1010 idl_type.is_wrapper_type, 766 idl_type.is_wrapper_type,
1011 'idl_type': idl_type.base_type, 767 'idl_type': idl_type.base_type,
1012 'is_custom': 'Custom' in extended_attributes, 768 'is_custom': 'Custom' in extended_attributes,
1013 'has_exception_state': is_raises_exception or 769 'has_exception_state': is_raises_exception or
1014 idl_type.is_integer_type, 770 idl_type.is_integer_type,
1015 'is_raises_exception': is_raises_exception, 771 'is_raises_exception': is_raises_exception,
1016 'name': cpp_name(setter), 772 'name': cpp_name(setter),
1017 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value(
1018 extended_attributes, 'v8Value', 'propertyValue'),
1019 } 773 }
1020 774
1021 775
1022 def property_deleter(deleter): 776 def property_deleter(deleter):
1023 idl_type = deleter.idl_type 777 idl_type = deleter.idl_type
1024 if str(idl_type) != 'boolean': 778 if str(idl_type) != 'boolean':
1025 raise Exception( 779 raise Exception(
1026 'Only deleters with boolean type are allowed, but type is "%s"' % 780 'Only deleters with boolean type are allowed, but type is "%s"' %
1027 idl_type) 781 idl_type)
1028 extended_attributes = deleter.extended_attributes 782 extended_attributes = deleter.extended_attributes
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 deleter = next( 885 deleter = next(
1132 method 886 method
1133 for method in interface.operations 887 for method in interface.operations
1134 if ('deleter' in method.specials and 888 if ('deleter' in method.specials and
1135 len(method.arguments) == 1 and 889 len(method.arguments) == 1 and
1136 str(method.arguments[0].idl_type) == 'DOMString')) 890 str(method.arguments[0].idl_type) == 'DOMString'))
1137 except StopIteration: 891 except StopIteration:
1138 return None 892 return None
1139 893
1140 return property_deleter(deleter) 894 return property_deleter(deleter)
OLDNEW
« no previous file with comments | « sky/engine/bindings2/scripts/v8_globals.py ('k') | sky/engine/bindings2/scripts/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698