| Index: sky/engine/bindings2/scripts/dart_callback_interface.py
|
| diff --git a/sky/engine/bindings/scripts/v8_callback_interface.py b/sky/engine/bindings2/scripts/dart_callback_interface.py
|
| similarity index 63%
|
| copy from sky/engine/bindings/scripts/v8_callback_interface.py
|
| copy to sky/engine/bindings2/scripts/dart_callback_interface.py
|
| index 9e30e888ec0def05abd3566ce52bc76f2abb3c96..2252fddd68787125aefd3228c75ee51b8195bff3 100644
|
| --- a/sky/engine/bindings/scripts/v8_callback_interface.py
|
| +++ b/sky/engine/bindings2/scripts/dart_callback_interface.py
|
| @@ -28,31 +28,25 @@
|
|
|
| """Generate template values for a callback interface.
|
|
|
| -Extends IdlTypeBase with property |callback_cpp_type|.
|
| +Extends IdlType with property |callback_cpp_type|.
|
|
|
| Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
|
| """
|
|
|
| -from idl_types import IdlTypeBase
|
| +from idl_types import IdlType, IdlTypeBase
|
| +import dart_types
|
| +from dart_utilities import DartUtilities
|
| from v8_globals import includes
|
| -import v8_types
|
| -import v8_utilities
|
|
|
| CALLBACK_INTERFACE_H_INCLUDES = frozenset([
|
| - 'bindings/core/v8/ActiveDOMCallback.h',
|
| - 'bindings/core/v8/DOMWrapperWorld.h',
|
| - 'bindings/core/v8/ScopedPersistent.h',
|
| + 'bindings2/dart_callback.h',
|
| ])
|
| +
|
| CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([
|
| - 'bindings/core/v8/ScriptController.h',
|
| - 'bindings/core/v8/V8Binding.h',
|
| - 'core/dom/ExecutionContext.h',
|
| - 'wtf/Assertions.h',
|
| 'wtf/GetPtr.h',
|
| 'wtf/RefPtr.h',
|
| ])
|
|
|
| -
|
| def cpp_type(idl_type):
|
| # FIXME: remove this function by making callback types consistent
|
| # (always use usual v8_types.cpp_type)
|
| @@ -62,25 +56,28 @@ def cpp_type(idl_type):
|
| if idl_type_name == 'void':
|
| return 'void'
|
| # Callbacks use raw pointers, so raw_type=True
|
| - raw_cpp_type = idl_type.cpp_type_args(raw_type=True)
|
| - if raw_cpp_type.startswith(('Vector', 'Vector')):
|
| - return 'const %s&' % raw_cpp_type
|
| - return raw_cpp_type
|
| + usual_cpp_type = idl_type.cpp_type_args(raw_type=True)
|
| + if usual_cpp_type.startswith(('Vector', 'HeapVector', 'WillBeHeapVector')):
|
| + return 'const %s&' % usual_cpp_type
|
| + return usual_cpp_type
|
|
|
| IdlTypeBase.callback_cpp_type = property(cpp_type)
|
|
|
|
|
| -def callback_interface_context(callback_interface):
|
| +def generate_callback_interface(callback_interface):
|
| includes.clear()
|
| includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
|
| - return {
|
| - 'conditional_string': v8_utilities.conditional_string(callback_interface),
|
| - 'cpp_class': callback_interface.name,
|
| - 'v8_class': v8_utilities.v8_class_name(callback_interface),
|
| + name = callback_interface.name
|
| +
|
| + methods = [generate_method(operation)
|
| + for operation in callback_interface.operations]
|
| + template_contents = {
|
| + 'cpp_class': name,
|
| + 'dart_class': dart_types.dart_type(callback_interface.name),
|
| 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
|
| - 'methods': [method_context(operation)
|
| - for operation in callback_interface.operations],
|
| + 'methods': methods,
|
| }
|
| + return template_contents
|
|
|
|
|
| def add_includes_for_operation(operation):
|
| @@ -89,7 +86,7 @@ def add_includes_for_operation(operation):
|
| argument.idl_type.add_includes_for_type()
|
|
|
|
|
| -def method_context(operation):
|
| +def generate_method(operation):
|
| extended_attributes = operation.extended_attributes
|
| idl_type = operation.idl_type
|
| idl_type_str = str(idl_type)
|
| @@ -99,33 +96,35 @@ def method_context(operation):
|
| if not is_custom:
|
| add_includes_for_operation(operation)
|
| call_with = extended_attributes.get('CallWith')
|
| - call_with_this_handle = v8_utilities.extended_attribute_value_contains(call_with, 'ThisValue')
|
| - context = {
|
| + call_with_this_handle = DartUtilities.extended_attribute_value_contains(call_with, 'ThisValue')
|
| + contents = {
|
| 'call_with_this_handle': call_with_this_handle,
|
| 'cpp_type': idl_type.callback_cpp_type,
|
| + 'custom': is_custom,
|
| 'idl_type': idl_type_str,
|
| - 'is_custom': is_custom,
|
| 'name': operation.name,
|
| }
|
| - context.update(arguments_context(operation.arguments,
|
| - call_with_this_handle))
|
| - return context
|
| + contents.update(generate_arguments_contents(operation.arguments, call_with_this_handle))
|
| + return contents
|
|
|
|
|
| -def arguments_context(arguments, call_with_this_handle):
|
| - def argument_context(argument):
|
| +def generate_arguments_contents(arguments, call_with_this_handle):
|
| + def generate_argument(argument):
|
| + creation_context = ''
|
| + if argument.idl_type.native_array_element_type is not None:
|
| + creation_context = '<Dart%s>' % argument.idl_type.native_array_element_type
|
| return {
|
| 'handle': '%sHandle' % argument.name,
|
| - 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value(
|
| - argument.name, isolate='m_scriptState->isolate()',
|
| - creation_context='m_scriptState->context()->Global()'),
|
| + 'cpp_value_to_dart_value': argument.idl_type.cpp_value_to_dart_value(argument.name,
|
| + creation_context=creation_context),
|
| }
|
|
|
| - argument_declarations = ['ScriptValue thisValue'] if call_with_this_handle else []
|
| - argument_declarations.extend(
|
| - '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
|
| - for argument in arguments)
|
| + argument_declarations = [
|
| + '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
|
| + for argument in arguments]
|
| + if call_with_this_handle:
|
| + argument_declarations.insert(0, 'ScriptValue thisValue')
|
| return {
|
| 'argument_declarations': argument_declarations,
|
| - 'arguments': [argument_context(argument) for argument in arguments],
|
| + 'arguments': [generate_argument(argument) for argument in arguments],
|
| }
|
|
|