| 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 # TODO(vsm): This logic needs to pulled from the source IDL. These tables are | 16 # TODO(vsm): This logic needs to pulled from the source IDL. These tables are |
| 17 # an ugly workaround. | 17 # an ugly workaround. |
| 18 _cpp_callback_map = { | 18 _cpp_callback_map = { |
| 19 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem', | 19 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem', |
| 20 ('Document', 'fonts'): 'DocumentFontFaceSet', |
| 20 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen', | 21 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen', |
| 21 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen', | 22 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen', |
| 22 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen', | 23 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen', |
| 23 ('Document', 'webkitCancelFullScreen'): 'DocumentFullscreen', | 24 ('Document', 'webkitCancelFullScreen'): 'DocumentFullscreen', |
| 24 ('Document', 'webkitFullscreenEnabled'): 'DocumentFullscreen', | 25 ('Document', 'webkitFullscreenEnabled'): 'DocumentFullscreen', |
| 25 ('Document', 'webkitFullscreenElement'): 'DocumentFullscreen', | 26 ('Document', 'webkitFullscreenElement'): 'DocumentFullscreen', |
| 26 ('Document', 'webkitExitFullscreen'): 'DocumentFullscreen', | 27 ('Document', 'webkitExitFullscreen'): 'DocumentFullscreen', |
| 27 ('DOMWindow', 'crypto'): 'DOMWindowCrypto', | 28 ('DOMWindow', 'crypto'): 'DOMWindowCrypto', |
| 28 ('DOMWindow', 'indexedDB'): 'DOMWindowIndexedDatabase', | 29 ('DOMWindow', 'indexedDB'): 'DOMWindowIndexedDatabase', |
| 29 ('DOMWindow', 'speechSynthesis'): 'DOMWindowSpeechSynthesis', | 30 ('DOMWindow', 'speechSynthesis'): 'DOMWindowSpeechSynthesis', |
| 30 ('DOMWindow', 'webkitNotifications'): 'DOMWindowNotifications', | 31 ('DOMWindow', 'webkitNotifications'): 'DOMWindowNotifications', |
| 31 ('DOMWindow', 'storage'): 'DOMWindowQuota', | 32 ('DOMWindow', 'storage'): 'DOMWindowQuota', |
| 32 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota', | 33 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota', |
| 33 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase', | 34 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase', |
| 34 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem', | 35 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem', |
| 35 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem', | 36 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem', |
| 36 ('DOMWindow', 'atob'): 'DOMWindowBase64', | 37 ('DOMWindow', 'atob'): 'DOMWindowBase64', |
| 37 ('DOMWindow', 'btoa'): 'DOMWindowBase64', | 38 ('DOMWindow', 'btoa'): 'DOMWindowBase64', |
| 38 ('DOMWindow', 'clearTimeout'): 'DOMWindowTimers', | 39 ('DOMWindow', 'clearTimeout'): 'DOMWindowTimers', |
| 39 ('DOMWindow', 'clearInterval'): 'DOMWindowTimers', | 40 ('DOMWindow', 'clearInterval'): 'DOMWindowTimers', |
| 40 ('DOMWindow', 'createImageBitmap'): 'ImageBitmapFactories', | 41 ('DOMWindow', 'createImageBitmap'): 'ImageBitmapFactories', |
| 41 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem', | 42 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem', |
| 43 ('HTMLVideoElement', 'getVideoPlaybackQuality'): 'HTMLVideoElementMediaSource'
, |
| 42 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack', | 44 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack', |
| 43 ('Navigator', 'geolocation'): 'NavigatorGeolocation', | 45 ('Navigator', 'geolocation'): 'NavigatorGeolocation', |
| 44 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota', | 46 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota', |
| 45 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota', | 47 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota', |
| 46 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils', | 48 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils', |
| 47 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils', | 49 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils', |
| 48 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream', | 50 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream', |
| 49 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad', | 51 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad', |
| 50 ('Navigator', 'requestMIDIAccess'): 'NavigatorWebMIDI', | 52 ('Navigator', 'requestMIDIAccess'): 'NavigatorWebMIDI', |
| 51 ('Navigator', 'vibrate'): 'NavigatorVibration', | 53 ('Navigator', 'vibrate'): 'NavigatorVibration', |
| 52 ('Navigator', 'appName'): 'NavigatorID', | 54 ('Navigator', 'appName'): 'NavigatorID', |
| 53 ('Navigator', 'appVersion'): 'NavigatorID', | 55 ('Navigator', 'appVersion'): 'NavigatorID', |
| 54 ('Navigator', 'appCodeName'): 'NavigatorID', | 56 ('Navigator', 'appCodeName'): 'NavigatorID', |
| 55 ('Navigator', 'platform'): 'NavigatorID', | 57 ('Navigator', 'platform'): 'NavigatorID', |
| 56 ('Navigator', 'product'): 'NavigatorID', | 58 ('Navigator', 'product'): 'NavigatorID', |
| 57 ('Navigator', 'userAgent'): 'NavigatorID', | 59 ('Navigator', 'userAgent'): 'NavigatorID', |
| 58 ('Navigator', 'onLine'): 'NavigatorOnLine', | 60 ('Navigator', 'onLine'): 'NavigatorOnLine', |
| 59 ('Navigator', 'registerServiceWorker'): 'NavigatorServiceWorker', | 61 ('Navigator', 'registerServiceWorker'): 'NavigatorServiceWorker', |
| 60 ('Navigator', 'unregisterServiceWorker'): 'NavigatorServiceWorker', | 62 ('Navigator', 'unregisterServiceWorker'): 'NavigatorServiceWorker', |
| 63 ('Navigator', 'maxTouchPoints'): 'NavigatorEvents', |
| 61 ('WorkerGlobalScope', 'crypto'): 'WorkerGlobalScopeCrypto', | 64 ('WorkerGlobalScope', 'crypto'): 'WorkerGlobalScopeCrypto', |
| 62 ('WorkerGlobalScope', 'indexedDB'): 'WorkerGlobalScopeIndexedDatabase', | 65 ('WorkerGlobalScope', 'indexedDB'): 'WorkerGlobalScopeIndexedDatabase', |
| 63 ('WorkerGlobalScope', 'webkitNotifications'): 'WorkerGlobalScopeNotifications'
, | 66 ('WorkerGlobalScope', 'webkitNotifications'): 'WorkerGlobalScopeNotifications'
, |
| 64 ('WorkerGlobalScope', 'openDatabase'): 'WorkerGlobalScopeWebDatabase', | 67 ('WorkerGlobalScope', 'openDatabase'): 'WorkerGlobalScopeWebDatabase', |
| 65 ('WorkerGlobalScope', 'openDatabaseSync'): 'WorkerGlobalScopeWebDatabase', | 68 ('WorkerGlobalScope', 'openDatabaseSync'): 'WorkerGlobalScopeWebDatabase', |
| 66 ('WorkerGlobalScope', 'performance'): 'WorkerGlobalScopePerformance', | 69 ('WorkerGlobalScope', 'performance'): 'WorkerGlobalScopePerformance', |
| 67 ('WorkerGlobalScope', 'webkitRequestFileSystem'): 'WorkerGlobalScopeFileSystem
', | 70 ('WorkerGlobalScope', 'webkitRequestFileSystem'): 'WorkerGlobalScopeFileSystem
', |
| 68 ('WorkerGlobalScope', 'webkitRequestFileSystemSync'): 'WorkerGlobalScopeFileSy
stem', | 71 ('WorkerGlobalScope', 'webkitRequestFileSystemSync'): 'WorkerGlobalScopeFileSy
stem', |
| 69 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemURL'): 'WorkerGlobalScopeFi
leSystem', | 72 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemURL'): 'WorkerGlobalScopeFi
leSystem', |
| 70 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemSyncURL'): 'WorkerGlobalSco
peFileSystem', | 73 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemSyncURL'): 'WorkerGlobalSco
peFileSystem', |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource', | 85 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource', |
| 83 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', | 86 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', |
| 84 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', | 87 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', |
| 85 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', | 88 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', |
| 86 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaSource', | 89 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaSource', |
| 87 ('DOMURL', '_createObjectURL_4Callback'): 'URLMediaStream', | 90 ('DOMURL', '_createObjectURL_4Callback'): 'URLMediaStream', |
| 88 } | 91 } |
| 89 | 92 |
| 90 _cpp_partial_map = {} | 93 _cpp_partial_map = {} |
| 91 | 94 |
| 95 # TODO(vsm): This should be recoverable from IDL, but we appear to not |
| 96 # track the necessary info. |
| 97 _url_utils = ['hash', 'host', 'hostname', 'origin', |
| 98 'password', 'pathname', 'port', 'protocol', |
| 99 'search', 'username'] |
| 100 _cpp_static_call_map = { |
| 101 'DOMURL': _url_utils + ['href', 'toString'], |
| 102 'HTMLAnchorElement': _url_utils, |
| 103 'HTMLAreaElement': _url_utils, |
| 104 } |
| 105 |
| 92 def _GetCPPPartialNames(interface): | 106 def _GetCPPPartialNames(interface): |
| 93 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id) | 107 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id) |
| 94 if not _cpp_partial_map: | 108 if not _cpp_partial_map: |
| 95 for (type, member) in _cpp_callback_map.keys(): | 109 for (type, member) in _cpp_callback_map.keys(): |
| 96 if type not in _cpp_partial_map: | 110 if type not in _cpp_partial_map: |
| 97 _cpp_partial_map[type] = set([]) | 111 _cpp_partial_map[type] = set([]) |
| 98 | 112 |
| 99 name_with_path = _cpp_callback_map[(type, member)] | 113 name_with_path = _cpp_callback_map[(type, member)] |
| 100 if name_with_path in _cpp_import_map: | 114 if name_with_path in _cpp_import_map: |
| 101 name_with_path = _cpp_import_map[name_with_path] | 115 name_with_path = _cpp_import_map[name_with_path] |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 def GenerateCallback(self, info): | 170 def GenerateCallback(self, info): |
| 157 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id): | 171 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id): |
| 158 return | 172 return |
| 159 | 173 |
| 160 cpp_impl_includes = set(['"' + partial + '.h"' | 174 cpp_impl_includes = set(['"' + partial + '.h"' |
| 161 for partial in _GetCPPPartialNames(self._interface)
]) | 175 for partial in _GetCPPPartialNames(self._interface)
]) |
| 162 cpp_header_handlers_emitter = emitter.Emitter() | 176 cpp_header_handlers_emitter = emitter.Emitter() |
| 163 cpp_impl_handlers_emitter = emitter.Emitter() | 177 cpp_impl_handlers_emitter = emitter.Emitter() |
| 164 class_name = 'Dart%s' % self._interface.id | 178 class_name = 'Dart%s' % self._interface.id |
| 165 for operation in self._interface.operations: | 179 for operation in self._interface.operations: |
| 180 function_name = operation.id |
| 166 parameters = [] | 181 parameters = [] |
| 167 arguments = [] | 182 arguments = [] |
| 183 if operation.ext_attrs.get('CallWith') == 'ThisValue': |
| 184 parameters.append('ScriptValue scriptValue') |
| 168 conversion_includes = [] | 185 conversion_includes = [] |
| 169 for argument in operation.arguments: | 186 for argument in operation.arguments: |
| 170 argument_type_info = self._TypeInfo(argument.type.id) | 187 argument_type_info = self._TypeInfo(argument.type.id) |
| 171 parameters.append('%s %s' % (argument_type_info.parameter_type(), | 188 parameters.append('%s %s' % (argument_type_info.parameter_type(), |
| 172 argument.id)) | 189 argument.id)) |
| 173 arguments.append(argument_type_info.to_dart_conversion(argument.id)) | 190 arguments.append(argument_type_info.to_dart_conversion(argument.id)) |
| 174 conversion_includes.extend(argument_type_info.conversion_includes()) | 191 conversion_includes.extend(argument_type_info.conversion_includes()) |
| 175 | 192 |
| 193 # FIXME(vsm): Handle ThisValue attribute. |
| 194 if operation.ext_attrs.get('CallWith') == 'ThisValue': |
| 195 cpp_header_handlers_emitter.Emit( |
| 196 '\n' |
| 197 ' virtual bool $FUNCTION($PARAMETERS) {\n' |
| 198 ' DART_UNIMPLEMENTED();\n' |
| 199 ' return false;\n' |
| 200 ' }\n', |
| 201 FUNCTION=function_name, |
| 202 PARAMETERS=', '.join(parameters)) |
| 203 continue |
| 204 |
| 176 cpp_header_handlers_emitter.Emit( | 205 cpp_header_handlers_emitter.Emit( |
| 177 '\n' | 206 '\n' |
| 178 ' virtual bool handleEvent($PARAMETERS);\n', | 207 ' virtual bool $FUNCTION($PARAMETERS);\n', |
| 208 FUNCTION=function_name, |
| 179 PARAMETERS=', '.join(parameters)) | 209 PARAMETERS=', '.join(parameters)) |
| 180 | 210 |
| 181 if 'Custom' in operation.ext_attrs: | 211 if 'Custom' in operation.ext_attrs: |
| 182 continue | 212 continue |
| 183 | 213 |
| 184 cpp_impl_includes |= set(conversion_includes) | 214 cpp_impl_includes |= set(conversion_includes) |
| 185 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg
uments) | 215 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg
uments) |
| 186 if not len(arguments): | 216 if not len(arguments): |
| 187 arguments_declaration = 'Dart_Handle* arguments = 0' | 217 arguments_declaration = 'Dart_Handle* arguments = 0' |
| 188 cpp_impl_handlers_emitter.Emit( | 218 cpp_impl_handlers_emitter.Emit( |
| 189 '\n' | 219 '\n' |
| 190 'bool $CLASS_NAME::handleEvent($PARAMETERS)\n' | 220 'bool $CLASS_NAME::$FUNCTION($PARAMETERS)\n' |
| 191 '{\n' | 221 '{\n' |
| 192 ' if (!m_callback.isIsolateAlive())\n' | 222 ' if (!m_callback.isIsolateAlive())\n' |
| 193 ' return false;\n' | 223 ' return false;\n' |
| 194 ' DartIsolateScope scope(m_callback.isolate());\n' | 224 ' DartIsolateScope scope(m_callback.isolate());\n' |
| 195 ' DartApiScope apiScope;\n' | 225 ' DartApiScope apiScope;\n' |
| 196 ' $ARGUMENTS_DECLARATION;\n' | 226 ' $ARGUMENTS_DECLARATION;\n' |
| 197 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n' | 227 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n' |
| 198 '}\n', | 228 '}\n', |
| 199 CLASS_NAME=class_name, | 229 CLASS_NAME=class_name, |
| 230 FUNCTION=function_name, |
| 200 PARAMETERS=', '.join(parameters), | 231 PARAMETERS=', '.join(parameters), |
| 201 ARGUMENTS_DECLARATION=arguments_declaration, | 232 ARGUMENTS_DECLARATION=arguments_declaration, |
| 202 ARGUMENT_COUNT=len(arguments)) | 233 ARGUMENT_COUNT=len(arguments)) |
| 203 | 234 |
| 204 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter( | 235 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter( |
| 205 self._interface.id, | 236 self._interface.id, |
| 206 self._renamer.GetLibraryName(self._interface), | 237 self._renamer.GetLibraryName(self._interface), |
| 207 True) | 238 True) |
| 208 cpp_header_emitter.Emit( | 239 cpp_header_emitter.Emit( |
| 209 self._template_loader.Load('cpp_callback_header.template'), | 240 self._template_loader.Load('cpp_callback_header.template'), |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr
.type.id)) | 566 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr
.type.id)) |
| 536 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext
_attrs) | 567 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext
_attrs) |
| 537 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, | 568 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, |
| 538 dart_declaration, 'Setter', is_custom) | 569 dart_declaration, 'Setter', is_custom) |
| 539 if is_custom: | 570 if is_custom: |
| 540 return | 571 return |
| 541 | 572 |
| 542 if 'Reflect' in attr.ext_attrs: | 573 if 'Reflect' in attr.ext_attrs: |
| 543 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() | 574 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() |
| 544 else: | 575 else: |
| 545 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', | 576 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)', |
| 546 lambda s: s.group(1).upper(), | 577 lambda s: s.group(1).upper(), |
| 547 attr.id) | 578 attr.id) |
| 548 webcore_function_name = 'set%s' % webcore_function_name | 579 webcore_function_name = 'set%s' % webcore_function_name |
| 549 | 580 |
| 550 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, attr) | 581 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, attr) |
| 551 self._GenerateNativeCallback( | 582 self._GenerateNativeCallback( |
| 552 cpp_callback_name, | 583 cpp_callback_name, |
| 553 True, | 584 True, |
| 554 function_expression, | 585 function_expression, |
| 555 attr, | 586 attr, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 needs_receiver, | 765 needs_receiver, |
| 735 function_expression, | 766 function_expression, |
| 736 node, | 767 node, |
| 737 arguments, | 768 arguments, |
| 738 return_type, | 769 return_type, |
| 739 return_type_is_nullable, | 770 return_type_is_nullable, |
| 740 raises_dom_exception, | 771 raises_dom_exception, |
| 741 generate_custom_element_scope_if_needed=False): | 772 generate_custom_element_scope_if_needed=False): |
| 742 | 773 |
| 743 ext_attrs = node.ext_attrs | 774 ext_attrs = node.ext_attrs |
| 775 if self._IsStatic(node.id): |
| 776 needs_receiver = True |
| 744 | 777 |
| 745 cpp_arguments = [] | 778 cpp_arguments = [] |
| 746 runtime_check = None | 779 runtime_check = None |
| 747 raises_exceptions = raises_dom_exception or arguments | 780 raises_exceptions = raises_dom_exception or arguments |
| 748 needs_custom_element_callbacks = False | 781 needs_custom_element_callbacks = False |
| 749 | 782 |
| 750 # TODO(antonm): unify with ScriptState below. | 783 # TODO(antonm): unify with ScriptState below. |
| 751 requires_stack_info = (ext_attrs.get('CallWith') == 'ScriptArguments|ScriptS
tate' or | 784 requires_stack_info = (ext_attrs.get('CallWith') == 'ScriptArguments|ScriptS
tate' or |
| 752 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume
nts|ScriptState' or | 785 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume
nts|ScriptState' or |
| 753 ext_attrs.get('CallWith') == 'ScriptArguments&ScriptS
tate' or | 786 ext_attrs.get('CallWith') == 'ScriptArguments&ScriptS
tate' or |
| 754 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume
nts&ScriptState') | 787 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume
nts&ScriptState') |
| 755 if requires_stack_info: | 788 if requires_stack_info: |
| 756 raises_exceptions = True | 789 raises_exceptions = True |
| 757 cpp_arguments = ['&state', 'scriptArguments.release()'] | 790 cpp_arguments = ['&state', 'scriptArguments.release()'] |
| 758 # WebKit uses scriptArguments to reconstruct last argument, so | 791 # WebKit uses scriptArguments to reconstruct last argument, so |
| 759 # it's not needed and should be just removed. | 792 # it's not needed and should be just removed. |
| 760 arguments = arguments[:-1] | 793 arguments = arguments[:-1] |
| 761 | 794 |
| 762 # TODO(antonm): unify with ScriptState below. | 795 # TODO(antonm): unify with ScriptState below. |
| 763 requires_script_arguments = (ext_attrs.get('CallWith') == 'ScriptArguments'
or | 796 requires_script_arguments = (ext_attrs.get('CallWith') == 'ScriptArguments'
or |
| 764 ext_attrs.get('ConstructorCallWith') == 'Script
Arguments') | 797 ext_attrs.get('ConstructorCallWith') == 'Script
Arguments') |
| 765 if requires_script_arguments: | 798 if requires_script_arguments: |
| 766 raises_exceptions = True | 799 raises_exceptions = True |
| 767 cpp_arguments = ['scriptArguments.release()'] | 800 cpp_arguments = ['scriptArguments.release()'] |
| 768 # WebKit uses scriptArguments to reconstruct last argument, so | 801 # WebKit uses scriptArguments to reconstruct last argument, so |
| 769 # it's not needed and should be just removed. | 802 # it's not needed and should be just removed. |
| 770 arguments = arguments[:-1] | 803 arguments = arguments[:-1] |
| 771 | 804 |
| 772 requires_script_execution_context = (ext_attrs.get('CallWith') == 'ScriptExe
cutionContext' or | 805 requires_script_execution_context = (ext_attrs.get('CallWith') == 'Execution
Context' or |
| 773 ext_attrs.get('ConstructorCallWith') ==
'ScriptExecutionContext') | 806 ext_attrs.get('ConstructorCallWith') ==
'ExecutionContext') |
| 774 | 807 |
| 775 requires_document = ext_attrs.get('ConstructorCallWith') == 'Document' | 808 requires_document = ext_attrs.get('ConstructorCallWith') == 'Document' |
| 776 | 809 |
| 777 if requires_script_execution_context: | 810 if requires_script_execution_context: |
| 778 raises_exceptions = True | 811 raises_exceptions = True |
| 779 cpp_arguments = ['context'] | 812 cpp_arguments = ['context'] |
| 780 | 813 |
| 781 requires_script_state = (ext_attrs.get('CallWith') == 'ScriptState' or | 814 requires_script_state = (ext_attrs.get('CallWith') == 'ScriptState' or |
| 782 ext_attrs.get('ConstructorCallWith') == 'ScriptStat
e') | 815 ext_attrs.get('ConstructorCallWith') == 'ScriptStat
e') |
| 783 if requires_script_state: | 816 if requires_script_state: |
| 784 raises_exceptions = True | 817 raises_exceptions = True |
| 785 cpp_arguments = ['&state'] | 818 cpp_arguments = ['&state'] |
| 786 | 819 |
| 787 requires_dom_window = 'NamedConstructor' in ext_attrs | 820 requires_dom_window = 'NamedConstructor' in ext_attrs |
| 788 if requires_dom_window or requires_document: | 821 if requires_dom_window or requires_document: |
| 789 raises_exceptions = True | 822 raises_exceptions = True |
| 790 cpp_arguments = ['document'] | 823 cpp_arguments = ['document'] |
| 791 | 824 |
| 792 if 'ImplementedBy' in ext_attrs: | 825 if 'ImplementedBy' in ext_attrs: |
| 793 assert needs_receiver | 826 assert needs_receiver |
| 794 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy']) | 827 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy']) |
| 795 cpp_arguments.append('receiver') | 828 cpp_arguments.append('receiver') |
| 796 | 829 |
| 797 if 'Reflect' in ext_attrs: | 830 if 'Reflect' in ext_attrs: |
| 798 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] | 831 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] |
| 799 | 832 |
| 800 if generate_custom_element_scope_if_needed and (ext_attrs.get('CustomElement
Callbacks', 'None') != 'None' or 'Reflect' in ext_attrs): | 833 if generate_custom_element_scope_if_needed and (ext_attrs.get('CustomElement
Callbacks', 'None') != 'None' or 'Reflect' in ext_attrs): |
| 801 self._cpp_impl_includes.add('"core/dom/CustomElementCallbackDispatcher.h"'
) | 834 self._cpp_impl_includes.add('"core/dom/custom/CustomElementCallbackDispatc
her.h"') |
| 802 needs_custom_element_callbacks = True | 835 needs_custom_element_callbacks = True |
| 803 | 836 |
| 804 if return_type_is_nullable: | 837 if return_type_is_nullable: |
| 805 cpp_arguments = ['isNull'] | 838 cpp_arguments = ['isNull'] |
| 806 | 839 |
| 807 v8EnabledPerContext = ext_attrs.get('synthesizedV8EnabledPerContext', ext_at
trs.get('V8EnabledPerContext')) | 840 v8EnabledPerContext = ext_attrs.get('synthesizedV8EnabledPerContext', ext_at
trs.get('V8EnabledPerContext')) |
| 808 v8EnabledAtRuntime = ext_attrs.get('synthesizedV8EnabledAtRuntime', ext_attr
s.get('V8EnabledAtRuntime')) | 841 v8EnabledAtRuntime = ext_attrs.get('synthesizedV8EnabledAtRuntime', ext_attr
s.get('V8EnabledAtRuntime')) |
| 809 assert(not (v8EnabledPerContext and v8EnabledAtRuntime)) | 842 assert(not (v8EnabledPerContext and v8EnabledAtRuntime)) |
| 810 | 843 |
| 811 if v8EnabledPerContext: | 844 if v8EnabledPerContext: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 ' return;\n' | 885 ' return;\n' |
| 853 ' }\n') | 886 ' }\n') |
| 854 | 887 |
| 855 if runtime_check: | 888 if runtime_check: |
| 856 body_emitter.Emit( | 889 body_emitter.Emit( |
| 857 '$RUNTIME_CHECK\n', | 890 '$RUNTIME_CHECK\n', |
| 858 RUNTIME_CHECK=runtime_check) | 891 RUNTIME_CHECK=runtime_check) |
| 859 | 892 |
| 860 if requires_script_execution_context: | 893 if requires_script_execution_context: |
| 861 body_emitter.Emit( | 894 body_emitter.Emit( |
| 862 ' ScriptExecutionContext* context = DartUtilities::scriptExecut
ionContext();\n' | 895 ' ExecutionContext* context = DartUtilities::scriptExecutionCon
text();\n' |
| 863 ' if (!context) {\n' | 896 ' if (!context) {\n' |
| 864 ' exception = Dart_NewStringFromCString("Failed to retrieve
a context");\n' | 897 ' exception = Dart_NewStringFromCString("Failed to retrieve
a context");\n' |
| 865 ' goto fail;\n' | 898 ' goto fail;\n' |
| 866 ' }\n\n') | 899 ' }\n\n') |
| 867 | 900 |
| 868 if requires_script_state: | 901 if requires_script_state: |
| 869 body_emitter.Emit( | 902 body_emitter.Emit( |
| 870 ' ScriptState* currentState = DartUtilities::currentScriptState
();\n' | 903 ' ScriptState* currentState = DartUtilities::currentScriptState
();\n' |
| 871 ' if (!currentState) {\n' | 904 ' if (!currentState) {\n' |
| 872 ' exception = Dart_NewStringFromCString("Failed to retrieve
a script state");\n' | 905 ' exception = Dart_NewStringFromCString("Failed to retrieve
a script state");\n' |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 if needs_receiver: | 1032 if needs_receiver: |
| 1000 interface_name = self._interface_type_info.native_type() | 1033 interface_name = self._interface_type_info.native_type() |
| 1001 # Hack to determine if this came from the _cpp_callback_map. | 1034 # Hack to determine if this came from the _cpp_callback_map. |
| 1002 # In this case, the getter is mapped to a static method. | 1035 # In this case, the getter is mapped to a static method. |
| 1003 if (not function_expression.startswith('receiver->') and | 1036 if (not function_expression.startswith('receiver->') and |
| 1004 not function_expression.startswith(interface_name + '::')): | 1037 not function_expression.startswith(interface_name + '::')): |
| 1005 if interface_name == 'DOMWindow' or interface_name == 'Navigator' or int
erface_name == 'WorkerGlobalScope': | 1038 if interface_name == 'DOMWindow' or interface_name == 'Navigator' or int
erface_name == 'WorkerGlobalScope': |
| 1006 cpp_arguments.insert(0, 'receiver') | 1039 cpp_arguments.insert(0, 'receiver') |
| 1007 else: | 1040 else: |
| 1008 cpp_arguments.append('receiver') | 1041 cpp_arguments.append('receiver') |
| 1042 elif self._IsStatic(node.id): |
| 1043 cpp_arguments.insert(0, 'receiver') |
| 1009 | 1044 |
| 1010 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments)) | 1045 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments)) |
| 1011 if return_type == 'void': | 1046 if return_type == 'void': |
| 1012 invocation_emitter.Emit( | 1047 invocation_emitter.Emit( |
| 1013 ' $FUNCTION_CALL;\n', | 1048 ' $FUNCTION_CALL;\n', |
| 1014 FUNCTION_CALL=function_call) | 1049 FUNCTION_CALL=function_call) |
| 1015 else: | 1050 else: |
| 1016 return_type_info = self._TypeInfo(return_type) | 1051 return_type_info = self._TypeInfo(return_type) |
| 1017 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) | 1052 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) |
| 1018 | 1053 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', | 1133 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', |
| 1099 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', | 1134 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', |
| 1100 'onmouseup', 'onresize', 'onscroll', 'onunload'] | 1135 'onmouseup', 'onresize', 'onscroll', 'onunload'] |
| 1101 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: | 1136 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: |
| 1102 namespace = 'SVGNames' | 1137 namespace = 'SVGNames' |
| 1103 self._cpp_impl_includes.add('"%s.h"' % namespace) | 1138 self._cpp_impl_includes.add('"%s.h"' % namespace) |
| 1104 | 1139 |
| 1105 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() | 1140 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() |
| 1106 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) | 1141 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) |
| 1107 | 1142 |
| 1143 def _IsStatic(self, attribute_name): |
| 1144 cpp_type_name = self._interface_type_info.native_type() |
| 1145 if cpp_type_name in _cpp_static_call_map: |
| 1146 return attribute_name in _cpp_static_call_map[cpp_type_name] |
| 1147 return False |
| 1148 |
| 1108 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node, cpp_call
back_name=None): | 1149 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node, cpp_call
back_name=None): |
| 1109 if 'ImplementedBy' in idl_node.ext_attrs: | 1150 if 'ImplementedBy' in idl_node.ext_attrs: |
| 1110 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) | 1151 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) |
| 1111 cpp_type_name = self._interface_type_info.native_type() | 1152 cpp_type_name = self._interface_type_info.native_type() |
| 1112 impl_type_name = _GetCPPTypeName(cpp_type_name, function_name, cpp_callback_
name) | 1153 impl_type_name = _GetCPPTypeName(cpp_type_name, function_name, cpp_callback_
name) |
| 1113 if idl_node.is_static: | 1154 if idl_node.is_static or self._IsStatic(idl_node.id): |
| 1114 return '%s::%s' % (impl_type_name, function_name) | 1155 return '%s::%s' % (impl_type_name, function_name) |
| 1115 if cpp_type_name == impl_type_name: | 1156 if cpp_type_name == impl_type_name: |
| 1116 return '%s%s' % (self._interface_type_info.receiver(), function_name) | 1157 return '%s%s' % (self._interface_type_info.receiver(), function_name) |
| 1117 else: | 1158 else: |
| 1118 return '%s::%s' % (impl_type_name, function_name) | 1159 return '%s::%s' % (impl_type_name, function_name) |
| 1119 | 1160 |
| 1120 def _IsArgumentOptionalInWebCore(self, operation, argument): | 1161 def _IsArgumentOptionalInWebCore(self, operation, argument): |
| 1121 if not IsOptional(argument): | 1162 if not IsOptional(argument): |
| 1122 return False | 1163 return False |
| 1123 if 'Callback' in argument.ext_attrs: | 1164 if 'Callback' in argument.ext_attrs: |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 e.Emit("};\n"); | 1320 e.Emit("};\n"); |
| 1280 e.Emit('\n'); | 1321 e.Emit('\n'); |
| 1281 e.Emit('} // namespace WebCore\n'); | 1322 e.Emit('} // namespace WebCore\n'); |
| 1282 | 1323 |
| 1283 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1324 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 1284 return ( | 1325 return ( |
| 1285 interface.id.endswith('Event') and | 1326 interface.id.endswith('Event') and |
| 1286 operation.id.startswith('init') and | 1327 operation.id.startswith('init') and |
| 1287 argument.ext_attrs.get('Default') == 'Undefined' and | 1328 argument.ext_attrs.get('Default') == 'Undefined' and |
| 1288 argument.type.id == 'DOMString') | 1329 argument.type.id == 'DOMString') |
| OLD | NEW |