Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Side by Side Diff: tools/dom/scripts/systemnative.py

Issue 150783005: Fixes for 1750 roll (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More fixes for 1750 Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 21 matching lines...) Expand all
32 ('DOMWindow', 'storage'): 'DOMWindowQuota', 32 ('DOMWindow', 'storage'): 'DOMWindowQuota',
33 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota', 33 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota',
34 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase', 34 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase',
35 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem', 35 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem',
36 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem', 36 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem',
37 ('DOMWindow', 'atob'): 'DOMWindowBase64', 37 ('DOMWindow', 'atob'): 'DOMWindowBase64',
38 ('DOMWindow', 'btoa'): 'DOMWindowBase64', 38 ('DOMWindow', 'btoa'): 'DOMWindowBase64',
39 ('DOMWindow', 'clearTimeout'): 'DOMWindowTimers', 39 ('DOMWindow', 'clearTimeout'): 'DOMWindowTimers',
40 ('DOMWindow', 'clearInterval'): 'DOMWindowTimers', 40 ('DOMWindow', 'clearInterval'): 'DOMWindowTimers',
41 ('DOMWindow', 'createImageBitmap'): 'ImageBitmapFactories', 41 ('DOMWindow', 'createImageBitmap'): 'ImageBitmapFactories',
42 ('Element', 'animate'): 'ElementAnimation',
42 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem', 43 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem',
43 ('HTMLVideoElement', 'getVideoPlaybackQuality'): 'HTMLVideoElementMediaSource' , 44 ('HTMLVideoElement', 'getVideoPlaybackQuality'): 'HTMLVideoElementMediaSource' ,
44 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack', 45 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack',
45 ('Navigator', 'geolocation'): 'NavigatorGeolocation', 46 ('Navigator', 'geolocation'): 'NavigatorGeolocation',
46 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota', 47 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota',
47 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota', 48 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota',
48 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils', 49 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils',
49 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils', 50 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils',
50 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream', 51 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream',
51 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad', 52 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad',
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id): 193 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id):
193 return 194 return
194 195
195 cpp_impl_includes = set(['"' + partial + '.h"' 196 cpp_impl_includes = set(['"' + partial + '.h"'
196 for partial in _GetCPPPartialNames(self._interface) ]) 197 for partial in _GetCPPPartialNames(self._interface) ])
197 cpp_header_handlers_emitter = emitter.Emitter() 198 cpp_header_handlers_emitter = emitter.Emitter()
198 cpp_impl_handlers_emitter = emitter.Emitter() 199 cpp_impl_handlers_emitter = emitter.Emitter()
199 class_name = 'Dart%s' % self._interface.id 200 class_name = 'Dart%s' % self._interface.id
200 for operation in self._interface.operations: 201 for operation in self._interface.operations:
201 function_name = operation.id 202 function_name = operation.id
203 return_type = self.SecureOutputType(operation.type.id)
202 parameters = [] 204 parameters = []
203 arguments = [] 205 arguments = []
204 if operation.ext_attrs.get('CallWith') == 'ThisValue': 206 if operation.ext_attrs.get('CallWith') == 'ThisValue':
205 parameters.append('ScriptValue scriptValue') 207 parameters.append('ScriptValue scriptValue')
206 conversion_includes = [] 208 conversion_includes = []
207 for argument in operation.arguments: 209 for argument in operation.arguments:
208 argument_type_info = self._TypeInfo(argument.type.id) 210 argument_type_info = self._TypeInfo(argument.type.id)
209 parameters.append('%s %s' % (argument_type_info.parameter_type(), 211 parameters.append('%s %s' % (argument_type_info.parameter_type(),
210 argument.id)) 212 argument.id))
211 arguments.append(argument_type_info.to_dart_conversion(argument.id)) 213 arguments.append(argument_type_info.to_dart_conversion(argument.id))
212 conversion_includes.extend(argument_type_info.conversion_includes()) 214 conversion_includes.extend(argument_type_info.conversion_includes())
213 215
214 # FIXME(vsm): Handle ThisValue attribute. 216 # FIXME(vsm): Handle ThisValue attribute.
217 if (return_type == 'void'):
218 ret = ''
219 else:
220 ret = ' return 0;\n'
221
215 if operation.ext_attrs.get('CallWith') == 'ThisValue': 222 if operation.ext_attrs.get('CallWith') == 'ThisValue':
216 cpp_header_handlers_emitter.Emit( 223 cpp_header_handlers_emitter.Emit(
217 '\n' 224 '\n'
218 ' virtual bool $FUNCTION($PARAMETERS) {\n' 225 ' virtual $RETURN_TYPE $FUNCTION($PARAMETERS) {\n'
219 ' DART_UNIMPLEMENTED();\n' 226 ' DART_UNIMPLEMENTED();\n'
220 ' return false;\n' 227 '$RET'
221 ' }\n', 228 ' }\n',
229 RETURN_TYPE=return_type,
230 RET=ret,
222 FUNCTION=function_name, 231 FUNCTION=function_name,
223 PARAMETERS=', '.join(parameters)) 232 PARAMETERS=', '.join(parameters))
224 continue 233 continue
225 234
226 cpp_header_handlers_emitter.Emit( 235 cpp_header_handlers_emitter.Emit(
227 '\n' 236 '\n'
228 ' virtual bool $FUNCTION($PARAMETERS);\n', 237 ' virtual $RETURN_TYPE $FUNCTION($PARAMETERS);\n',
238 RETURN_TYPE=return_type,
229 FUNCTION=function_name, 239 FUNCTION=function_name,
230 PARAMETERS=', '.join(parameters)) 240 PARAMETERS=', '.join(parameters))
231 241
232 if 'Custom' in operation.ext_attrs: 242 if 'Custom' in operation.ext_attrs:
233 continue 243 continue
234 244
235 cpp_impl_includes |= set(conversion_includes) 245 cpp_impl_includes |= set(conversion_includes)
236 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg uments) 246 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg uments)
237 if not len(arguments): 247 if not len(arguments):
238 arguments_declaration = 'Dart_Handle* arguments = 0' 248 arguments_declaration = 'Dart_Handle* arguments = 0'
249 if (return_type == 'void'):
250 ret1 = 'return'
251 ret2 = ''
252 else:
253 ret1 = 'return 0'
254 ret2 = ' return'
239 cpp_impl_handlers_emitter.Emit( 255 cpp_impl_handlers_emitter.Emit(
240 '\n' 256 '\n'
241 'bool $CLASS_NAME::$FUNCTION($PARAMETERS)\n' 257 '$RETURN_TYPE $CLASS_NAME::$FUNCTION($PARAMETERS)\n'
242 '{\n' 258 '{\n'
243 ' if (!m_callback.isIsolateAlive())\n' 259 ' if (!m_callback.isIsolateAlive())\n'
244 ' return false;\n' 260 ' $RET1;\n'
245 ' DartIsolateScope scope(m_callback.isolate());\n' 261 ' DartIsolateScope scope(m_callback.isolate());\n'
246 ' DartApiScope apiScope;\n' 262 ' DartApiScope apiScope;\n'
247 ' $ARGUMENTS_DECLARATION;\n' 263 ' $ARGUMENTS_DECLARATION;\n'
248 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n' 264 ' $RET2 m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n'
249 '}\n', 265 '}\n',
266 RETURN_TYPE=return_type,
267 RET1=ret1,
268 RET2=ret2,
250 CLASS_NAME=class_name, 269 CLASS_NAME=class_name,
251 FUNCTION=function_name, 270 FUNCTION=function_name,
252 PARAMETERS=', '.join(parameters), 271 PARAMETERS=', '.join(parameters),
253 ARGUMENTS_DECLARATION=arguments_declaration, 272 ARGUMENTS_DECLARATION=arguments_declaration,
254 ARGUMENT_COUNT=len(arguments)) 273 ARGUMENT_COUNT=len(arguments))
255 274
256 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter( 275 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(
257 self._interface.id, 276 self._interface.id,
258 self._renamer.GetLibraryName(self._interface), 277 self._renamer.GetLibraryName(self._interface),
259 True) 278 True)
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 ' }\n' 520 ' }\n'
502 ' }\n' 521 ' }\n'
503 ' }\n' 522 ' }\n'
504 ' }\n', 523 ' }\n',
505 INTERFACE=self._interface.id) 524 INTERFACE=self._interface.id)
506 525
507 if ('CustomToV8' in ext_attrs or 526 if ('CustomToV8' in ext_attrs or
508 'PureInterface' in ext_attrs or 527 'PureInterface' in ext_attrs or
509 'CPPPureInterface' in ext_attrs or 528 'CPPPureInterface' in ext_attrs or
510 'SpecialWrapFor' in ext_attrs or 529 'SpecialWrapFor' in ext_attrs or
530 ('Custom' in ext_attrs and ext_attrs['Custom'] == 'Wrap') or
531 ('Custom' in ext_attrs and ext_attrs['Custom'] == 'ToV8') or
511 self._interface_type_info.custom_to_dart()): 532 self._interface_type_info.custom_to_dart()):
512 to_dart_emitter.Emit( 533 to_dart_emitter.Emit(
513 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType * value);\n') 534 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType * value);\n')
514 else: 535 else:
515 to_dart_emitter.Emit( 536 to_dart_emitter.Emit(
516 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType * value)\n' 537 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType * value)\n'
517 ' {\n' 538 ' {\n'
518 ' return DartDOMWrapper::createWrapper<Dart$(INTERFACE)>(domDat a, value);\n' 539 ' return DartDOMWrapper::createWrapper<Dart$(INTERFACE)>(domDat a, value);\n'
519 ' }\n', 540 ' }\n',
520 INTERFACE=self._interface.id) 541 INTERFACE=self._interface.id)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if attr.id == 'operator': 600 if attr.id == 'operator':
580 webcore_function_name = '_operator' 601 webcore_function_name = '_operator'
581 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': 602 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString':
582 webcore_function_name = 'svgTarget' 603 webcore_function_name = 'svgTarget'
583 elif attr.id == 'CSS': 604 elif attr.id == 'CSS':
584 webcore_function_name = 'css' 605 webcore_function_name = 'css'
585 else: 606 else:
586 webcore_function_name = self._ToWebKitName(attr.id) 607 webcore_function_name = self._ToWebKitName(attr.id)
587 608
588 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 609 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
610 raises = ('RaisesException' in attr.ext_attrs and
611 attr.ext_attrs['RaisesException'] != 'Setter')
589 self._GenerateNativeCallback( 612 self._GenerateNativeCallback(
590 cpp_callback_name, 613 cpp_callback_name,
591 True, 614 True,
592 function_expression, 615 function_expression,
593 attr, 616 attr,
594 [], 617 [],
595 attr.type.id, 618 attr.type.id,
596 attr.type.nullable, 619 attr.type.nullable,
597 'GetterRaisesException' in attr.ext_attrs or 'RaisesException' in attr.e xt_attrs, 620 raises,
598 auto_scope_setup) 621 auto_scope_setup)
599 622
600 def _AddSetter(self, attr, html_name): 623 def _AddSetter(self, attr, html_name):
601 type_info = self._TypeInfo(attr.type.id) 624 type_info = self._TypeInfo(attr.type.id)
602 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id)) 625 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id))
603 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) 626 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs)
604 native_suffix = 'Setter' 627 native_suffix = 'Setter'
605 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) 628 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix)
606 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, 629 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2,
607 dart_declaration, native_suffix, is_custom, auto_scope_setup) 630 dart_declaration, native_suffix, is_custom, auto_scope_setup)
608 if is_custom: 631 if is_custom:
609 return 632 return
610 633
611 if 'Reflect' in attr.ext_attrs: 634 if 'Reflect' in attr.ext_attrs:
612 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() 635 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name()
613 else: 636 else:
637 if 'ImplementedAs' in attr.ext_attrs:
638 attr_name = attr.ext_attrs['ImplementedAs']
639 else:
640 attr_name = attr.id
614 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)', 641 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)',
615 lambda s: s.group(1).upper(), 642 lambda s: s.group(1).upper(),
616 attr.id) 643 attr_name)
617 webcore_function_name = 'set%s' % webcore_function_name 644 webcore_function_name = 'set%s' % webcore_function_name
618 645
619 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 646 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
647 raises = ('RaisesException' in attr.ext_attrs and
648 attr.ext_attrs['RaisesException'] != 'Getter')
620 self._GenerateNativeCallback( 649 self._GenerateNativeCallback(
621 cpp_callback_name, 650 cpp_callback_name,
622 True, 651 True,
623 function_expression, 652 function_expression,
624 attr, 653 attr,
625 [attr], 654 [attr],
626 'void', 655 'void',
627 False, 656 False,
628 'SetterRaisesException' in attr.ext_attrs, 657 raises,
629 auto_scope_setup, 658 auto_scope_setup,
630 generate_custom_element_scope_if_needed=True) 659 generate_custom_element_scope_if_needed=True)
631 660
632 def AddIndexer(self, element_type): 661 def AddIndexer(self, element_type):
633 """Adds all the methods required to complete implementation of List.""" 662 """Adds all the methods required to complete implementation of List."""
634 # We would like to simply inherit the implementation of everything except 663 # We would like to simply inherit the implementation of everything except
635 # length, [], and maybe []=. It is possible to extend from a base 664 # length, [], and maybe []=. It is possible to extend from a base
636 # array implementation class only when there is no other implementation 665 # array implementation class only when there is no other implementation
637 # inheritance. There might be no implementation inheritance other than 666 # inheritance. There might be no implementation inheritance other than
638 # DOMBaseWrapper for many classes, but there might be some where the 667 # DOMBaseWrapper for many classes, but there might be some where the
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 ' goto fail;\n' 1104 ' goto fail;\n'
1076 ' }\n') 1105 ' }\n')
1077 1106
1078 1107
1079 if needs_receiver: 1108 if needs_receiver:
1080 interface_name = self._interface_type_info.native_type() 1109 interface_name = self._interface_type_info.native_type()
1081 # Hack to determine if this came from the _cpp_callback_map. 1110 # Hack to determine if this came from the _cpp_callback_map.
1082 # In this case, the getter is mapped to a static method. 1111 # In this case, the getter is mapped to a static method.
1083 if (not function_expression.startswith('receiver->') and 1112 if (not function_expression.startswith('receiver->') and
1084 not function_expression.startswith(interface_name + '::')): 1113 not function_expression.startswith(interface_name + '::')):
1085 if interface_name == 'DOMWindow' or interface_name == 'Navigator' or int erface_name == 'WorkerGlobalScope': 1114 if interface_name in ['DOMWindow', 'Element', 'Navigator', 'WorkerGlobal Scope']:
1086 cpp_arguments.insert(0, 'receiver') 1115 cpp_arguments.insert(0, 'receiver')
1087 else: 1116 else:
1088 cpp_arguments.append('receiver') 1117 cpp_arguments.append('receiver')
1089 elif self._IsStatic(node.id): 1118 elif self._IsStatic(node.id):
1090 cpp_arguments.insert(0, 'receiver') 1119 cpp_arguments.insert(0, 'receiver')
1091 1120
1092 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments)) 1121 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments))
1093 if return_type == 'void': 1122 if return_type == 'void':
1094 invocation_emitter.Emit( 1123 invocation_emitter.Emit(
1095 ' $FUNCTION_CALL;\n', 1124 ' $FUNCTION_CALL;\n',
1096 FUNCTION_CALL=function_call) 1125 FUNCTION_CALL=function_call)
1097 else: 1126 else:
1098 return_type_info = self._TypeInfo(return_type) 1127 return_type_info = self._TypeInfo(return_type)
1099 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) 1128 self._cpp_impl_includes |= set(return_type_info.conversion_includes())
1100 1129
1101 if return_type_is_nullable: 1130 if return_type_is_nullable:
1102 invocation_emitter.Emit( 1131 invocation_emitter.Emit(
1103 ' bool isNull = false;\n' 1132 ' bool isNull = false;\n'
1104 ' $NATIVE_TYPE result = $FUNCTION_CALL;\n' 1133 ' $NATIVE_TYPE result = $FUNCTION_CALL;\n'
1105 ' if (isNull)\n' 1134 ' if (isNull)\n'
1106 ' return;\n', 1135 ' return;\n',
1107 NATIVE_TYPE=return_type_info.native_type(), 1136 NATIVE_TYPE=return_type_info.parameter_type(),
1108 FUNCTION_CALL=function_call) 1137 FUNCTION_CALL=function_call)
1109 value_expression = 'result' 1138 value_expression = 'result'
1110 else: 1139 else:
1111 value_expression = function_call 1140 value_expression = function_call
1112 1141
1113 # Generate to Dart conversion of C++ value. 1142 # Generate to Dart conversion of C++ value.
1114 if return_type_info.dart_type() == 'bool': 1143 if return_type_info.dart_type() == 'bool':
1115 set_return_value = 'Dart_SetBooleanReturnValue(args, %s)' % (value_expre ssion) 1144 set_return_value = 'Dart_SetBooleanReturnValue(args, %s)' % (value_expre ssion)
1116 elif return_type_info.dart_type() == 'int': 1145 elif return_type_info.dart_type() == 'int':
1117 if return_type_info.native_type() == 'unsigned': 1146 if return_type_info.native_type() == 'unsigned':
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 e.Emit("};\n"); 1402 e.Emit("};\n");
1374 e.Emit('\n'); 1403 e.Emit('\n');
1375 e.Emit('} // namespace WebCore\n'); 1404 e.Emit('} // namespace WebCore\n');
1376 1405
1377 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1406 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1378 return ( 1407 return (
1379 interface.id.endswith('Event') and 1408 interface.id.endswith('Event') and
1380 operation.id.startswith('init') and 1409 operation.id.startswith('init') and
1381 argument.ext_attrs.get('Default') == 'Undefined' and 1410 argument.ext_attrs.get('Default') == 'Undefined' and
1382 argument.type.id == 'DOMString') 1411 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « tools/dom/scripts/htmlrenamer.py ('k') | tools/dom/templates/html/dartium/cpp_callback_header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698