| Index: Source/bindings/scripts/unstable/v8_interface.py
|
| diff --git a/Source/bindings/scripts/unstable/v8_interface.py b/Source/bindings/scripts/unstable/v8_interface.py
|
| deleted file mode 100644
|
| index 78aca2042ef14015ae2dfad03e521468ae17e990..0000000000000000000000000000000000000000
|
| --- a/Source/bindings/scripts/unstable/v8_interface.py
|
| +++ /dev/null
|
| @@ -1,727 +0,0 @@
|
| -# Copyright (C) 2013 Google Inc. All rights reserved.
|
| -#
|
| -# Redistribution and use in source and binary forms, with or without
|
| -# modification, are permitted provided that the following conditions are
|
| -# met:
|
| -#
|
| -# * Redistributions of source code must retain the above copyright
|
| -# notice, this list of conditions and the following disclaimer.
|
| -# * Redistributions in binary form must reproduce the above
|
| -# copyright notice, this list of conditions and the following disclaimer
|
| -# in the documentation and/or other materials provided with the
|
| -# distribution.
|
| -# * Neither the name of Google Inc. nor the names of its
|
| -# contributors may be used to endorse or promote products derived from
|
| -# this software without specific prior written permission.
|
| -#
|
| -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| -
|
| -"""Generate template values for an interface.
|
| -
|
| -FIXME: Not currently used in build.
|
| -This is a rewrite of the Perl IDL compiler in Python, but is not complete.
|
| -Once it is complete, we will switch all IDL files over to Python at once.
|
| -Until then, please work on the Perl IDL compiler.
|
| -For details, see bug http://crbug.com/239771
|
| -"""
|
| -
|
| -import v8_attributes
|
| -from v8_globals import includes
|
| -import v8_methods
|
| -import v8_types
|
| -from v8_types import inherits_interface, is_interface_type
|
| -import v8_utilities
|
| -from v8_utilities import capitalize, conditional_string, cpp_name, has_extended_attribute_value, runtime_enabled_function_name
|
| -
|
| -
|
| -INTERFACE_H_INCLUDES = frozenset([
|
| - 'bindings/v8/V8Binding.h',
|
| - 'bindings/v8/V8DOMWrapper.h',
|
| - 'bindings/v8/WrapperTypeInfo.h',
|
| - 'heap/Handle.h',
|
| -])
|
| -INTERFACE_CPP_INCLUDES = frozenset([
|
| - 'RuntimeEnabledFeatures.h',
|
| - 'bindings/v8/ExceptionState.h',
|
| - 'bindings/v8/V8DOMConfiguration.h',
|
| - 'bindings/v8/V8ObjectConstructor.h',
|
| - 'core/dom/ContextFeatures.h',
|
| - 'core/dom/Document.h',
|
| - 'platform/TraceEvent.h',
|
| - 'wtf/GetPtr.h', # FIXME: remove if can eliminate WTF::getPtr
|
| - 'wtf/RefPtr.h',
|
| -])
|
| -
|
| -
|
| -def generate_interface(interface):
|
| - includes.clear()
|
| - includes.update(INTERFACE_CPP_INCLUDES)
|
| - header_includes = set(INTERFACE_H_INCLUDES)
|
| -
|
| - parent_interface = interface.parent
|
| - if parent_interface:
|
| - header_includes.update(v8_types.includes_for_type(parent_interface))
|
| - extended_attributes = interface.extended_attributes
|
| -
|
| - is_audio_buffer = inherits_interface(interface.name, 'AudioBuffer')
|
| - if is_audio_buffer:
|
| - includes.add('modules/webaudio/AudioBuffer.h')
|
| -
|
| - is_document = inherits_interface(interface.name, 'Document')
|
| - if is_document:
|
| - includes.update(['bindings/v8/ScriptController.h',
|
| - 'bindings/v8/V8WindowShell.h',
|
| - 'core/frame/LocalFrame.h'])
|
| -
|
| - # [CheckSecurity]
|
| - is_check_security = 'CheckSecurity' in extended_attributes
|
| - if is_check_security:
|
| - includes.add('bindings/v8/BindingSecurity.h')
|
| -
|
| - # [MeasureAs]
|
| - is_measure_as = 'MeasureAs' in extended_attributes
|
| - if is_measure_as:
|
| - includes.add('core/frame/UseCounter.h')
|
| -
|
| - # [SetWrapperReferenceFrom]
|
| - reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom')
|
| - reachable_node_reference_function = extended_attributes.get('SetWrapperReferenceFromReference')
|
| - if reachable_node_function or reachable_node_reference_function:
|
| - includes.update(['bindings/v8/V8GCController.h',
|
| - 'core/dom/Element.h'])
|
| -
|
| - # [SetWrapperReferenceTo]
|
| - set_wrapper_reference_to_list = [{
|
| - 'name': argument.name,
|
| - # FIXME: properly should be:
|
| - # 'cpp_type': v8_types.cpp_type(argument.idl_type, used_as_argument=True),
|
| - # (if type is non-wrapper type like NodeFilter, normally RefPtr)
|
| - # Raw pointers faster though, and NodeFilter hacky anyway.
|
| - 'cpp_type': v8_types.implemented_as(argument.idl_type) + '*',
|
| - 'idl_type': argument.idl_type,
|
| - 'v8_type': v8_types.v8_type(argument.idl_type),
|
| - } for argument in extended_attributes.get('SetWrapperReferenceTo', [])]
|
| - for set_wrapper_reference_to in set_wrapper_reference_to_list:
|
| - v8_types.add_includes_for_type(set_wrapper_reference_to['idl_type'])
|
| -
|
| - # [SpecialWrapFor]
|
| - if 'SpecialWrapFor' in extended_attributes:
|
| - special_wrap_for = extended_attributes['SpecialWrapFor'].split('|')
|
| - else:
|
| - special_wrap_for = []
|
| - for special_wrap_interface in special_wrap_for:
|
| - v8_types.add_includes_for_type(special_wrap_interface)
|
| -
|
| - # [WillBeGarbageCollected]
|
| - is_will_be_garbage_collected = 'WillBeGarbageCollected' in extended_attributes
|
| -
|
| - template_contents = {
|
| - 'conditional_string': conditional_string(interface), # [Conditional]
|
| - 'cpp_class': cpp_name(interface),
|
| - 'has_custom_legacy_call_as_function': has_extended_attribute_value(interface, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction]
|
| - 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'ToV8'), # [Custom=ToV8]
|
| - 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wrap'), # [Custom=Wrap]
|
| - 'has_visit_dom_wrapper': (
|
| - # [Custom=Wrap], [SetWrapperReferenceFrom]
|
| - has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or
|
| - reachable_node_function or
|
| - reachable_node_reference_function or
|
| - set_wrapper_reference_to_list),
|
| - 'header_includes': header_includes,
|
| - 'interface_name': interface.name,
|
| - 'is_active_dom_object': 'ActiveDOMObject' in extended_attributes, # [ActiveDOMObject]
|
| - 'is_audio_buffer': is_audio_buffer,
|
| - 'is_check_security': is_check_security,
|
| - 'is_dependent_lifetime': 'DependentLifetime' in extended_attributes, # [DependentLifetime]
|
| - 'is_document': is_document,
|
| - 'is_event_target': inherits_interface(interface.name, 'EventTarget'),
|
| - 'is_exception': interface.is_exception,
|
| - 'is_will_be_garbage_collected': is_will_be_garbage_collected,
|
| - 'is_node': inherits_interface(interface.name, 'Node'),
|
| - 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs]
|
| - 'parent_interface': parent_interface,
|
| - 'pass_ref_ptr': 'PassRefPtrWillBeRawPtr'
|
| - if is_will_be_garbage_collected else 'PassRefPtr',
|
| - 'reachable_node_function': reachable_node_function,
|
| - 'reachable_node_reference_function': reachable_node_reference_function,
|
| - 'ref_ptr': 'RefPtrWillBeRawPtr'
|
| - if is_will_be_garbage_collected else 'RefPtr',
|
| - 'runtime_enabled_function': runtime_enabled_function_name(interface), # [RuntimeEnabled]
|
| - 'set_wrapper_reference_to_list': set_wrapper_reference_to_list,
|
| - 'special_wrap_for': special_wrap_for,
|
| - 'v8_class': v8_utilities.v8_class_name(interface),
|
| - }
|
| -
|
| - # Constructors
|
| - constructors = [generate_constructor(interface, constructor)
|
| - for constructor in interface.constructors
|
| - # FIXME: shouldn't put named constructors with constructors
|
| - # (currently needed for Perl compatibility)
|
| - # Handle named constructors separately
|
| - if constructor.name == 'Constructor']
|
| - generate_constructor_overloads(constructors)
|
| -
|
| - # [CustomConstructor]
|
| - custom_constructors = [{ # Only needed for computing interface length
|
| - 'number_of_required_arguments':
|
| - number_of_required_arguments(constructor),
|
| - } for constructor in interface.custom_constructors]
|
| -
|
| - # [EventConstructor]
|
| - has_event_constructor = 'EventConstructor' in extended_attributes
|
| - any_type_attributes = [attribute for attribute in interface.attributes
|
| - if attribute.idl_type == 'any']
|
| - if has_event_constructor:
|
| - includes.add('bindings/v8/Dictionary.h')
|
| - if any_type_attributes:
|
| - includes.add('bindings/v8/SerializedScriptValue.h')
|
| -
|
| - # [NamedConstructor]
|
| - named_constructor = generate_named_constructor(interface)
|
| -
|
| - if (constructors or custom_constructors or has_event_constructor or
|
| - named_constructor):
|
| - includes.add('bindings/v8/V8ObjectConstructor.h')
|
| -
|
| - template_contents.update({
|
| - 'any_type_attributes': any_type_attributes,
|
| - 'constructors': constructors,
|
| - 'has_custom_constructor': bool(custom_constructors),
|
| - 'has_event_constructor': has_event_constructor,
|
| - 'interface_length':
|
| - interface_length(interface, constructors + custom_constructors),
|
| - 'is_constructor_call_with_document': has_extended_attribute_value(
|
| - interface, 'ConstructorCallWith', 'Document'), # [ConstructorCallWith=Document]
|
| - 'is_constructor_call_with_execution_context': has_extended_attribute_value(
|
| - interface, 'ConstructorCallWith', 'ExecutionContext'), # [ConstructorCallWith=ExeuctionContext]
|
| - 'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor]
|
| - 'named_constructor': named_constructor,
|
| - })
|
| -
|
| - # Constants
|
| - template_contents.update({
|
| - 'constants': [generate_constant(constant) for constant in interface.constants],
|
| - 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes,
|
| - })
|
| -
|
| - # Attributes
|
| - attributes = [v8_attributes.generate_attribute(interface, attribute)
|
| - for attribute in interface.attributes]
|
| - template_contents.update({
|
| - 'attributes': attributes,
|
| - 'has_accessors': any(attribute['is_expose_js_accessors'] for attribute in attributes),
|
| - 'has_attribute_configuration': any(
|
| - not (attribute['is_expose_js_accessors'] or
|
| - attribute['is_static'] or
|
| - attribute['runtime_enabled_function'] or
|
| - attribute['per_context_enabled_function'])
|
| - for attribute in attributes),
|
| - 'has_constructor_attributes': any(attribute['constructor_type'] for attribute in attributes),
|
| - 'has_per_context_enabled_attributes': any(attribute['per_context_enabled_function'] for attribute in attributes),
|
| - 'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes),
|
| - })
|
| -
|
| - # Methods
|
| - methods = [v8_methods.generate_method(interface, method)
|
| - for method in interface.operations
|
| - if method.name] # Skip anonymous special operations (methods)
|
| - generate_overloads(methods)
|
| - for method in methods:
|
| - method['do_generate_method_configuration'] = (
|
| - method['do_not_check_signature'] and
|
| - not method['per_context_enabled_function'] and
|
| - # For overloaded methods, only generate one accessor
|
| - ('overload_index' not in method or method['overload_index'] == 1))
|
| -
|
| - template_contents.update({
|
| - 'has_origin_safe_method_setter': any(
|
| - method['is_check_security_for_frame'] and not method['is_read_only']
|
| - for method in methods),
|
| - 'has_method_configuration': any(method['do_generate_method_configuration'] for method in methods),
|
| - 'has_per_context_enabled_methods': any(method['per_context_enabled_function'] for method in methods),
|
| - 'methods': methods,
|
| - })
|
| -
|
| - template_contents.update({
|
| - 'indexed_property_getter': indexed_property_getter(interface),
|
| - 'indexed_property_setter': indexed_property_setter(interface),
|
| - 'indexed_property_deleter': indexed_property_deleter(interface),
|
| - 'is_override_builtins': 'OverrideBuiltins' in extended_attributes,
|
| - 'named_property_getter': named_property_getter(interface),
|
| - 'named_property_setter': named_property_setter(interface),
|
| - 'named_property_deleter': named_property_deleter(interface),
|
| - })
|
| -
|
| - return template_contents
|
| -
|
| -
|
| -# [DeprecateAs], [Reflect], [RuntimeEnabled]
|
| -def generate_constant(constant):
|
| - # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted
|
| - # in C++.
|
| - if constant.idl_type == 'DOMString':
|
| - value = '"%s"' % constant.value
|
| - else:
|
| - value = constant.value
|
| -
|
| - extended_attributes = constant.extended_attributes
|
| - return {
|
| - 'cpp_class': extended_attributes.get('ImplementedBy'),
|
| - 'name': constant.name,
|
| - # FIXME: use 'reflected_name' as correct 'name'
|
| - 'reflected_name': extended_attributes.get('Reflect', constant.name),
|
| - 'runtime_enabled_function': runtime_enabled_function_name(constant),
|
| - 'value': value,
|
| - }
|
| -
|
| -
|
| -################################################################################
|
| -# Overloads
|
| -################################################################################
|
| -
|
| -def generate_overloads(methods):
|
| - generate_overloads_by_type(methods, is_static=False) # Regular methods
|
| - generate_overloads_by_type(methods, is_static=True)
|
| -
|
| -
|
| -def generate_overloads_by_type(methods, is_static):
|
| - # Generates |overloads| template values and modifies |methods| in place;
|
| - # |is_static| flag used (instead of partitioning list in 2) because need to
|
| - # iterate over original list of methods to modify in place
|
| - method_counts = {}
|
| - for method in methods:
|
| - if method['is_static'] != is_static:
|
| - continue
|
| - name = method['name']
|
| - method_counts.setdefault(name, 0)
|
| - method_counts[name] += 1
|
| -
|
| - # Filter to only methods that are actually overloaded
|
| - overloaded_method_counts = dict((name, count)
|
| - for name, count in method_counts.iteritems()
|
| - if count > 1)
|
| -
|
| - # Add overload information only to overloaded methods, so template code can
|
| - # easily verify if a function is overloaded
|
| - method_overloads = {}
|
| - for method in methods:
|
| - name = method['name']
|
| - if (method['is_static'] != is_static or
|
| - name not in overloaded_method_counts):
|
| - continue
|
| - # Overload index includes self, so first append, then compute index
|
| - method_overloads.setdefault(name, []).append(method)
|
| - method.update({
|
| - 'overload_index': len(method_overloads[name]),
|
| - 'overload_resolution_expression': overload_resolution_expression(method),
|
| - })
|
| -
|
| - # Resolution function is generated after last overloaded function;
|
| - # package necessary information into |method.overloads| for that method.
|
| - for method in methods:
|
| - if (method['is_static'] != is_static or
|
| - 'overload_index' not in method):
|
| - continue
|
| - name = method['name']
|
| - if method['overload_index'] != overloaded_method_counts[name]:
|
| - continue
|
| - overloads = method_overloads[name]
|
| - minimum_number_of_required_arguments = min(
|
| - overload['number_of_required_arguments']
|
| - for overload in overloads)
|
| - method['overloads'] = {
|
| - 'has_exception_state': bool(minimum_number_of_required_arguments),
|
| - 'methods': overloads,
|
| - 'minimum_number_of_required_arguments': minimum_number_of_required_arguments,
|
| - 'name': name,
|
| - }
|
| -
|
| -
|
| -def overload_resolution_expression(method):
|
| - # Expression is an OR of ANDs: each term in the OR corresponds to a
|
| - # possible argument count for a given method, with type checks.
|
| - # FIXME: Blink's overload resolution algorithm is incorrect, per:
|
| - # Implement WebIDL overload resolution algorithm.
|
| - # https://code.google.com/p/chromium/issues/detail?id=293561
|
| - #
|
| - # Currently if distinguishing non-primitive type from primitive type,
|
| - # (e.g., sequence<DOMString> from DOMString or Dictionary from double)
|
| - # the method with a non-primitive type argument must appear *first* in the
|
| - # IDL file, since we're not adding a check to primitive types.
|
| - # FIXME: Once fixed, check IDLs, as usually want methods with primitive
|
| - # types to appear first (style-wise).
|
| - #
|
| - # Properly:
|
| - # 1. Compute effective overload set.
|
| - # 2. First check type list length.
|
| - # 3. If multiple entries for given length, compute distinguishing argument
|
| - # index and have check for that type.
|
| - arguments = method['arguments']
|
| - overload_checks = [overload_check_expression(method, index)
|
| - # check *omitting* optional arguments at |index| and up:
|
| - # index 0 => argument_count 0 (no arguments)
|
| - # index 1 => argument_count 1 (index 0 argument only)
|
| - for index, argument in enumerate(arguments)
|
| - if argument['is_optional']]
|
| - # FIXME: this is wrong if a method has optional arguments and a variadic
|
| - # one, though there are not yet any examples of this
|
| - if not method['is_variadic']:
|
| - # Includes all optional arguments (len = last index + 1)
|
| - overload_checks.append(overload_check_expression(method, len(arguments)))
|
| - return ' || '.join('(%s)' % check for check in overload_checks)
|
| -
|
| -
|
| -def overload_check_expression(method, argument_count):
|
| - overload_checks = ['info.Length() == %s' % argument_count]
|
| - arguments = method['arguments'][:argument_count]
|
| - overload_checks.extend(overload_check_argument(index, argument)
|
| - for index, argument in
|
| - enumerate(arguments))
|
| - return ' && '.join('(%s)' % check for check in overload_checks if check)
|
| -
|
| -
|
| -def overload_check_argument(index, argument):
|
| - def null_or_optional_check():
|
| - # If undefined is passed for an optional argument, the argument should
|
| - # be treated as missing; otherwise undefined is not allowed.
|
| - if argument['is_nullable']:
|
| - if argument['is_optional']:
|
| - return 'isUndefinedOrNull(%s)'
|
| - return '%s->IsNull()'
|
| - if argument['is_optional']:
|
| - return '%s->IsUndefined()'
|
| - return None
|
| -
|
| - cpp_value = 'info[%s]' % index
|
| - idl_type = argument['idl_type']
|
| - # FIXME: proper type checking, sharing code with attributes and methods
|
| - if idl_type == 'DOMString' and argument['is_strict_type_checking']:
|
| - return ' || '.join(['isUndefinedOrNull(%s)' % cpp_value,
|
| - '%s->IsString()' % cpp_value,
|
| - '%s->IsObject()' % cpp_value])
|
| - if v8_types.array_or_sequence_type(idl_type):
|
| - return '%s->IsArray()' % cpp_value
|
| - if v8_types.is_callback_interface(idl_type):
|
| - return ' || '.join(['%s->IsNull()' % cpp_value,
|
| - '%s->IsFunction()' % cpp_value])
|
| - if v8_types.is_wrapper_type(idl_type):
|
| - type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'.format(idl_type=idl_type, cpp_value=cpp_value)
|
| - if argument['is_nullable']:
|
| - type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check])
|
| - return type_check
|
| - if is_interface_type(idl_type):
|
| - # Non-wrapper types are just objects: we don't distinguish type
|
| - # We only allow undefined for non-wrapper types (notably Dictionary),
|
| - # as we need it for optional Dictionary arguments, but we don't want to
|
| - # change behavior of existing bindings for other types.
|
| - type_check = '%s->IsObject()' % cpp_value
|
| - added_check_template = null_or_optional_check()
|
| - if added_check_template:
|
| - type_check = ' || '.join([added_check_template % cpp_value,
|
| - type_check])
|
| - return type_check
|
| - return None
|
| -
|
| -
|
| -################################################################################
|
| -# Constructors
|
| -################################################################################
|
| -
|
| -# [Constructor]
|
| -def generate_constructor(interface, constructor):
|
| - return {
|
| - 'argument_list': constructor_argument_list(interface, constructor),
|
| - 'arguments': [constructor_argument(argument, index)
|
| - for index, argument in enumerate(constructor.arguments)],
|
| - 'has_exception_state':
|
| - # [RaisesException=Constructor]
|
| - interface.extended_attributes.get('RaisesException') == 'Constructor' or
|
| - any(argument for argument in constructor.arguments
|
| - if argument.idl_type == 'SerializedScriptValue' or
|
| - v8_types.is_integer_type(argument.idl_type)),
|
| - 'is_constructor': True,
|
| - 'is_variadic': False, # Required for overload resolution
|
| - 'number_of_required_arguments':
|
| - number_of_required_arguments(constructor),
|
| - }
|
| -
|
| -
|
| -def constructor_argument_list(interface, constructor):
|
| - arguments = []
|
| - # [ConstructorCallWith=ExecutionContext]
|
| - if has_extended_attribute_value(interface, 'ConstructorCallWith', 'ExecutionContext'):
|
| - arguments.append('context')
|
| - # [ConstructorCallWith=Document]
|
| - if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document'):
|
| - arguments.append('document')
|
| -
|
| - arguments.extend([argument.name for argument in constructor.arguments])
|
| -
|
| - # [RaisesException=Constructor]
|
| - if interface.extended_attributes.get('RaisesException') == 'Constructor':
|
| - arguments.append('exceptionState')
|
| -
|
| - return arguments
|
| -
|
| -
|
| -def constructor_argument(argument, index):
|
| - return {
|
| - 'has_default': 'Default' in argument.extended_attributes,
|
| - 'idl_type': argument.idl_type,
|
| - 'index': index,
|
| - 'is_nullable': False, # Required for overload resolution
|
| - 'is_optional': argument.is_optional,
|
| - 'is_strict_type_checking': False, # Required for overload resolution
|
| - 'name': argument.name,
|
| - 'v8_value_to_local_cpp_value':
|
| - v8_methods.v8_value_to_local_cpp_value(argument, index),
|
| - }
|
| -
|
| -
|
| -def generate_constructor_overloads(constructors):
|
| - if len(constructors) <= 1:
|
| - return
|
| - for overload_index, constructor in enumerate(constructors):
|
| - constructor.update({
|
| - 'overload_index': overload_index + 1,
|
| - 'overload_resolution_expression':
|
| - overload_resolution_expression(constructor),
|
| - })
|
| -
|
| -
|
| -# [NamedConstructor]
|
| -def generate_named_constructor(interface):
|
| - extended_attributes = interface.extended_attributes
|
| - if 'NamedConstructor' not in extended_attributes:
|
| - return None
|
| - # FIXME: parser should return named constructor separately;
|
| - # included in constructors (and only name stored in extended attribute)
|
| - # for Perl compatibility
|
| - idl_constructor = interface.constructors[0]
|
| - constructor = generate_constructor(interface, idl_constructor)
|
| - constructor['argument_list'].insert(0, '*document')
|
| - constructor['name'] = extended_attributes['NamedConstructor']
|
| - return constructor
|
| -
|
| -
|
| -def number_of_required_arguments(constructor):
|
| - return len([argument for argument in constructor.arguments
|
| - if not argument.is_optional])
|
| -
|
| -
|
| -def interface_length(interface, constructors):
|
| - # Docs: http://heycam.github.io/webidl/#es-interface-call
|
| - if 'EventConstructor' in interface.extended_attributes:
|
| - return 1
|
| - if not constructors:
|
| - return 0
|
| - return min(constructor['number_of_required_arguments']
|
| - for constructor in constructors)
|
| -
|
| -
|
| -################################################################################
|
| -# Special operations (methods)
|
| -# http://heycam.github.io/webidl/#idl-special-operations
|
| -################################################################################
|
| -
|
| -def property_getter(getter, cpp_arguments):
|
| - def is_null_expression(idl_type):
|
| - if v8_types.is_union_type(idl_type):
|
| - return ' && '.join('!result%sEnabled' % i
|
| - for i, _ in
|
| - enumerate(idl_type.union_member_types))
|
| - if idl_type == 'DOMString':
|
| - return 'result.isNull()'
|
| - if is_interface_type(idl_type):
|
| - return '!result'
|
| - return ''
|
| -
|
| - idl_type = getter.idl_type
|
| - extended_attributes = getter.extended_attributes
|
| - is_raises_exception = 'RaisesException' in extended_attributes
|
| -
|
| - if v8_types.is_union_type(idl_type):
|
| - release = [v8_types.is_interface_type(union_member_type)
|
| - for union_member_type in idl_type.union_member_types]
|
| - else:
|
| - release = v8_types.is_interface_type(idl_type)
|
| -
|
| - # FIXME: make more generic, so can use v8_methods.cpp_value
|
| - cpp_method_name = 'imp->%s' % cpp_name(getter)
|
| -
|
| - if is_raises_exception:
|
| - cpp_arguments.append('exceptionState')
|
| - this_union_arguments = v8_methods.union_arguments(idl_type)
|
| - if this_union_arguments:
|
| - cpp_arguments.extend(this_union_arguments)
|
| -
|
| - cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
|
| -
|
| - return {
|
| - 'cpp_type': v8_types.cpp_type(idl_type),
|
| - 'cpp_value': cpp_value,
|
| - 'is_custom':
|
| - 'Custom' in extended_attributes and
|
| - (not extended_attributes['Custom'] or
|
| - has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')),
|
| - 'is_custom_property_enumerator': has_extended_attribute_value(
|
| - getter, 'Custom', 'PropertyEnumerator'),
|
| - 'is_custom_property_query': has_extended_attribute_value(
|
| - getter, 'Custom', 'PropertyQuery'),
|
| - 'is_enumerable': 'NotEnumerable' not in extended_attributes,
|
| - 'is_null_expression': is_null_expression(idl_type),
|
| - 'is_raises_exception': is_raises_exception,
|
| - 'name': cpp_name(getter),
|
| - 'union_arguments': v8_methods.union_arguments(idl_type),
|
| - 'v8_set_return_value': v8_types.v8_set_return_value(idl_type, 'result', extended_attributes=extended_attributes, script_wrappable='imp', release=release),
|
| - }
|
| -
|
| -
|
| -def property_setter(setter):
|
| - idl_type = setter.arguments[1].idl_type
|
| - extended_attributes = setter.extended_attributes
|
| - is_raises_exception = 'RaisesException' in extended_attributes
|
| - return {
|
| - 'has_strict_type_checking':
|
| - 'StrictTypeChecking' in extended_attributes and
|
| - v8_types.is_wrapper_type(idl_type),
|
| - 'idl_type': idl_type,
|
| - 'is_custom': 'Custom' in extended_attributes,
|
| - 'has_exception_state': is_raises_exception or
|
| - v8_types.is_integer_type(idl_type),
|
| - 'is_raises_exception': is_raises_exception,
|
| - 'name': cpp_name(setter),
|
| - 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(
|
| - idl_type, extended_attributes, 'jsValue', 'propertyValue'),
|
| - }
|
| -
|
| -
|
| -def property_deleter(deleter):
|
| - idl_type = deleter.idl_type
|
| - if idl_type != 'boolean':
|
| - raise Exception(
|
| - 'Only deleters with boolean type are allowed, but type is "%s"' %
|
| - idl_type)
|
| - extended_attributes = deleter.extended_attributes
|
| - return {
|
| - 'is_custom': 'Custom' in extended_attributes,
|
| - 'is_raises_exception': 'RaisesException' in extended_attributes,
|
| - 'name': cpp_name(deleter),
|
| - }
|
| -
|
| -
|
| -################################################################################
|
| -# Indexed properties
|
| -# http://heycam.github.io/webidl/#idl-indexed-properties
|
| -################################################################################
|
| -
|
| -def indexed_property_getter(interface):
|
| - try:
|
| - # Find indexed property getter, if present; has form:
|
| - # getter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1)
|
| - getter = next(
|
| - method
|
| - for method in interface.operations
|
| - if ('getter' in method.specials and
|
| - len(method.arguments) == 1 and
|
| - method.arguments[0].idl_type == 'unsigned long'))
|
| - except StopIteration:
|
| - return None
|
| -
|
| - return property_getter(getter, ['index'])
|
| -
|
| -
|
| -def indexed_property_setter(interface):
|
| - try:
|
| - # Find indexed property setter, if present; has form:
|
| - # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1, ARG_TYPE ARG2)
|
| - setter = next(
|
| - method
|
| - for method in interface.operations
|
| - if ('setter' in method.specials and
|
| - len(method.arguments) == 2 and
|
| - method.arguments[0].idl_type == 'unsigned long'))
|
| - except StopIteration:
|
| - return None
|
| -
|
| - return property_setter(setter)
|
| -
|
| -
|
| -def indexed_property_deleter(interface):
|
| - try:
|
| - # Find indexed property deleter, if present; has form:
|
| - # deleter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG)
|
| - deleter = next(
|
| - method
|
| - for method in interface.operations
|
| - if ('deleter' in method.specials and
|
| - len(method.arguments) == 1 and
|
| - method.arguments[0].idl_type == 'unsigned long'))
|
| - except StopIteration:
|
| - return None
|
| -
|
| - return property_deleter(deleter)
|
| -
|
| -
|
| -################################################################################
|
| -# Named properties
|
| -# http://heycam.github.io/webidl/#idl-named-properties
|
| -################################################################################
|
| -
|
| -def named_property_getter(interface):
|
| - try:
|
| - # Find named property getter, if present; has form:
|
| - # getter TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1)
|
| - getter = next(
|
| - method
|
| - for method in interface.operations
|
| - if ('getter' in method.specials and
|
| - len(method.arguments) == 1 and
|
| - method.arguments[0].idl_type == 'DOMString'))
|
| - except StopIteration:
|
| - return None
|
| -
|
| - getter.name = getter.name or 'anonymousNamedGetter'
|
| - return property_getter(getter, ['propertyName'])
|
| -
|
| -
|
| -def named_property_setter(interface):
|
| - try:
|
| - # Find named property setter, if present; has form:
|
| - # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1, ARG_TYPE ARG2)
|
| - setter = next(
|
| - method
|
| - for method in interface.operations
|
| - if ('setter' in method.specials and
|
| - len(method.arguments) == 2 and
|
| - method.arguments[0].idl_type == 'DOMString'))
|
| - except StopIteration:
|
| - return None
|
| -
|
| - return property_setter(setter)
|
| -
|
| -
|
| -def named_property_deleter(interface):
|
| - try:
|
| - # Find named property deleter, if present; has form:
|
| - # deleter TYPE [OPTIONAL_IDENTIFIER](DOMString ARG)
|
| - deleter = next(
|
| - method
|
| - for method in interface.operations
|
| - if ('deleter' in method.specials and
|
| - len(method.arguments) == 1 and
|
| - method.arguments[0].idl_type == 'DOMString'))
|
| - except StopIteration:
|
| - return None
|
| -
|
| - return property_deleter(deleter)
|
|
|