| Index: Source/bindings/scripts/v8_interface_header.py
|
| diff --git a/Source/bindings/scripts/v8_interface_header.py b/Source/bindings/scripts/v8_interface_header.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9b49d83f8d11cb0a81435571ef1b937bea12c041
|
| --- /dev/null
|
| +++ b/Source/bindings/scripts/v8_interface_header.py
|
| @@ -0,0 +1,186 @@
|
| +# 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 Blink V8 bindings (.h and .cpp files).
|
| +
|
| +Input: An object of class IdlDefinitions, containing an IDL interface X
|
| +Output: V8X.h and V8X.cpp
|
| +"""
|
| +
|
| +
|
| +from code_generator_idl_reader import inherits_interface, interface_inherits_extended_attribute
|
| +from v8_includes import header_files_for_interface
|
| +import v8_special_accessors
|
| +# from v8_types import get_native_type, get_v8_class_name
|
| +from v8_types import *
|
| +from v8_utilities import generate_conditional_string, implemented_as_cpp_name
|
| +
|
| +
|
| +def generate_header(interface):
|
| + includes = base_header_includes(interface)
|
| + cpp_class_name = implemented_as_cpp_name(interface)
|
| + cpp_class_name_as_parameter = get_native_type(interface.name, used_as_parameter=True)
|
| +
|
| + # Ensure the IsDOMNodeType function is in sync.
|
| + if is_dom_node_type(interface.name) != inherits_interface(interface, 'Node'):
|
| + # inh = 'INHERIT' if inherits_interface(interface, 'Node') else ''
|
| + # dom = 'DOM' if is_dom_node_type(interface.name) else ''
|
| + # print '[IsDOMNodeType]', dom, inh
|
| + raise Exception('IsDOMNodeType is out of date with respect to %s' % interface.name)
|
| +
|
| + # SVG
|
| + svg_property_type, svg_list_property_type, svg_native_type, svg_header_includes, svg_cpp_includes = get_svg_property_types(interface.name)
|
| + includes |= set(svg_header_includes)
|
| +# print '[[]]', svg_native_type
|
| + svg_native_type_contains_svg_static_list_property_tear_off = 'SVGStaticListPropertyTearOff' in svg_native_type
|
| + svg_type_needing_tear_off = get_svg_type_needing_tear_off(interface.name)
|
| + if svg_type_needing_tear_off:
|
| + cpp_class_name = svg_type_needing_tear_off
|
| +# cpp_class_name_as_parameter = svg_type_needing_tear_off
|
| + cpp_class_name_as_parameter = get_native_type(svg_type_needing_tear_off, used_as_parameter=True)
|
| +
|
| + # Wrap
|
| + no_to_v8 = 'DoNotGenerateToV8' in interface.extended_attributes
|
| + no_wrap = 'DoNotGenerateWrap' in interface.extended_attributes or no_to_v8
|
| + generate_to_v8 = False
|
| + custom_wrap = 'CustomToV8' in interface.extended_attributes
|
| + if no_to_v8:
|
| + if interface.parent:
|
| + raise Exception("Can't suppress toV8 for subclass")
|
| + elif no_wrap:
|
| + if not custom_wrap:
|
| + raise Exception('Must have custom toV8')
|
| + generate_to_v8 = True
|
| +
|
| + if interface.parent:
|
| + v8_parent_class_name = 'V8' + interface.parent
|
| + to_wrapped_type = '%s::toInternalPointer(impl)' % v8_parent_class_name
|
| + from_wrapped_type = 'static_cast<%s*>(%s::fromInternalPointer(object))' % (cpp_class_name, v8_parent_class_name)
|
| + else:
|
| + to_wrapped_type = 'impl'
|
| + from_wrapped_type = 'static_cast<%s*>(object)' % cpp_class_name
|
| +
|
| + # Enabled per context
|
| + enabled_per_context_functions = [operation for operation in interface.operations if operation.name and operation.extended_attributes.get('EnabledPerContext')]
|
| + enabled_per_context_attributes = [attribute for attribute in interface.attributes if attribute.extended_attributes.get('EnabledPerContext')]
|
| +
|
| + template_parameters = {
|
| + 'conditional_string': generate_conditional_string(interface),
|
| + 'cpp_class_name': cpp_class_name,
|
| + # used in function parameter -> can be replaced
|
| + 'cpp_class_name_as_parameter': cpp_class_name_as_parameter,
|
| + 'inherits_event_target': inherits_interface(interface, 'EventTarget'),
|
| + 'internal_fields': get_internal_fields(interface),
|
| + 'generate_to_v8': generate_to_v8,
|
| + 'header_includes': sorted(includes),
|
| + 'operation_definitions': operation_definitions(interface),
|
| + 'attribute_definitions': attribute_definitions(interface),
|
| + 'has_custom_named_enumerator': has_custom_named_enumerator(interface),
|
| + 'install_per_context_properties_body': semicolon_or_braces(enabled_per_context_attributes),
|
| + 'install_per_context_prototype_properties_body': semicolon_or_braces(enabled_per_context_functions),
|
| + 'wrap': not no_wrap,
|
| + 'custom_wrap': custom_wrap,
|
| + 'to_wrapped_type': to_wrapped_type,
|
| + 'from_wrapped_type': from_wrapped_type,
|
| + 'svg_property_type': svg_property_type,
|
| + 'svg_list_property_type': svg_list_property_type,
|
| + 'svg_native_type': svg_native_type,
|
| + 'svg_native_type_contains_svg_static_list_property_tear_off': svg_native_type_contains_svg_static_list_property_tear_off,
|
| + }
|
| + template_parameters.update(v8_special_accessors.has_custom_accessors(interface))
|
| + return template_parameters
|
| +
|
| +
|
| +def base_header_includes(interface):
|
| + includes = set([
|
| + 'bindings/v8/WrapperTypeInfo.h',
|
| + 'bindings/v8/V8Binding.h',
|
| + 'bindings/v8/V8DOMWrapper.h',
|
| + ])
|
| + if interface.parent:
|
| + includes.add('V8%s.h' % interface.parent)
|
| + includes |= set(header_files_for_interface(interface.name, implemented_as_cpp_name(interface)))
|
| + return includes
|
| +
|
| +
|
| +def get_internal_fields(interface):
|
| + # Event listeners on DOM nodes are explicitly supported in the GC controller.
|
| + if (not inherits_interface(interface, 'Node') and
|
| + (inherits_interface(interface, 'EventTarget') or
|
| + any([attribute.data_type == 'EventListener'
|
| + for attribute in interface.attributes]))):
|
| + return ['eventListenerCacheIndex']
|
| + return []
|
| +
|
| +
|
| +# FIXME: list comprehension
|
| +# FIXME: in fact, template instead
|
| +def operation_definitions(interface):
|
| + definitions = []
|
| + for operation in interface.operations:
|
| + if not operation.name:
|
| + continue
|
| + if has_custom_implementation(operation) and operation.overload_index == 1:
|
| + code = 'static void %sMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&);' % operation.name
|
| + definitions.append(apply_conditional(operation, code))
|
| + return definitions
|
| +
|
| +
|
| +# FIXME: list comprehension
|
| +# FIXME: in fact, template instead
|
| +def attribute_definitions(interface):
|
| + definitions = []
|
| + for attribute in interface.attributes:
|
| + if has_custom_getter(attribute):
|
| + code = 'static void %sAttrGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>&);' % attribute.name
|
| + definitions.append(apply_conditional(attribute, code))
|
| + if has_custom_setter(attribute):
|
| + code = 'static void %sAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&);' % attribute.name
|
| + definitions.append(apply_conditional(attribute, code))
|
| + return definitions
|
| +
|
| +
|
| +def has_custom_named_enumerator(interface):
|
| + named_getter_operation = v8_special_accessors.get_named_getter_operation(interface)
|
| + return named_getter_operation and 'CustomEnumerateProperty' in named_getter_operation.extended_attributes
|
| +
|
| +
|
| +def semicolon_or_braces(l):
|
| + if l:
|
| + return ';'
|
| + return ' { }'
|
| +
|
| +
|
| +# FIXME: template instead?
|
| +def apply_conditional(operation_or_attribute, code):
|
| + conditional_string = generate_conditional_string(operation_or_attribute)
|
| + if conditional_string:
|
| + return ('#if %s\n' % conditional_string +
|
| + code +
|
| + '#endif // %s\n' % conditional_string)
|
| + return code
|
|
|