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

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

Issue 12052076: Support overloaded constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
« no previous file with comments | « tools/dom/scripts/idlrenderer.py ('k') | tools/dom/scripts/systemnative.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 import os 10 import os
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 515
516 def FinishInterface(self): 516 def FinishInterface(self):
517 pass 517 pass
518 518
519 def HasSupportCheck(self): 519 def HasSupportCheck(self):
520 return self._interface.doc_js_name in js_support_checks 520 return self._interface.doc_js_name in js_support_checks
521 521
522 def GetSupportCheck(self): 522 def GetSupportCheck(self):
523 return js_support_checks.get(self._interface.doc_js_name) 523 return js_support_checks.get(self._interface.doc_js_name)
524 524
525 def EmitStaticFactory(self, constructor_info): 525 def GenerateCustomFactory(self, constructor_info):
526 WITH_CUSTOM_STATIC_FACTORY = [ 526 # Custom factory will be taken from the template.
527 return self._interface.doc_js_name in [
527 'AudioContext', 528 'AudioContext',
528 'Blob', 529 'Blob',
529 'MutationObserver', 530 'MutationObserver',
530 'SpeechRecognition', 531 'SpeechRecognition',
531 ] 532 ]
532 533
533 if self._interface.doc_js_name in WITH_CUSTOM_STATIC_FACTORY: 534 def IsConstructorArgumentOptional(self, argument):
534 return 535 return 'Optional' in argument.ext_attrs
535 536
536 has_optional = any(param_info.is_optional 537 def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
537 for param_info in constructor_info.param_infos) 538 index = len(arguments)
538 539 arguments = constructor_info.ParametersAsArgumentList(index)
539 def FormatJS(index): 540 if arguments:
540 arguments = constructor_info.ParametersAsArgumentList(index) 541 arguments = ', ' + arguments
541 if arguments: 542 self._members_emitter.Emit(
542 arguments = ', ' + arguments 543 " static $INTERFACE_NAME $NAME($PARAMETERS) => "
543 return "JS('%s', 'new %s(%s)'%s)" % ( 544 "JS('$INTERFACE_NAME', 'new $CTOR_NAME($PLACEHOLDERS)'$ARGUMENTS);\n",
544 self._interface_type_info.interface_name(), 545 INTERFACE_NAME=self._interface_type_info.interface_name(),
545 constructor_info.name or self._interface.doc_js_name, 546 NAME=name,
546 ','.join(['#'] * index), 547 # TODO(antonm): add types to parameters.
547 arguments) 548 PARAMETERS=constructor_info.ParametersAsArgumentList(index),
548 549 CTOR_NAME=constructor_info.name or self._interface.doc_js_name,
549 if not has_optional: 550 PLACEHOLDERS=','.join(['#'] * index),
550 self._members_emitter.Emit( 551 ARGUMENTS=arguments)
551 " static $INTERFACE_NAME _create($PARAMETERS_DECLARATION) => $JS;\n",
552 INTERFACE_NAME=self._interface_type_info.interface_name(),
553 PARAMETERS_DECLARATION=constructor_info.ParametersDeclaration(
554 self._DartType),
555 JS=FormatJS(len(constructor_info.param_infos)))
556 else:
557 dispatcher_emitter = self._members_emitter.Emit(
558 " static $INTERFACE_NAME _create($PARAMETERS_DECLARATION) {\n"
559 "$!DISPATCHER"
560 " return $JS;\n"
561 " }\n",
562 INTERFACE_NAME=self._interface_type_info.interface_name(),
563 PARAMETERS_DECLARATION=constructor_info.ParametersDeclaration(
564 self._DartType),
565 JS=FormatJS(len(constructor_info.param_infos)))
566
567 for index, param_info in enumerate(constructor_info.param_infos):
568 if param_info.is_optional:
569 dispatcher_emitter.Emit(
570 " if (!?$OPT_PARAM_NAME) {\n"
571 " return $JS;\n"
572 " }\n",
573 OPT_PARAM_NAME=constructor_info.param_infos[index].name,
574 JS=FormatJS(index))
575 552
576 def SecondaryContext(self, interface): 553 def SecondaryContext(self, interface):
577 if interface is not self._current_secondary_parent: 554 if interface is not self._current_secondary_parent:
578 self._current_secondary_parent = interface 555 self._current_secondary_parent = interface
579 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) 556 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id)
580 557
581 def AddIndexer(self, element_type): 558 def AddIndexer(self, element_type):
582 """Adds all the methods required to complete implementation of List.""" 559 """Adds all the methods required to complete implementation of List."""
583 # We would like to simply inherit the implementation of everything except 560 # We would like to simply inherit the implementation of everything except
584 # length, [], and maybe []=. It is possible to extend from a base 561 # length, [], and maybe []=. It is possible to extend from a base
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 for library_name in libraries: 1019 for library_name in libraries:
1043 self._libraries[library_name] = DartLibrary( 1020 self._libraries[library_name] = DartLibrary(
1044 library_name, template_loader, library_type, output_dir) 1021 library_name, template_loader, library_type, output_dir)
1045 1022
1046 def AddFile(self, basename, library_name, path): 1023 def AddFile(self, basename, library_name, path):
1047 self._libraries[library_name].AddFile(path) 1024 self._libraries[library_name].AddFile(path)
1048 1025
1049 def Emit(self, emitter, auxiliary_dir): 1026 def Emit(self, emitter, auxiliary_dir):
1050 for lib in self._libraries.values(): 1027 for lib in self._libraries.values():
1051 lib.Emit(emitter, auxiliary_dir) 1028 lib.Emit(emitter, auxiliary_dir)
OLDNEW
« no previous file with comments | « tools/dom/scripts/idlrenderer.py ('k') | tools/dom/scripts/systemnative.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698