| 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 |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 self._cpp_impl_includes.add('"DOMWindow.h"') | 696 self._cpp_impl_includes.add('"DOMWindow.h"') |
| 697 cpp_arguments = ['document'] | 697 cpp_arguments = ['document'] |
| 698 | 698 |
| 699 if 'Reflect' in ext_attrs: | 699 if 'Reflect' in ext_attrs: |
| 700 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] | 700 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] |
| 701 | 701 |
| 702 for argument in arguments: | 702 for argument in arguments: |
| 703 if self._TypeInfo(argument.type.id).requires_v8_scope(): | 703 if self._TypeInfo(argument.type.id).requires_v8_scope(): |
| 704 requires_v8_scope = True | 704 requires_v8_scope = True |
| 705 | 705 |
| 706 parameter_definitions_emitter = emitter.Emitter() | |
| 707 # Process Dart cpp_arguments. | |
| 708 start_index = 0 | |
| 709 if needs_receiver: | |
| 710 start_index = 1 | |
| 711 for (i, argument) in enumerate(arguments): | |
| 712 if (i == len(arguments) - 1 and | |
| 713 self._interface.id == 'Console' and | |
| 714 argument.id == 'arg'): | |
| 715 # FIXME: we are skipping last argument here because it was added in | |
| 716 # supplemental dart.idl. Cleanup dart.idl and remove this check. | |
| 717 break | |
| 718 argument_expression = self._GenerateToNative( | |
| 719 parameter_definitions_emitter, argument, start_index + i) | |
| 720 cpp_arguments.append(argument_expression) | |
| 721 | |
| 722 # FIXME: rework in IDLs. | |
| 723 if node.id in ['addEventListener', 'removeEventListener']: | |
| 724 # addEventListener's and removeEventListener's last argument is marked | |
| 725 # as optional in idl, but is not optional in webcore implementation. | |
| 726 if len(arguments) == 2: | |
| 727 cpp_arguments.append('false') | |
| 728 | |
| 729 if self._interface.id == 'CSSStyleDeclaration' and node.id == 'setProperty': | |
| 730 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart | |
| 731 # idl, but is not optional in webcore implementation. | |
| 732 if len(arguments) == 2: | |
| 733 cpp_arguments.append('String()') | |
| 734 | |
| 735 if 'NeedsUserGestureCheck' in ext_attrs: | |
| 736 cpp_arguments.append('DartUtilities::processingUserGesture'); | |
| 737 | |
| 738 assert (not ( | 706 assert (not ( |
| 739 'synthesizedV8EnabledPerContext' in ext_attrs and | 707 'synthesizedV8EnabledPerContext' in ext_attrs and |
| 740 'synthesizedV8EnabledAtRuntime' in ext_attrs)) | 708 'synthesizedV8EnabledAtRuntime' in ext_attrs)) |
| 741 if 'synthesizedV8EnabledPerContext' in ext_attrs: | 709 if 'synthesizedV8EnabledPerContext' in ext_attrs: |
| 742 raises_exceptions = True | 710 raises_exceptions = True |
| 743 self._cpp_impl_includes.add('"ContextFeatures.h"') | 711 self._cpp_impl_includes.add('"ContextFeatures.h"') |
| 744 self._cpp_impl_includes.add('"DOMWindow.h"') | 712 self._cpp_impl_includes.add('"DOMWindow.h"') |
| 745 runtime_check = emitter.Format( | 713 runtime_check = emitter.Format( |
| 746 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin
dowForCurrentIsolate()->document())) {\n' | 714 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin
dowForCurrentIsolate()->document())) {\n' |
| 747 ' exception = Dart_NewString("Feature $FEATURE is not enabl
ed");\n' | 715 ' exception = Dart_NewString("Feature $FEATURE is not enabl
ed");\n' |
| 748 ' goto fail;\n' | 716 ' goto fail;\n' |
| 749 ' }', | 717 ' }', |
| 750 FEATURE=ext_attrs['synthesizedV8EnabledPerContext']) | 718 FEATURE=ext_attrs['synthesizedV8EnabledPerContext']) |
| 751 | 719 |
| 752 if 'synthesizedV8EnabledAtRuntime' in ext_attrs: | 720 if 'synthesizedV8EnabledAtRuntime' in ext_attrs: |
| 753 raises_exceptions = True | 721 raises_exceptions = True |
| 754 self._cpp_impl_includes.add('"RuntimeEnabledFeatures.h"') | 722 self._cpp_impl_includes.add('"RuntimeEnabledFeatures.h"') |
| 755 runtime_check = emitter.Format( | 723 runtime_check = emitter.Format( |
| 756 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n' | 724 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n' |
| 757 ' exception = Dart_NewString("Feature $FEATURE is not enabl
ed");\n' | 725 ' exception = Dart_NewString("Feature $FEATURE is not enabl
ed");\n' |
| 758 ' goto fail;\n' | 726 ' goto fail;\n' |
| 759 ' }', | 727 ' }', |
| 760 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime'])) | 728 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime'])) |
| 761 | 729 |
| 762 invocation = self._GenerateWebCoreInvocation( | |
| 763 function_expression, cpp_arguments, return_type, ext_attrs, raises_dom_e
xception) | |
| 764 | |
| 765 head_emitter = emitter.Emitter() | 730 head_emitter = emitter.Emitter() |
| 766 | 731 |
| 767 if requires_v8_scope: | 732 if requires_v8_scope: |
| 768 head_emitter.Emit( | 733 head_emitter.Emit( |
| 769 ' V8Scope v8scope;\n\n') | 734 ' V8Scope v8scope;\n\n') |
| 770 | 735 |
| 771 if runtime_check: | 736 if runtime_check: |
| 772 head_emitter.Emit( | 737 head_emitter.Emit( |
| 773 '$RUNTIME_CHECK\n', | 738 '$RUNTIME_CHECK\n', |
| 774 RUNTIME_CHECK=runtime_check) | 739 RUNTIME_CHECK=runtime_check) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 800 '\n' | 765 '\n' |
| 801 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN
DEX);\n' | 766 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN
DEX);\n' |
| 802 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create
ScriptArguments(customArgument, exception));\n' | 767 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create
ScriptArguments(customArgument, exception));\n' |
| 803 ' if (!scriptArguments)\n' | 768 ' if (!scriptArguments)\n' |
| 804 ' goto fail;\n' | 769 ' goto fail;\n' |
| 805 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create
ScriptCallStack());\n' | 770 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create
ScriptCallStack());\n' |
| 806 ' if (!scriptCallStack->size())\n' | 771 ' if (!scriptCallStack->size())\n' |
| 807 ' return;\n', | 772 ' return;\n', |
| 808 INDEX=len(arguments)) | 773 INDEX=len(arguments)) |
| 809 | 774 |
| 810 head_emitter.Emit( | 775 # Process Dart cpp_arguments. |
| 811 '$PARAMETE_DEFINITIONS\n', | 776 start_index = 0 |
| 812 PARAMETE_DEFINITIONS=parameter_definitions_emitter.Fragments()) | 777 if needs_receiver: |
| 778 start_index = 1 |
| 779 for (i, argument) in enumerate(arguments): |
| 780 if (i == len(arguments) - 1 and |
| 781 self._interface.id == 'Console' and |
| 782 argument.id == 'arg'): |
| 783 # FIXME: we are skipping last argument here because it was added in |
| 784 # supplemental dart.idl. Cleanup dart.idl and remove this check. |
| 785 break |
| 786 argument_expression = self._GenerateToNative(head_emitter, argument, start
_index + i) |
| 787 cpp_arguments.append(argument_expression) |
| 788 |
| 789 head_emitter.Emit('\n') |
| 790 |
| 791 # FIXME: rework in IDLs. |
| 792 if node.id in ['addEventListener', 'removeEventListener']: |
| 793 # addEventListener's and removeEventListener's last argument is marked |
| 794 # as optional in idl, but is not optional in webcore implementation. |
| 795 if len(arguments) == 2: |
| 796 cpp_arguments.append('false') |
| 797 |
| 798 if self._interface.id == 'CSSStyleDeclaration' and node.id == 'setProperty': |
| 799 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart |
| 800 # idl, but is not optional in webcore implementation. |
| 801 if len(arguments) == 2: |
| 802 cpp_arguments.append('String()') |
| 803 |
| 804 if 'NeedsUserGestureCheck' in ext_attrs: |
| 805 cpp_arguments.append('DartUtilities::processingUserGesture'); |
| 806 |
| 807 invocation = self._GenerateWebCoreInvocation( |
| 808 function_expression, cpp_arguments, return_type, ext_attrs, raises_dom_e
xception) |
| 813 | 809 |
| 814 body = emitter.Format( | 810 body = emitter.Format( |
| 815 ' {\n' | 811 ' {\n' |
| 816 '$HEAD' | 812 '$HEAD' |
| 817 '$INVOCATION' | 813 '$INVOCATION' |
| 818 ' return;\n' | 814 ' return;\n' |
| 819 ' }\n', | 815 ' }\n', |
| 820 HEAD=head_emitter.Fragments(), | 816 HEAD=head_emitter.Fragments(), |
| 821 INVOCATION=invocation) | 817 INVOCATION=invocation) |
| 822 | 818 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 | 944 |
| 949 def _IsArgumentOptionalInWebCore(argument): | 945 def _IsArgumentOptionalInWebCore(argument): |
| 950 return IsOptional(argument) and not 'Callback' in argument.ext_attrs | 946 return IsOptional(argument) and not 'Callback' in argument.ext_attrs |
| 951 | 947 |
| 952 def _ToWebKitName(name): | 948 def _ToWebKitName(name): |
| 953 name = name[0].lower() + name[1:] | 949 name = name[0].lower() + name[1:] |
| 954 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | 950 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), |
| 955 name) | 951 name) |
| 956 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
, | 952 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
, |
| 957 name) | 953 name) |
| OLD | NEW |