| Index: Source/bindings/scripts/v8_constructors.py
|
| diff --git a/Source/bindings/scripts/v8_constructors.py b/Source/bindings/scripts/v8_constructors.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a3de285a2b786a5b5b89041edb897bd6ab741516
|
| --- /dev/null
|
| +++ b/Source/bindings/scripts/v8_constructors.py
|
| @@ -0,0 +1,162 @@
|
| +# 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 constructors.
|
| +
|
| +FIXME: rename: "template parameters" is easily confused with "function parameters"
|
| +Also, "parameter*s*", not "parameter".
|
| +"""
|
| +
|
| +from v8_functions import get_function_mandatory_parameters, get_parameter_check_parameters
|
| +from v8_includes import *
|
| +from v8_types import *
|
| +from v8_utilities import implemented_as_cpp_name
|
| +
|
| +
|
| +NAMED_PARAMETER_INCLUDES = [
|
| + 'V8Document.h',
|
| + 'bindings/v8/V8ObjectConstructor.h',
|
| +]
|
| +
|
| +
|
| +def generate_constructor_contents(interface):
|
| + includes = []
|
| +
|
| + constructor_raises_exception = 'ConstructorRaisesException' in interface.extended_attributes
|
| + if constructor_raises_exception:
|
| + includes.append('bindings/v8/ExceptionState.h')
|
| +
|
| + has_named_constructor = 'NamedConstructor' in interface.extended_attributes
|
| + if has_named_constructor:
|
| + named_constructor_parameter, named_constructor_includes = generate_named_constructor(interface)
|
| + includes += named_constructor_includes
|
| + else:
|
| + named_constructor_parameter = {}
|
| +
|
| + constructor_parameters, constructor_includes = generate_constructors(interface)
|
| + includes += constructor_includes
|
| +
|
| + is_constructor_template_of_event = is_constructor_template(interface, 'Event')
|
| + if is_constructor_template_of_event:
|
| + includes.append('bindings/v8/Dictionary.h')
|
| +
|
| + is_constructor_template_of_typed_array = is_constructor_template(interface, 'TypedArray')
|
| +
|
| + constructable = is_constructable(interface)
|
| + if constructable:
|
| + includes.append('bindings/v8/V8ObjectConstructor.h')
|
| +
|
| + template_parameters = {
|
| + 'is_constructable': constructable,
|
| + 'named_constructor': named_constructor_parameter,
|
| + 'constructor_raises_exception': constructor_raises_exception,
|
| + 'constructor_call_with': interface.extended_attributes.get('ConstructorCallWith'),
|
| + 'constructors': constructor_parameters,
|
| + 'has_custom_constructor': has_custom_constructor(interface),
|
| + 'has_named_constructor': has_named_constructor,
|
| + 'has_constructor': 'Constructor' in interface.extended_attributes,
|
| + 'is_constructor_template_of_event': is_constructor_template_of_event,
|
| + 'is_constructor_template_of_typed_array': is_constructor_template_of_typed_array,
|
| + }
|
| + return template_parameters, includes
|
| +
|
| +
|
| +def generate_constructors(interface):
|
| + # FIXME: clearer with a list comprehension + nested function to handle includes
|
| + constructors = []
|
| + includes = []
|
| + for constructor in interface.constructors:
|
| + if len(interface.constructors) == 1:
|
| + constructor_contents, constructor_includes = generate_constructor(interface, constructor)
|
| + constructors.append(constructor_contents)
|
| + includes += constructor_includes
|
| + else:
|
| + # TODO
|
| + pass
|
| + return constructors, includes
|
| +
|
| +
|
| +def generate_named_constructor(interface):
|
| + named_constructor = interface.constructors[0]
|
| + parameter_check_parameters, parameter_check_includes, replacements = get_parameter_check_parameters(interface, named_constructor)
|
| + includes = NAMED_PARAMETER_INCLUDES + parameter_check_includes
|
| +
|
| + argument_list = ['document']
|
| + for argument in named_constructor.arguments:
|
| + argument_name = argument.name
|
| + if argument_name in replacements:
|
| + argument_name = replacements[argument_name]
|
| + argument_list.append(argument_name)
|
| +
|
| + constructor_raises_exception = 'ConstructorRaisesException' in interface.extended_attributes
|
| + if constructor_raises_exception:
|
| + argument_list.append('ec')
|
| +
|
| + argument_string = ', '.join(argument_list)
|
| + named_constructor_parameter = {
|
| + 'argument_string': argument_string,
|
| + 'parameters': parameter_check_parameters,
|
| + }
|
| + return named_constructor_parameter, includes
|
| +
|
| +
|
| +def generate_constructor(interface, constructor):
|
| + includes = []
|
| + cpp_class_name = implemented_as_cpp_name(interface)
|
| + v8_class_name = get_v8_class_name(interface)
|
| + overloaded_index_string = ''
|
| + if constructor.overloaded_index > 0:
|
| + overloaded_index_string = constructor.overloaded_index
|
| + # print '####### [ctor]', len(constructor.arguments)
|
| +
|
| + # FIXME: Currently [Constructor(...)] does not yet support optional arguments without [Default=...]
|
| +# parameter_check_string, _, replacements) = GenerateParametersCheck($function, $interface, '')
|
| + parameter_check_parameters, parameter_check_includes, replacements = get_parameter_check_parameters(interface, constructor)
|
| + includes += parameter_check_includes
|
| +
|
| + argument_list = []
|
| + if interface.extended_attributes.get('ConstructorCallWith') == 'ScriptExecutionContext':
|
| + argument_list.append('context')
|
| + for parameter in constructor.arguments:
|
| + parameter_name = parameter.name
|
| + if parameter_name in replacements:
|
| + parameter_name = replacements[parameter_name]
|
| + argument_list.append(parameter_name)
|
| +
|
| + if 'ConstructorRaisesException' in interface.extended_attributes:
|
| + argument_list.append('es')
|
| + argument_string = ', '.join(argument_list)
|
| +
|
| + parameter = {
|
| + 'argument_string': argument_string,
|
| + 'mandatory_parameters': get_function_mandatory_parameters(constructor),
|
| + 'parameters': parameter_check_parameters,
|
| + 'overloaded_index': constructor.overloaded_index,
|
| + 'overloaded_index_string': overloaded_index_string,
|
| + }
|
| + return parameter, includes
|
|
|