| 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 system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 dart:html APIs from the IDL database.""" | 7 dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 from generator import AnalyzeOperation, ConstantOutputOrder, \ | 10 from generator import AnalyzeOperation, ConstantOutputOrder, \ |
| 11 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ | 11 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ |
| 12 IsPureInterface, TypeOrNothing, GetAnnotationsAndComments, \ | 12 IsPureInterface, TypeOrNothing, GetAnnotationsAndComments, \ |
| 13 FormatAnnotationsAndComments, ConvertToFuture, GetCallbackInfo | 13 FormatAnnotationsAndComments, ConvertToFuture, GetCallbackInfo |
| 14 from htmlrenamer import convert_to_future_members | 14 from htmlrenamer import convert_to_future_members |
| 15 | 15 |
| 16 # Types that are accessible cross-frame in a limited fashion. | 16 # Types that are accessible cross-frame in a limited fashion. |
| 17 # In these cases, the base type (e.g., WindowBase) provides restricted access | 17 # In these cases, the base type (e.g., WindowBase) provides restricted access |
| 18 # while the subtype (e.g., Window) provides full access to the | 18 # while the subtype (e.g., Window) provides full access to the |
| 19 # corresponding objects if there are from the same frame. | 19 # corresponding objects if there are from the same frame. |
| 20 _secure_base_types = { | 20 _secure_base_types = { |
| 21 'Window': 'WindowBase', | 21 'Window': 'WindowBase', |
| 22 'Location': 'LocationBase', | 22 'Location': 'LocationBase', |
| 23 'History': 'HistoryBase', | 23 'History': 'HistoryBase', |
| 24 } | 24 } |
| 25 | 25 |
| 26 _custom_factories = [ | |
| 27 'Notification', | |
| 28 'EventSource', | |
| 29 ] | |
| 30 | 26 |
| 31 class HtmlDartGenerator(object): | 27 class HtmlDartGenerator(object): |
| 32 def __init__(self, interface, options): | 28 def __init__(self, interface, options): |
| 33 self._database = options.database | 29 self._database = options.database |
| 34 self._interface = interface | 30 self._interface = interface |
| 35 self._type_registry = options.type_registry | 31 self._type_registry = options.type_registry |
| 36 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 32 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
| 37 self._renamer = options.renamer | 33 self._renamer = options.renamer |
| 38 self._library_name = self._renamer.GetLibraryName(self._interface) | 34 self._library_name = self._renamer.GetLibraryName(self._interface) |
| 39 | 35 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 NAME=name, | 478 NAME=name, |
| 483 FACTORY_PARAMS= \ | 479 FACTORY_PARAMS= \ |
| 484 constructor_info.ParametersAsArgumentList(argument_count)) | 480 constructor_info.ParametersAsArgumentList(argument_count)) |
| 485 self.EmitStaticFactoryOverload( | 481 self.EmitStaticFactoryOverload( |
| 486 constructor_info, name, | 482 constructor_info, name, |
| 487 constructor_info.idl_args[signature_index][:argument_count]) | 483 constructor_info.idl_args[signature_index][:argument_count]) |
| 488 | 484 |
| 489 def IsOptional(signature_index, argument): | 485 def IsOptional(signature_index, argument): |
| 490 return self.IsConstructorArgumentOptional(argument) | 486 return self.IsConstructorArgumentOptional(argument) |
| 491 | 487 |
| 492 custom_factory_ctr = self._interface.id in _custom_factories | |
| 493 constructor_full_name = constructor_info._ConstructorFullName( | |
| 494 self._DartType) | |
| 495 self._GenerateOverloadDispatcher( | 488 self._GenerateOverloadDispatcher( |
| 496 constructor_info.idl_args, | 489 constructor_info.idl_args, |
| 497 False, | 490 False, |
| 498 [info.name for info in constructor_info.param_infos], | 491 [info.name for info in constructor_info.param_infos], |
| 499 emitter.Format('$(ANNOTATIONS)$FACTORY_KEYWORD $CTOR($PARAMS)', | 492 emitter.Format('$(ANNOTATIONS)factory $CTOR($PARAMS)', |
| 500 FACTORY_KEYWORD=('factory' if not custom_factory_ctr else | 493 CTOR=constructor_info._ConstructorFullName(self._DartType), |
| 501 'static %s' % constructor_full_name), | |
| 502 CTOR=(('' if not custom_factory_ctr else '_factory') | |
| 503 + constructor_full_name), | |
| 504 ANNOTATIONS=annotations, | 494 ANNOTATIONS=annotations, |
| 505 PARAMS=constructor_info.ParametersDeclaration(self._DartType)), | 495 PARAMS=constructor_info.ParametersDeclaration(self._DartType)), |
| 506 GenerateCall, | 496 GenerateCall, |
| 507 IsOptional) | 497 IsOptional) |
| 508 | 498 |
| 509 def _AddFutureifiedOperation(self, info, html_name): | 499 def _AddFutureifiedOperation(self, info, html_name): |
| 510 """Given a API function that uses callbacks, convert it to using Futures. | 500 """Given a API function that uses callbacks, convert it to using Futures. |
| 511 | 501 |
| 512 This conversion assumes the success callback is always provided before the | 502 This conversion assumes the success callback is always provided before the |
| 513 error callback (and so far in the DOM API, this is the case).""" | 503 error callback (and so far in the DOM API, this is the case).""" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 walk(interface.parents) | 641 walk(interface.parents) |
| 652 else: | 642 else: |
| 653 walk(interface.parents[1:]) | 643 walk(interface.parents[1:]) |
| 654 return result | 644 return result |
| 655 | 645 |
| 656 def _DartType(self, type_name): | 646 def _DartType(self, type_name): |
| 657 return self._type_registry.DartType(type_name) | 647 return self._type_registry.DartType(type_name) |
| 658 | 648 |
| 659 def _IsPrivate(self, name): | 649 def _IsPrivate(self, name): |
| 660 return name.startswith('_') | 650 return name.startswith('_') |
| OLD | NEW |