| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 INTERFACE=self._interface.id, | 254 INTERFACE=self._interface.id, |
| 255 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), | 255 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), |
| 256 CALLBACKS=self._cpp_definitions_emitter.Fragments(), | 256 CALLBACKS=self._cpp_definitions_emitter.Fragments(), |
| 257 RESOLVER=self._cpp_resolver_emitter.Fragments(), | 257 RESOLVER=self._cpp_resolver_emitter.Fragments(), |
| 258 DART_IMPLEMENTATION_CLASS=self._interface_type_info.implementation_name(
), | 258 DART_IMPLEMENTATION_CLASS=self._interface_type_info.implementation_name(
), |
| 259 DART_IMPLEMENTATION_LIBRARY='dart:%s' % self._renamer.GetLibraryName(sel
f._interface)) | 259 DART_IMPLEMENTATION_LIBRARY='dart:%s' % self._renamer.GetLibraryName(sel
f._interface)) |
| 260 | 260 |
| 261 def _GenerateCPPHeader(self): | 261 def _GenerateCPPHeader(self): |
| 262 to_native_emitter = emitter.Emitter() | 262 to_native_emitter = emitter.Emitter() |
| 263 if self._interface_type_info.custom_to_native(): | 263 if self._interface_type_info.custom_to_native(): |
| 264 to_native_emitter.Emit( | 264 return_type = 'PassRefPtr<NativeType>' |
| 265 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H
andle& exception);\n') | 265 to_native_body = ';' |
| 266 else: | 266 else: |
| 267 to_native_emitter.Emit( | 267 return_type = 'NativeType*' |
| 268 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce
ption)\n' | 268 to_native_body = emitter.Format( |
| 269 '\n' |
| 269 ' {\n' | 270 ' {\n' |
| 270 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(hand
le, exception);\n' | 271 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(hand
le, exception);\n' |
| 271 ' }\n', | 272 ' }', |
| 272 INTERFACE=self._interface.id) | 273 INTERFACE=self._interface.id) |
| 273 | 274 |
| 275 to_native_emitter.Emit( |
| 276 ' static $RETURN_TYPE toNative(Dart_Handle handle, Dart_Handle& excep
tion)$TO_NATIVE_BODY\n' |
| 277 '\n' |
| 278 ' static $RETURN_TYPE toNativeWithNullCheck(Dart_Handle handle, Dart_
Handle& exception)\n' |
| 279 ' {\n' |
| 280 ' return Dart_IsNull(handle) ? 0 : toNative(handle, exception);\n
' |
| 281 ' }\n', |
| 282 RETURN_TYPE=return_type, |
| 283 TO_NATIVE_BODY=to_native_body, |
| 284 INTERFACE=self._interface.id) |
| 285 |
| 274 to_dart_emitter = emitter.Emitter() | 286 to_dart_emitter = emitter.Emitter() |
| 275 | 287 |
| 276 ext_attrs = self._interface.ext_attrs | 288 ext_attrs = self._interface.ext_attrs |
| 277 | 289 |
| 278 if ('CustomToJS' in ext_attrs or | 290 if ('CustomToJS' in ext_attrs or |
| 279 ('CustomToJSObject' in ext_attrs and 'TypedArray' not in ext_attrs) or | 291 ('CustomToJSObject' in ext_attrs and 'TypedArray' not in ext_attrs) or |
| 280 'PureInterface' in ext_attrs or | 292 'PureInterface' in ext_attrs or |
| 281 'CPPPureInterface' in ext_attrs or | 293 'CPPPureInterface' in ext_attrs or |
| 282 self._interface_type_info.custom_to_dart()): | 294 self._interface_type_info.custom_to_dart()): |
| 283 to_dart_emitter.Emit( | 295 to_dart_emitter.Emit( |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 return '%s::%s' % (self._interface_type_info.idl_type(), function_name) | 856 return '%s::%s' % (self._interface_type_info.idl_type(), function_name) |
| 845 return '%s%s' % (self._interface_type_info.receiver(), function_name) | 857 return '%s%s' % (self._interface_type_info.receiver(), function_name) |
| 846 | 858 |
| 847 def _IsArgumentOptionalInWebCore(self, operation, argument): | 859 def _IsArgumentOptionalInWebCore(self, operation, argument): |
| 848 if not IsOptional(argument): | 860 if not IsOptional(argument): |
| 849 return False | 861 return False |
| 850 if 'Callback' in argument.ext_attrs: | 862 if 'Callback' in argument.ext_attrs: |
| 851 return False | 863 return False |
| 852 if operation.id in ['addEventListener', 'removeEventListener'] and argument.
id == 'useCapture': | 864 if operation.id in ['addEventListener', 'removeEventListener'] and argument.
id == 'useCapture': |
| 853 return False | 865 return False |
| 854 # Another option would be to adjust in IDLs, but let's keep it here for now | 866 if 'ForceOptional' in argument.ext_attrs: |
| 855 # as it's a single instance. | |
| 856 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope
rty' and argument.id == 'priority': | |
| 857 return False | 867 return False |
| 858 if argument.type.id == 'Dictionary': | 868 if argument.type.id == 'Dictionary': |
| 859 return False | 869 return False |
| 860 return True | 870 return True |
| 861 | 871 |
| 862 def _GenerateCPPIncludes(self, includes): | 872 def _GenerateCPPIncludes(self, includes): |
| 863 return ''.join(['#include %s\n' % include for include in sorted(includes)]) | 873 return ''.join(['#include %s\n' % include for include in sorted(includes)]) |
| 864 | 874 |
| 865 def _ToWebKitName(self, name): | 875 def _ToWebKitName(self, name): |
| 866 name = name[0].lower() + name[1:] | 876 name = name[0].lower() + name[1:] |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 930 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
| 921 ' return func;\n', | 931 ' return func;\n', |
| 922 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 932 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| 923 | 933 |
| 924 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 934 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 925 return ( | 935 return ( |
| 926 interface.id.endswith('Event') and | 936 interface.id.endswith('Event') and |
| 927 operation.id.startswith('init') and | 937 operation.id.startswith('init') and |
| 928 argument.ext_attrs.get('Default') == 'Undefined' and | 938 argument.ext_attrs.get('Default') == 'Undefined' and |
| 929 argument.type.id == 'DOMString') | 939 argument.type.id == 'DOMString') |
| OLD | NEW |