| 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 idlnode import IDLArgument |
| 13 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES | 14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES |
| 14 | 15 |
| 15 class DartiumBackend(HtmlDartGenerator): | 16 class DartiumBackend(HtmlDartGenerator): |
| 16 """Generates Dart implementation for one DOM IDL interface.""" | 17 """Generates Dart implementation for one DOM IDL interface.""" |
| 17 | 18 |
| 18 def __init__(self, interface, cpp_library_emitter, options): | 19 def __init__(self, interface, cpp_library_emitter, options): |
| 19 super(DartiumBackend, self).__init__(interface, options) | 20 super(DartiumBackend, self).__init__(interface, options) |
| 20 | 21 |
| 21 self._interface = interface | 22 self._interface = interface |
| 22 self._cpp_library_emitter = cpp_library_emitter | 23 self._cpp_library_emitter = cpp_library_emitter |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 ' }\n' | 674 ' }\n' |
| 674 ' Document* document = domWindow->document();\n') | 675 ' Document* document = domWindow->document();\n') |
| 675 | 676 |
| 676 if needs_receiver: | 677 if needs_receiver: |
| 677 body_emitter.Emit( | 678 body_emitter.Emit( |
| 678 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE
BCORE_CLASS_NAME >(args);\n', | 679 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE
BCORE_CLASS_NAME >(args);\n', |
| 679 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) | 680 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) |
| 680 | 681 |
| 681 if requires_stack_info: | 682 if requires_stack_info: |
| 682 self._cpp_impl_includes.add('"ScriptArguments.h"') | 683 self._cpp_impl_includes.add('"ScriptArguments.h"') |
| 684 self._cpp_impl_includes.add('"ScriptCallStack.h"') |
| 683 body_emitter.Emit( | 685 body_emitter.Emit( |
| 684 '\n' | 686 '\n' |
| 685 ' ScriptState* currentState = ScriptState::current();\n' | 687 ' ScriptState* currentState = ScriptState::current();\n' |
| 686 ' if (!currentState) {\n' | 688 ' if (!currentState) {\n' |
| 687 ' exception = Dart_NewStringFromCString("Failed to retrieve
a script state");\n' | 689 ' exception = Dart_NewStringFromCString("Failed to retrieve
a script state");\n' |
| 688 ' goto fail;\n' | 690 ' goto fail;\n' |
| 689 ' }\n' | 691 ' }\n' |
| 690 ' ScriptState& state = *currentState;\n' | 692 ' ScriptState& state = *currentState;\n' |
| 691 '\n' | 693 '\n' |
| 692 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN
DEX);\n' | 694 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN
DEX);\n' |
| (...skipping 18 matching lines...) Expand all Loading... |
| 711 ' return;\n', | 713 ' return;\n', |
| 712 INDEX=len(arguments) + 1) | 714 INDEX=len(arguments) + 1) |
| 713 | 715 |
| 714 # Emit arguments. | 716 # Emit arguments. |
| 715 start_index = 1 if needs_receiver else 0 | 717 start_index = 1 if needs_receiver else 0 |
| 716 for i, argument in enumerate(arguments): | 718 for i, argument in enumerate(arguments): |
| 717 type_info = self._TypeInfo(argument.type.id) | 719 type_info = self._TypeInfo(argument.type.id) |
| 718 argument_expression_template, type, cls, function = \ | 720 argument_expression_template, type, cls, function = \ |
| 719 type_info.to_native_info(argument, self._interface.id) | 721 type_info.to_native_info(argument, self._interface.id) |
| 720 | 722 |
| 721 if ((IsOptional(argument) and not self._IsArgumentOptionalInWebCore(node,
argument)) or | 723 if (isinstance(argument, IDLArgument) and ( |
| 722 (argument.ext_attrs.get('Optional') == 'DefaultIsNullString') or | 724 (IsOptional(argument) and not self._IsArgumentOptionalInWebCore(node,
argument)) or |
| 723 _IsOptionalStringArgumentInInitEventMethod(self._interface, node, argu
ment)): | 725 (argument.ext_attrs.get('Default') == 'NullString') or |
| 726 _IsOptionalStringArgumentInInitEventMethod(self._interface, node, arg
ument))): |
| 724 function += 'WithNullCheck' | 727 function += 'WithNullCheck' |
| 725 | 728 |
| 726 argument_name = DartDomNameOfAttribute(argument) | 729 argument_name = DartDomNameOfAttribute(argument) |
| 727 if type_info.pass_native_by_ref(): | 730 if type_info.pass_native_by_ref(): |
| 728 invocation_template =\ | 731 invocation_template =\ |
| 729 ' $TYPE $ARGUMENT_NAME;\n'\ | 732 ' $TYPE $ARGUMENT_NAME;\n'\ |
| 730 ' $CLS::$FUNCTION(Dart_GetNativeArgument(args, $INDEX), $ARGU
MENT_NAME, exception);\n' | 733 ' $CLS::$FUNCTION(Dart_GetNativeArgument(args, $INDEX), $ARGU
MENT_NAME, exception);\n' |
| 731 else: | 734 else: |
| 732 invocation_template =\ | 735 invocation_template =\ |
| 733 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(Dart_GetNativeArgume
nt(args, $INDEX), exception);\n' | 736 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(Dart_GetNativeArgume
nt(args, $INDEX), exception);\n' |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 918 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 916 body_emitter.Emit( | 919 body_emitter.Emit( |
| 917 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 920 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
| 918 ' return func;\n', | 921 ' return func;\n', |
| 919 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 922 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| 920 | 923 |
| 921 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 924 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 922 return ( | 925 return ( |
| 923 interface.id.endswith('Event') and | 926 interface.id.endswith('Event') and |
| 924 operation.id.startswith('init') and | 927 operation.id.startswith('init') and |
| 925 argument.ext_attrs.get('Optional') == 'DefaultIsUndefined' and | 928 argument.ext_attrs.get('Default') == 'Undefined' and |
| 926 argument.type.id == 'DOMString') | 929 argument.type.id == 'DOMString') |
| OLD | NEW |