| 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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 653 |
| 654 def _GenerateNativeCallback(self, | 654 def _GenerateNativeCallback(self, |
| 655 callback_name, | 655 callback_name, |
| 656 needs_receiver, | 656 needs_receiver, |
| 657 function_expression, | 657 function_expression, |
| 658 node, | 658 node, |
| 659 arguments, | 659 arguments, |
| 660 return_type, | 660 return_type, |
| 661 raises_dom_exception): | 661 raises_dom_exception): |
| 662 ext_attrs = node.ext_attrs | 662 ext_attrs = node.ext_attrs |
| 663 |
| 663 cpp_arguments = [] | 664 cpp_arguments = [] |
| 665 requires_v8_scope = \ |
| 666 any((self._TypeInfo(argument.type.id).requires_v8_scope() for argument i
n arguments)) |
| 667 runtime_check = None |
| 668 raises_exceptions = raises_dom_exception or arguments |
| 664 | 669 |
| 665 requires_v8_scope = False | 670 requires_stack_info = ext_attrs.get('CallWith') == 'ScriptArguments|CallStac
k' |
| 666 runtime_check = None | 671 if requires_stack_info: |
| 667 raises_exceptions = False | |
| 668 requires_script_execution_context = False | |
| 669 requires_dom_window = False | |
| 670 requires_stack_info = False | |
| 671 | |
| 672 if raises_dom_exception or arguments: | |
| 673 raises_exceptions = True | |
| 674 | |
| 675 if ext_attrs.get('CallWith') == 'ScriptArguments|CallStack': | |
| 676 raises_exceptions = True | 672 raises_exceptions = True |
| 677 requires_v8_scope = True | 673 requires_v8_scope = True |
| 678 requires_stack_info = True | |
| 679 self._cpp_impl_includes.add('"ScriptArguments.h"') | |
| 680 self._cpp_impl_includes.add('"ScriptCallStack.h"') | |
| 681 cpp_arguments = ['scriptArguments', 'scriptCallStack'] | 674 cpp_arguments = ['scriptArguments', 'scriptCallStack'] |
| 682 # WebKit uses scriptArguments to reconstruct last argument, so | 675 # WebKit uses scriptArguments to reconstruct last argument, so |
| 683 # it's not needed and should be just removed. | 676 # it's not needed and should be just removed. |
| 684 arguments = arguments[:-1] | 677 arguments = arguments[:-1] |
| 685 | 678 |
| 686 if ext_attrs.get('CallWith') == 'ScriptExecutionContext': | 679 requires_script_execution_context = ext_attrs.get('CallWith') == 'ScriptExec
utionContext' |
| 680 if requires_script_execution_context: |
| 687 raises_exceptions = True | 681 raises_exceptions = True |
| 688 requires_script_execution_context = True | |
| 689 cpp_arguments = ['context'] | 682 cpp_arguments = ['context'] |
| 690 | 683 |
| 684 requires_dom_window = 'NamedConstructor' in ext_attrs |
| 685 if requires_dom_window: |
| 686 raises_exceptions = True |
| 687 cpp_arguments = ['document'] |
| 688 |
| 691 if 'ImplementedBy' in ext_attrs: | 689 if 'ImplementedBy' in ext_attrs: |
| 692 assert needs_receiver | 690 assert needs_receiver |
| 693 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy']) | 691 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy']) |
| 694 cpp_arguments.append('receiver') | 692 cpp_arguments.append('receiver') |
| 695 | 693 |
| 696 if 'NamedConstructor' in ext_attrs: | |
| 697 raises_exceptions = True | |
| 698 requires_dom_window = True | |
| 699 self._cpp_impl_includes.add('"DOMWindow.h"') | |
| 700 cpp_arguments = ['document'] | |
| 701 | |
| 702 if 'Reflect' in ext_attrs: | 694 if 'Reflect' in ext_attrs: |
| 703 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] | 695 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] |
| 704 | 696 |
| 705 for argument in arguments: | |
| 706 if self._TypeInfo(argument.type.id).requires_v8_scope(): | |
| 707 requires_v8_scope = True | |
| 708 | |
| 709 assert (not ( | 697 assert (not ( |
| 710 'synthesizedV8EnabledPerContext' in ext_attrs and | 698 'synthesizedV8EnabledPerContext' in ext_attrs and |
| 711 'synthesizedV8EnabledAtRuntime' in ext_attrs)) | 699 'synthesizedV8EnabledAtRuntime' in ext_attrs)) |
| 712 if 'synthesizedV8EnabledPerContext' in ext_attrs: | 700 if 'synthesizedV8EnabledPerContext' in ext_attrs: |
| 713 raises_exceptions = True | 701 raises_exceptions = True |
| 714 self._cpp_impl_includes.add('"ContextFeatures.h"') | 702 self._cpp_impl_includes.add('"ContextFeatures.h"') |
| 715 self._cpp_impl_includes.add('"DOMWindow.h"') | 703 self._cpp_impl_includes.add('"DOMWindow.h"') |
| 716 runtime_check = emitter.Format( | 704 runtime_check = emitter.Format( |
| 717 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin
dowForCurrentIsolate()->document())) {\n' | 705 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin
dowForCurrentIsolate()->document())) {\n' |
| 718 ' exception = Dart_NewString("Feature $FEATURE is not enabl
ed");\n' | 706 ' exception = Dart_NewString("Feature $FEATURE is not enabl
ed");\n' |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 | 753 |
| 766 if requires_script_execution_context: | 754 if requires_script_execution_context: |
| 767 body_emitter.Emit( | 755 body_emitter.Emit( |
| 768 ' ScriptExecutionContext* context = DartUtilities::scriptExecut
ionContext();\n' | 756 ' ScriptExecutionContext* context = DartUtilities::scriptExecut
ionContext();\n' |
| 769 ' if (!context) {\n' | 757 ' if (!context) {\n' |
| 770 ' exception = Dart_NewString("Failed to retrieve a context"
);\n' | 758 ' exception = Dart_NewString("Failed to retrieve a context"
);\n' |
| 771 ' goto fail;\n' | 759 ' goto fail;\n' |
| 772 ' }\n\n') | 760 ' }\n\n') |
| 773 | 761 |
| 774 if requires_dom_window: | 762 if requires_dom_window: |
| 763 self._cpp_impl_includes.add('"DOMWindow.h"') |
| 775 body_emitter.Emit( | 764 body_emitter.Emit( |
| 776 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol
ate();\n' | 765 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol
ate();\n' |
| 777 ' if (!domWindow) {\n' | 766 ' if (!domWindow) {\n' |
| 778 ' exception = Dart_NewString("Failed to fetch domWindow");\
n' | 767 ' exception = Dart_NewString("Failed to fetch domWindow");\
n' |
| 779 ' goto fail;\n' | 768 ' goto fail;\n' |
| 780 ' }\n' | 769 ' }\n' |
| 781 ' Document* document = domWindow->document();\n') | 770 ' Document* document = domWindow->document();\n') |
| 782 | 771 |
| 783 if needs_receiver: | 772 if needs_receiver: |
| 784 body_emitter.Emit( | 773 body_emitter.Emit( |
| 785 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE
BCORE_CLASS_NAME >(args);\n', | 774 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE
BCORE_CLASS_NAME >(args);\n', |
| 786 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) | 775 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) |
| 787 | 776 |
| 788 if requires_stack_info: | 777 if requires_stack_info: |
| 778 self._cpp_impl_includes.add('"ScriptArguments.h"') |
| 779 self._cpp_impl_includes.add('"ScriptCallStack.h"') |
| 789 body_emitter.Emit( | 780 body_emitter.Emit( |
| 790 '\n' | 781 '\n' |
| 791 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN
DEX);\n' | 782 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN
DEX);\n' |
| 792 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create
ScriptArguments(customArgument, exception));\n' | 783 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create
ScriptArguments(customArgument, exception));\n' |
| 793 ' if (!scriptArguments)\n' | 784 ' if (!scriptArguments)\n' |
| 794 ' goto fail;\n' | 785 ' goto fail;\n' |
| 795 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create
ScriptCallStack());\n' | 786 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create
ScriptCallStack());\n' |
| 796 ' if (!scriptCallStack->size())\n' | 787 ' if (!scriptCallStack->size())\n' |
| 797 ' return;\n', | 788 ' return;\n', |
| 798 INDEX=len(arguments) + 1) | 789 INDEX=len(arguments) + 1) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 parent_interface = _FindInHierarchy(database, parent_interface, test) | 911 parent_interface = _FindInHierarchy(database, parent_interface, test) |
| 921 if parent_interface: | 912 if parent_interface: |
| 922 return parent_interface | 913 return parent_interface |
| 923 | 914 |
| 924 def _ToWebKitName(name): | 915 def _ToWebKitName(name): |
| 925 name = name[0].lower() + name[1:] | 916 name = name[0].lower() + name[1:] |
| 926 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | 917 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), |
| 927 name) | 918 name) |
| 928 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
, | 919 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
, |
| 929 name) | 920 name) |
| OLD | NEW |