| 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, IDLAttribute | 13 from idlnode import IDLArgument, IDLAttribute |
| 14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES | 14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES |
| 15 | 15 |
| 16 _cpp_type_map = { | 16 _cpp_type_map = { |
| 17 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem', | 17 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem', |
| 18 ('DOMWindow', 'indexedDB'): 'DOMWindowIndexedDatabase', | 18 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen', |
| 19 ('DOMWindow', 'speechSynthesis'): 'DOMWindowSpeechSynthesis', | 19 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen', |
| 20 ('DOMWindow', 'webkitNotifications'): 'DOMWindowNotifications', | 20 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen', |
| 21 ('DOMWindow', 'storage'): 'DOMWindowQuota', | 21 ('Document', 'webkitCancelFullScreen'): 'DocumentFullscreen', |
| 22 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota', | 22 ('Document', 'webkitFullscreenEnabled'): 'DocumentFullscreen', |
| 23 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase', | 23 ('Document', 'webkitFullscreenElement'): 'DocumentFullscreen', |
| 24 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem', | 24 ('Document', 'webkitExitFullscreen'): 'DocumentFullscreen', |
| 25 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem', | 25 ('Window', 'crypto'): 'DOMWindowCrypto', |
| 26 ('Window', 'indexedDB'): 'DOMWindowIndexedDatabase', |
| 27 ('Window', 'speechSynthesis'): 'DOMWindowSpeechSynthesis', |
| 28 ('Window', 'webkitNotifications'): 'DOMWindowNotifications', |
| 29 ('Window', 'storage'): 'DOMWindowQuota', |
| 30 ('Window', 'webkitStorageInfo'): 'DOMWindowQuota', |
| 31 ('Window', 'openDatabase'): 'DOMWindowWebDatabase', |
| 32 ('Window', 'webkitRequestFileSystem'): 'DOMWindowFileSystem', |
| 33 ('Window', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem', |
| 26 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem', | 34 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem', |
| 27 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack', | 35 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack', |
| 28 ('Navigator', 'geolocation'): 'NavigatorGeolocation', | 36 ('Navigator', 'geolocation'): 'NavigatorGeolocation', |
| 29 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota', | 37 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota', |
| 30 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota', | 38 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota', |
| 31 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils', | 39 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils', |
| 32 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils', | 40 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils', |
| 33 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream', | 41 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream', |
| 34 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad', | 42 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad', |
| 43 ('Navigator', 'requestMIDIAccess'): 'NavigatorWebMIDI', |
| 44 ('Navigator', 'vibrate'): 'NavigatorVibration', |
| 35 } | 45 } |
| 36 | 46 |
| 37 _cpp_partial_map = {} | 47 _cpp_partial_map = {} |
| 38 | 48 |
| 39 def _GetCPPPartialNames(interface_name): | 49 def _GetCPPPartialNames(interface_name): |
| 40 if not _cpp_partial_map: | 50 if not _cpp_partial_map: |
| 41 for (type, member) in _cpp_type_map.keys(): | 51 for (type, member) in _cpp_type_map.keys(): |
| 42 if type not in _cpp_partial_map: | 52 if type not in _cpp_partial_map: |
| 43 _cpp_partial_map[type] = set([]) | 53 _cpp_partial_map[type] = set([]) |
| 44 _cpp_partial_map[type].add(_cpp_type_map[(type, member)]) | 54 _cpp_partial_map[type].add(_cpp_type_map[(type, member)]) |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 296 |
| 287 def FinishInterface(self): | 297 def FinishInterface(self): |
| 288 self._GenerateCPPHeader() | 298 self._GenerateCPPHeader() |
| 289 | 299 |
| 290 self._cpp_impl_emitter.Emit( | 300 self._cpp_impl_emitter.Emit( |
| 291 self._template_loader.Load('cpp_implementation.template'), | 301 self._template_loader.Load('cpp_implementation.template'), |
| 292 INTERFACE=self._interface.id, | 302 INTERFACE=self._interface.id, |
| 293 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), | 303 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), |
| 294 CALLBACKS=self._cpp_definitions_emitter.Fragments(), | 304 CALLBACKS=self._cpp_definitions_emitter.Fragments(), |
| 295 RESOLVER=self._cpp_resolver_emitter.Fragments(), | 305 RESOLVER=self._cpp_resolver_emitter.Fragments(), |
| 306 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
| 307 WEBCORE_CLASS_NAME_ESCAPED= |
| 308 self._interface_type_info.native_type().replace('<', '_').replace('>', '
_'), |
| 296 DART_IMPLEMENTATION_CLASS=self._interface_type_info.implementation_name(
), | 309 DART_IMPLEMENTATION_CLASS=self._interface_type_info.implementation_name(
), |
| 297 DART_IMPLEMENTATION_LIBRARY='dart:%s' % self._renamer.GetLibraryName(sel
f._interface)) | 310 DART_IMPLEMENTATION_LIBRARY='dart:%s' % self._renamer.GetLibraryName(sel
f._interface)) |
| 298 | 311 |
| 299 def _GenerateCPPHeader(self): | 312 def _GenerateCPPHeader(self): |
| 300 to_native_emitter = emitter.Emitter() | 313 to_native_emitter = emitter.Emitter() |
| 301 if self._interface_type_info.custom_to_native(): | 314 if self._interface_type_info.custom_to_native(): |
| 302 return_type = 'PassRefPtr<NativeType>' | 315 return_type = 'PassRefPtr<NativeType>' |
| 303 to_native_body = ';' | 316 to_native_body = ';' |
| 304 else: | 317 else: |
| 305 return_type = 'NativeType*' | 318 return_type = 'NativeType*' |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs | 359 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs |
| 347 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attr
s | 360 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attr
s |
| 348 def TypeCheckHelper(test): | 361 def TypeCheckHelper(test): |
| 349 return 'true' if any(map(test, self._database.Hierarchy(self._interface)))
else 'false' | 362 return 'true' if any(map(test, self._database.Hierarchy(self._interface)))
else 'false' |
| 350 | 363 |
| 351 self._cpp_header_emitter.Emit( | 364 self._cpp_header_emitter.Emit( |
| 352 self._template_loader.Load('cpp_header.template'), | 365 self._template_loader.Load('cpp_header.template'), |
| 353 INTERFACE=self._interface.id, | 366 INTERFACE=self._interface.id, |
| 354 WEBCORE_INCLUDES=webcore_includes, | 367 WEBCORE_INCLUDES=webcore_includes, |
| 355 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 368 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
| 369 WEBCORE_CLASS_NAME_ESCAPED= |
| 370 self._interface_type_info.native_type().replace('<', '_').replace('>', '
_'), |
| 356 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), | 371 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), |
| 357 IS_NODE=TypeCheckHelper(is_node_test), | 372 IS_NODE=TypeCheckHelper(is_node_test), |
| 358 IS_ACTIVE=TypeCheckHelper(is_active_test), | 373 IS_ACTIVE=TypeCheckHelper(is_active_test), |
| 359 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test), | 374 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test), |
| 360 TO_NATIVE=to_native_emitter.Fragments(), | 375 TO_NATIVE=to_native_emitter.Fragments(), |
| 361 TO_DART=to_dart_emitter.Fragments()) | 376 TO_DART=to_dart_emitter.Fragments()) |
| 362 | 377 |
| 363 def EmitAttribute(self, attribute, html_name, read_only): | 378 def EmitAttribute(self, attribute, html_name, read_only): |
| 364 self._AddGetter(attribute, html_name) | 379 self._AddGetter(attribute, html_name) |
| 365 if not read_only: | 380 if not read_only: |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 return_type, | 615 return_type, |
| 601 return_type_is_nullable, | 616 return_type_is_nullable, |
| 602 raises_dom_exception): | 617 raises_dom_exception): |
| 603 ext_attrs = node.ext_attrs | 618 ext_attrs = node.ext_attrs |
| 604 | 619 |
| 605 cpp_arguments = [] | 620 cpp_arguments = [] |
| 606 runtime_check = None | 621 runtime_check = None |
| 607 raises_exceptions = raises_dom_exception or arguments | 622 raises_exceptions = raises_dom_exception or arguments |
| 608 | 623 |
| 609 # TODO(antonm): unify with ScriptState below. | 624 # TODO(antonm): unify with ScriptState below. |
| 610 requires_stack_info = ext_attrs.get('CallWith') == 'ScriptArguments|ScriptSt
ate' | 625 requires_stack_info = (ext_attrs.get('CallWith') == 'ScriptArguments|ScriptS
tate' or |
| 626 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume
nts|ScriptState') |
| 611 if requires_stack_info: | 627 if requires_stack_info: |
| 612 raises_exceptions = True | 628 raises_exceptions = True |
| 613 cpp_arguments = ['&state', 'scriptArguments.release()'] | 629 cpp_arguments = ['&state', 'scriptArguments.release()'] |
| 614 # WebKit uses scriptArguments to reconstruct last argument, so | 630 # WebKit uses scriptArguments to reconstruct last argument, so |
| 615 # it's not needed and should be just removed. | 631 # it's not needed and should be just removed. |
| 616 arguments = arguments[:-1] | 632 arguments = arguments[:-1] |
| 617 | 633 |
| 618 # TODO(antonm): unify with ScriptState below. | 634 # TODO(antonm): unify with ScriptState below. |
| 619 requires_script_arguments = ext_attrs.get('CallWith') == 'ScriptArguments' | 635 requires_script_arguments = (ext_attrs.get('CallWith') == 'ScriptArguments'
or |
| 636 ext_attrs.get('ConstructorCallWith') == 'Script
Arguments') |
| 620 if requires_script_arguments: | 637 if requires_script_arguments: |
| 621 raises_exceptions = True | 638 raises_exceptions = True |
| 622 cpp_arguments = ['scriptArguments.release()'] | 639 cpp_arguments = ['scriptArguments.release()'] |
| 623 # WebKit uses scriptArguments to reconstruct last argument, so | 640 # WebKit uses scriptArguments to reconstruct last argument, so |
| 624 # it's not needed and should be just removed. | 641 # it's not needed and should be just removed. |
| 625 arguments = arguments[:-1] | 642 arguments = arguments[:-1] |
| 626 | 643 |
| 627 requires_script_execution_context = ext_attrs.get('CallWith') == 'ScriptExec
utionContext' | 644 requires_script_execution_context = (ext_attrs.get('CallWith') == 'ScriptExe
cutionContext' or |
| 645 ext_attrs.get('ConstructorCallWith') ==
'ScriptExecutionContext') |
| 628 if requires_script_execution_context: | 646 if requires_script_execution_context: |
| 629 raises_exceptions = True | 647 raises_exceptions = True |
| 630 cpp_arguments = ['context'] | 648 cpp_arguments = ['context'] |
| 631 | 649 |
| 632 requires_script_state = ext_attrs.get('CallWith') == 'ScriptState' | 650 requires_script_state = (ext_attrs.get('CallWith') == 'ScriptState' or |
| 651 ext_attrs.get('ConstructorCallWith') == 'ScriptStat
e') |
| 633 if requires_script_state: | 652 if requires_script_state: |
| 634 raises_exceptions = True | 653 raises_exceptions = True |
| 635 cpp_arguments = ['&state'] | 654 cpp_arguments = ['&state'] |
| 636 | 655 |
| 637 requires_dom_window = 'NamedConstructor' in ext_attrs | 656 requires_dom_window = 'NamedConstructor' in ext_attrs |
| 638 if requires_dom_window: | 657 if requires_dom_window: |
| 639 raises_exceptions = True | 658 raises_exceptions = True |
| 640 cpp_arguments = ['document'] | 659 cpp_arguments = ['document'] |
| 641 | 660 |
| 642 if 'ImplementedBy' in ext_attrs: | 661 if 'ImplementedBy' in ext_attrs: |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 ' if (UNLIKELY(ec)) {\n' | 857 ' if (UNLIKELY(ec)) {\n' |
| 839 ' exception = DartDOMWrapper::exceptionCodeToDartException(ec
);\n' | 858 ' exception = DartDOMWrapper::exceptionCodeToDartException(ec
);\n' |
| 840 ' goto fail;\n' | 859 ' goto fail;\n' |
| 841 ' }\n') | 860 ' }\n') |
| 842 | 861 |
| 843 | 862 |
| 844 if needs_receiver: | 863 if needs_receiver: |
| 845 interface_name = self._interface_type_info.native_type() | 864 interface_name = self._interface_type_info.native_type() |
| 846 cpp_type_name = _GetCPPTypeName(interface_name, | 865 cpp_type_name = _GetCPPTypeName(interface_name, |
| 847 node.id) | 866 node.id) |
| 848 if interface_name != cpp_type_name: | 867 # Hack to determine if this came from the _cpp_type_map. |
| 868 # In this case, the getter is mapped to a static method. |
| 869 if (not function_expression.startswith('receiver->') and |
| 870 not function_expression.startswith(interface_name + '::')): |
| 871 if 'childNodes' in callback_name: |
| 872 print function_expression |
| 873 print interface_name |
| 874 raise 'hell' |
| 849 if interface_name == 'DOMWindow' or interface_name == 'Navigator': | 875 if interface_name == 'DOMWindow' or interface_name == 'Navigator': |
| 850 cpp_arguments.insert(0, 'receiver') | 876 cpp_arguments.insert(0, 'receiver') |
| 851 else: | 877 else: |
| 852 cpp_arguments.append('receiver') | 878 cpp_arguments.append('receiver') |
| 853 | 879 |
| 854 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments)) | 880 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments)) |
| 855 if return_type == 'void': | 881 if return_type == 'void': |
| 856 invocation_emitter.Emit( | 882 invocation_emitter.Emit( |
| 857 ' $FUNCTION_CALL;\n', | 883 ' $FUNCTION_CALL;\n', |
| 858 FUNCTION_CALL=function_call) | 884 FUNCTION_CALL=function_call) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 1039 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
| 1014 ' return func;\n', | 1040 ' return func;\n', |
| 1015 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 1041 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| 1016 | 1042 |
| 1017 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1043 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 1018 return ( | 1044 return ( |
| 1019 interface.id.endswith('Event') and | 1045 interface.id.endswith('Event') and |
| 1020 operation.id.startswith('init') and | 1046 operation.id.startswith('init') and |
| 1021 argument.ext_attrs.get('Default') == 'Undefined' and | 1047 argument.ext_attrs.get('Default') == 'Undefined' and |
| 1022 argument.type.id == 'DOMString') | 1048 argument.type.id == 'DOMString') |
| OLD | NEW |