OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 """This module provides shared functionality for the systems to generate | 6 """This module provides shared functionality for the systems to generate |
7 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 import os | 10 import os |
11 from generator import * | 11 from generator import * |
12 from htmldartgenerator import * | 12 from htmldartgenerator import * |
13 from systemhtml import js_support_checks | 13 from systemhtml import js_support_checks, GetCallbackInfo |
14 | 14 |
15 class DartiumBackend(HtmlDartGenerator): | 15 class DartiumBackend(HtmlDartGenerator): |
16 """Generates Dart implementation for one DOM IDL interface.""" | 16 """Generates Dart implementation for one DOM IDL interface.""" |
17 | 17 |
18 def __init__(self, interface, cpp_library_emitter, options): | 18 def __init__(self, interface, cpp_library_emitter, options): |
19 super(DartiumBackend, self).__init__(interface, options) | 19 super(DartiumBackend, self).__init__(interface, options) |
20 | 20 |
21 self._interface = interface | 21 self._interface = interface |
22 self._cpp_library_emitter = cpp_library_emitter | 22 self._cpp_library_emitter = cpp_library_emitter |
23 self._database = options.database | 23 self._database = options.database |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 'static ' if info.IsStatic() else '', | 468 'static ' if info.IsStatic() else '', |
469 self.SecureOutputType(info.type_name), | 469 self.SecureOutputType(info.type_name), |
470 html_name, | 470 html_name, |
471 info.ParametersDeclaration(self._DartType)) | 471 info.ParametersDeclaration(self._DartType)) |
472 | 472 |
473 operation = info.operations[0] | 473 operation = info.operations[0] |
474 is_custom = 'Custom' in operation.ext_attrs | 474 is_custom = 'Custom' in operation.ext_attrs |
475 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) | 475 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) |
476 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) | 476 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) |
477 | 477 |
478 if not needs_dispatcher: | 478 if info.callback_args: |
| 479 self._AddFutureifiedOperation(info, html_name) |
| 480 elif not needs_dispatcher: |
479 # Bind directly to native implementation | 481 # Bind directly to native implementation |
480 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 482 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
481 cpp_callback_name = self._GenerateNativeBinding( | 483 cpp_callback_name = self._GenerateNativeBinding( |
482 info.name, argument_count, dart_declaration, 'Callback', is_custom) | 484 info.name, argument_count, dart_declaration, 'Callback', is_custom) |
483 if not is_custom: | 485 if not is_custom: |
484 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) | 486 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) |
485 else: | 487 else: |
486 self._GenerateDispatcher(info.operations, dart_declaration, [info.name for
info in info.param_infos]) | 488 self._GenerateDispatcher(info.operations, dart_declaration, [info.name for
info in info.param_infos]) |
487 | 489 |
488 def _GenerateDispatcher(self, operations, dart_declaration, parameter_names): | 490 def _GenerateDispatcher(self, operations, dart_declaration, parameter_names): |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 896 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
895 ' return func;\n', | 897 ' return func;\n', |
896 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 898 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
897 | 899 |
898 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 900 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
899 return ( | 901 return ( |
900 interface.id.endswith('Event') and | 902 interface.id.endswith('Event') and |
901 operation.id.startswith('init') and | 903 operation.id.startswith('init') and |
902 argument.ext_attrs.get('Optional') == 'DefaultIsUndefined' and | 904 argument.ext_attrs.get('Optional') == 'DefaultIsUndefined' and |
903 argument.type.id == 'DOMString') | 905 argument.type.id == 'DOMString') |
OLD | NEW |