18abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# Copyright (C) 2013 Google Inc. All rights reserved. 28abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# 38abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# Redistribution and use in source and binary forms, with or without 48abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# modification, are permitted provided that the following conditions are 58abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# met: 68abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# 78abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# * Redistributions of source code must retain the above copyright 88abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# notice, this list of conditions and the following disclaimer. 98abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# * Redistributions in binary form must reproduce the above 108abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# copyright notice, this list of conditions and the following disclaimer 118abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# in the documentation and/or other materials provided with the 128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# distribution. 138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# * Neither the name of Google Inc. nor the names of its 148abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# contributors may be used to endorse or promote products derived from 158abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# this software without specific prior written permission. 168abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# 178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 258abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 268abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 278abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 288abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)"""Generate template values for an interface. 309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)FIXME: Not currently used in build. 329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)This is a rewrite of the Perl IDL compiler in Python, but is not complete. 339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)Once it is complete, we will switch all IDL files over to Python at once. 349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)Until then, please work on the Perl IDL compiler. 359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)For details, see bug http://crbug.com/239771 369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)""" 378abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 388abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)import v8_attributes 39f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)from v8_globals import includes 40f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)import v8_methods 4151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)import v8_types 42f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)import v8_utilities 43e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)from v8_utilities import capitalize, conditional_string, cpp_name, has_extended_attribute, has_extended_attribute_value, runtime_enabled_function_name 448abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 458abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 468abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)INTERFACE_H_INCLUDES = set([ 478abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 'bindings/v8/V8Binding.h', 48a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'bindings/v8/V8DOMWrapper.h', 49a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'bindings/v8/WrapperTypeInfo.h', 508abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)]) 518abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)INTERFACE_CPP_INCLUDES = set([ 528abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 'RuntimeEnabledFeatures.h', 53e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'bindings/v8/ExceptionState.h', 54a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'bindings/v8/V8DOMConfiguration.h', 558abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 'core/dom/ContextFeatures.h', 568abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 'core/dom/Document.h', 571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 'platform/TraceEvent.h', 588abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)]) 598abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 608abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 618abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)def generate_interface(interface): 62f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) includes.clear() 63f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) includes.update(INTERFACE_CPP_INCLUDES) 64a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) header_includes = INTERFACE_H_INCLUDES 65a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 66a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) parent_interface = interface.parent 67a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if parent_interface: 68a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) header_includes.update(v8_types.includes_for_type(parent_interface)) 6951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) extended_attributes = interface.extended_attributes 708abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 71a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [CheckSecurity] 7251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) is_check_security = 'CheckSecurity' in extended_attributes 7351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if is_check_security: 74e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) includes.add('bindings/v8/BindingSecurity.h') 7551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 76a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [GenerateVisitDOMWrapper] 77a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) generate_visit_dom_wrapper_function = extended_attributes.get('GenerateVisitDOMWrapper') 78a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if generate_visit_dom_wrapper_function: 79a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) includes.update(['bindings/v8/V8GCController.h', 80a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'core/dom/Element.h']) 81a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 82a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [MeasureAs] 83a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) is_measure_as = 'MeasureAs' in extended_attributes 84a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if is_measure_as: 85a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) includes.add('core/frame/UseCounter.h') 86a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 87a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [SpecialWrapFor] 88a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if 'SpecialWrapFor' in extended_attributes: 89a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) special_wrap_for = extended_attributes['SpecialWrapFor'].split('|') 90a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) else: 91a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) special_wrap_for = [] 92a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) for special_wrap_interface in special_wrap_for: 93a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) v8_types.add_includes_for_type(special_wrap_interface) 94a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 95a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # Constructors 96e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) constructors = [generate_constructor(interface, constructor) 97e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) for constructor in interface.constructors 98e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # FIXME: shouldn't put named constructors with constructors 99e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # (currently needed for Perl compatibility) 100e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # Handle named constructors separately 101e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if constructor.name == 'Constructor'] 102e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) generate_constructor_overloads(constructors) 103e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 104e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # [CustomConstructor] 105e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) has_custom_constructor = 'CustomConstructor' in extended_attributes 106a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 107a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [EventConstructor] 108a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) has_event_constructor = 'EventConstructor' in extended_attributes 109e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) any_type_attributes = [attribute for attribute in interface.attributes 110e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if attribute.idl_type == 'any'] 111a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if has_event_constructor: 112e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) includes.add('bindings/v8/Dictionary.h') 113e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if any_type_attributes: 114a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) includes.add('bindings/v8/SerializedScriptValue.h') 115a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 116e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # [NamedConstructor] 117e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if 'NamedConstructor' in extended_attributes: 118e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # FIXME: parser should return named constructor separately; 119e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # included in constructors (and only name stored in extended attribute) 120e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # for Perl compatibility 121e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) named_constructor = {'name': extended_attributes['NamedConstructor']} 122e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) else: 123e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) named_constructor = None 124e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 125e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if (constructors or has_custom_constructor or has_event_constructor or 126e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) named_constructor): 127e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) includes.add('bindings/v8/V8ObjectConstructor.h') 128e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 1298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) template_contents = { 130e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'any_type_attributes': any_type_attributes, 13151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'conditional_string': conditional_string(interface), # [Conditional] 132e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'constructors': constructors, 133a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'cpp_class': cpp_name(interface), 134a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'generate_visit_dom_wrapper_function': generate_visit_dom_wrapper_function, 135e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'has_custom_constructor': has_custom_constructor, 136a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'has_custom_legacy_call_as_function': has_extended_attribute_value(interface, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] 137a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'ToV8'), # [Custom=ToV8] 138a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wrap'), # [Custom=Wrap] 139a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'has_event_constructor': has_event_constructor, 140a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'has_visit_dom_wrapper': ( 141a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [Custom=Wrap], [GenerateVisitDOMWrapper] 142a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or 143a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'GenerateVisitDOMWrapper' in extended_attributes), 144a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'header_includes': header_includes, 145e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'interface_length': interface_length(interface, constructors), 146f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 'interface_name': interface.name, 14751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'is_active_dom_object': 'ActiveDOMObject' in extended_attributes, # [ActiveDOMObject] 14851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'is_check_security': is_check_security, 149a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'is_constructor_call_with_document': has_extended_attribute_value( 150a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) interface, 'ConstructorCallWith', 'Document'), # [ConstructorCallWith=Document] 151a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'is_constructor_call_with_execution_context': has_extended_attribute_value( 152a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) interface, 'ConstructorCallWith', 'ExecutionContext'), # [ConstructorCallWith=ExeuctionContext] 153e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor] 15451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'is_dependent_lifetime': 'DependentLifetime' in extended_attributes, # [DependentLifetime] 155e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'is_event_target': inherits_interface(interface, 'EventTarget'), 156e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'is_node': inherits_interface(interface, 'Node'), 157a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] 158e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'named_constructor': named_constructor, 159a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'parent_interface': parent_interface, 160a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'runtime_enabled_function': runtime_enabled_function_name(interface), # [RuntimeEnabled] 161a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'special_wrap_for': special_wrap_for, 162a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'v8_class': v8_utilities.v8_class_name(interface), 163f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 164f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 165f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) template_contents.update({ 1668abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 'constants': [generate_constant(constant) for constant in interface.constants], 16751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, 168f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) }) 169f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 170f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) attributes = [v8_attributes.generate_attribute(interface, attribute) 171f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for attribute in interface.attributes] 172f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) template_contents.update({ 173f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 'attributes': attributes, 17451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'has_accessors': any(attribute['is_expose_js_accessors'] for attribute in attributes), 17551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'has_constructor_attributes': any(attribute['constructor_type'] for attribute in attributes), 176a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'has_per_context_enabled_attributes': any(attribute['per_context_enabled_function'] for attribute in attributes), 177f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes), 178f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) }) 179f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 18051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) methods = [v8_methods.generate_method(interface, method) 18151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for method in interface.operations] 18251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) generate_overloads(methods) 18351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for method in methods: 18451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method['do_generate_method_configuration'] = ( 18551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method['do_not_check_signature'] and 186a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) not method['per_context_enabled_function'] and 18751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # For overloaded methods, only generate one accessor 18851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ('overload_index' not in method or method['overload_index'] == 1)) 18951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 19051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) template_contents.update({ 19151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'has_origin_safe_method_setter': any( 19251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method['is_check_security_for_frame'] and not method['is_read_only'] 19351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for method in methods), 19451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'has_method_configuration': any(method['do_generate_method_configuration'] for method in methods), 195a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'has_per_context_enabled_methods': any(method['per_context_enabled_function'] for method in methods), 19651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'methods': methods, 19751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) }) 198f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1998abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) return template_contents 2008abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 2018abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 202f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)# [DeprecateAs], [Reflect], [RuntimeEnabled] 2038abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)def generate_constant(constant): 2048abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted 2058abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) # in C++. 206f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if constant.idl_type == 'DOMString': 2078abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) value = '"%s"' % constant.value 2088abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) else: 2098abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) value = constant.value 2108abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 2118abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) constant_parameter = { 2128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 'name': constant.name, 2138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) # FIXME: use 'reflected_name' as correct 'name' 214f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 'reflected_name': constant.extended_attributes.get('Reflect', constant.name), 215a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 'runtime_enabled_function': runtime_enabled_function_name(constant), 216f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 'value': value, 2178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 2188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) return constant_parameter 21951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 22051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 221e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)# Overloads 222e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 22351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)def generate_overloads(methods): 22451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) generate_overloads_by_type(methods, is_static=False) # Regular methods 22551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) generate_overloads_by_type(methods, is_static=True) 22651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 22751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 22851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)def generate_overloads_by_type(methods, is_static): 22951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # Generates |overloads| template values and modifies |methods| in place; 23051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # |is_static| flag used (instead of partitioning list in 2) because need to 23151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # iterate over original list of methods to modify in place 23251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method_counts = {} 23351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for method in methods: 23451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if method['is_static'] != is_static: 23551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) continue 23651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) name = method['name'] 23751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method_counts.setdefault(name, 0) 23851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method_counts[name] += 1 23951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 24051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # Filter to only methods that are actually overloaded 24151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) overloaded_method_counts = dict((name, count) 24251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for name, count in method_counts.iteritems() 24351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if count > 1) 24451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 24551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # Add overload information only to overloaded methods, so template code can 24651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # easily verify if a function is overloaded 24751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method_overloads = {} 24851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for method in methods: 24951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) name = method['name'] 25051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (method['is_static'] != is_static or 25151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) name not in overloaded_method_counts): 25251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) continue 25351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # Overload index includes self, so first append, then compute index 25451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method_overloads.setdefault(name, []).append(method) 25551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method.update({ 25651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'overload_index': len(method_overloads[name]), 25751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'overload_resolution_expression': overload_resolution_expression(method), 25851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) }) 25951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 26051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # Resolution function is generated after last overloaded function; 26151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # package necessary information into |method.overloads| for that method. 26251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for method in methods: 26351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (method['is_static'] != is_static or 26451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'overload_index' not in method): 26551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) continue 26651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) name = method['name'] 26751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if method['overload_index'] != overloaded_method_counts[name]: 26851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) continue 26951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) overloads = method_overloads[name] 27051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) method['overloads'] = { 27151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'name': name, 27251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'methods': overloads, 27351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 'minimum_number_of_required_arguments': min( 27451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) overload['number_of_required_arguments'] 27551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for overload in overloads), 27651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 27751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 27851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 27951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)def overload_resolution_expression(method): 28051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # Expression is an OR of ANDs: each term in the OR corresponds to a 28151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # possible argument count for a given method, with type checks. 28251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # FIXME: Blink's overload resolution algorithm is incorrect, per: 28351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # https://code.google.com/p/chromium/issues/detail?id=293561 28451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # Properly: 28551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # 1. Compute effective overload set. 28651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # 2. First check type list length. 28751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # 3. If multiple entries for given length, compute distinguishing argument 28851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # index and have check for that type. 28951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) arguments = method['arguments'] 29051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) overload_checks = [overload_check_expression(method, index) 29151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # check *omitting* optional arguments at |index| and up: 29251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # index 0 => argument_count 0 (no arguments) 29351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # index 1 => argument_count 1 (index 0 argument only) 29451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for index, argument in enumerate(arguments) 29551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if argument['is_optional']] 29651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # FIXME: this is wrong if a method has optional arguments and a variadic 29751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # one, though there are not yet any examples of this 29851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if not method['is_variadic']: 29951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # Includes all optional arguments (len = last index + 1) 30051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) overload_checks.append(overload_check_expression(method, len(arguments))) 30151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return ' || '.join('(%s)' % check for check in overload_checks) 30251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 30351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 30451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)def overload_check_expression(method, argument_count): 30551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) overload_checks = ['info.Length() == %s' % argument_count] 30651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) arguments = method['arguments'][:argument_count] 30751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) overload_checks.extend(overload_check_argument(index, argument) 30851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for index, argument in 30951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) enumerate(arguments)) 31051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return ' && '.join('(%s)' % check for check in overload_checks if check) 31151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 31251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 31351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)def overload_check_argument(index, argument): 31451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) cpp_value = 'info[%s]' % index 31551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) idl_type = argument['idl_type'] 31651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) # FIXME: proper type checking, sharing code with attributes and methods 31751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if idl_type == 'DOMString' and argument['is_strict_type_checking']: 31851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return ' || '.join(['%s->IsNull()' % cpp_value, 31951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) '%s->IsUndefined()' % cpp_value, 32051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) '%s->IsString()' % cpp_value, 32151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) '%s->IsObject()' % cpp_value]) 32251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if v8_types.array_or_sequence_type(idl_type): 32351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return '%s->IsArray()' % cpp_value 32451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if v8_types.is_wrapper_type(idl_type): 32551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate(), worldType(info.GetIsolate()))'.format(idl_type=idl_type, cpp_value=cpp_value) 32651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if argument['is_nullable']: 32751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) 32851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return type_check 32951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return None 330a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 331a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 332e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)# Constructors 333e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 334e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)# [Constructor] 335e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)def generate_constructor(interface, constructor): 336e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return { 337e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'argument_list': constructor_argument_list(interface, constructor), 338e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'arguments': [constructor_argument(argument, index) 339e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) for index, argument in enumerate(constructor.arguments)], 340e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'is_constructor': True, 341e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'is_variadic': False, # Required for overload resolution 342e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'number_of_required_arguments': 343e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) len([argument for argument in constructor.arguments 344e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if not argument.is_optional]), 345e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) } 346e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 347e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 348e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)def constructor_argument_list(interface, constructor): 349a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) arguments = [] 350a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [ConstructorCallWith=ExecutionContext] 351a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if has_extended_attribute_value(interface, 'ConstructorCallWith', 'ExecutionContext'): 352a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) arguments.append('context') 353a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [ConstructorCallWith=Document] 354a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document'): 355a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) arguments.append('document') 356e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 357e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) arguments.extend([argument.name for argument in constructor.arguments]) 358e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 359a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) # [RaisesException=Constructor] 360a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if interface.extended_attributes.get('RaisesException') == 'Constructor': 361a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) arguments.append('exceptionState') 362e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 363a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return arguments 364e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 365e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 366e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)def constructor_argument(argument, index): 367e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return { 368e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'has_default': 'Default' in argument.extended_attributes, 369e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'idl_type': argument.idl_type, 370e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'index': index, 371e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'is_nullable': False, # Required for overload resolution 372e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'is_optional': argument.is_optional, 373e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'is_strict_type_checking': False, # Required for overload resolution 374e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'name': argument.name, 375e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'v8_value_to_local_cpp_value': 376e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) v8_methods.v8_value_to_local_cpp_value(argument, index), 377e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) } 378e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 379e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 380e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)def generate_constructor_overloads(constructors): 381e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if len(constructors) <= 1: 382e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return 383e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) for overload_index, constructor in enumerate(constructors): 384e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) constructor.update({ 385e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'overload_index': overload_index + 1, 386e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'overload_resolution_expression': 387e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) overload_resolution_expression(constructor), 388e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) }) 389e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 390e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 391e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)def interface_length(interface, constructors): 392e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # Docs: http://heycam.github.io/webidl/#es-interface-call 393e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if 'EventConstructor' in interface.extended_attributes: 394e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return 1 395e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if not constructors: 396e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return 0 397e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return min(constructor['number_of_required_arguments'] 398e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) for constructor in constructors) 399e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 400e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 401e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)# Interface dependencies 402e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 403e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)def inherits_interface(interface, ancestor): 404e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # FIXME: support distant ancestors (but don't parse all ancestors!) 405e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) # Do by computing ancestor chain in compute_dependencies.py 406e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return ancestor in [interface.name, interface.parent] 407