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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: tools/dom/scripts/systemhtml.py
diff --git a/tools/dom/scripts/systemhtml.py b/tools/dom/scripts/systemhtml.py
index 22061d3ee03a39122063a436496906d4b0243969..b84b6224ddad3c1ced32ab2fe9be212459f0f909 100644
--- a/tools/dom/scripts/systemhtml.py
+++ b/tools/dom/scripts/systemhtml.py
@@ -514,56 +514,32 @@ class Dart2JSBackend(HtmlDartGenerator):
def GetSupportCheck(self):
return js_support_checks.get(self._interface.doc_js_name)
- def EmitStaticFactory(self, constructor_info):
- WITH_CUSTOM_STATIC_FACTORY = [
+ def HasCustomFactory(self):
+ return self._interface.doc_js_name in [
'AudioContext',
'Blob',
'MutationObserver',
'SpeechRecognition',
]
- if self._interface.doc_js_name in WITH_CUSTOM_STATIC_FACTORY:
- return
-
- has_optional = any(param_info.is_optional
- for param_info in constructor_info.param_infos)
-
- def FormatJS(index):
- arguments = constructor_info.ParametersAsArgumentList(index)
- if arguments:
- arguments = ', ' + arguments
- return "JS('%s', 'new %s(%s)'%s)" % (
- self._interface_type_info.interface_name(),
- constructor_info.name or self._interface.doc_js_name,
- ','.join(['#'] * index),
- arguments)
+ def IsConstructorArgumentOptional(self, argument):
+ return 'Optional' in argument.ext_attrs
- if not has_optional:
- self._members_emitter.Emit(
- " static $INTERFACE_NAME _create($PARAMETERS_DECLARATION) => $JS;\n",
- INTERFACE_NAME=self._interface_type_info.interface_name(),
- PARAMETERS_DECLARATION=constructor_info.ParametersDeclaration(
- self._DartType),
- JS=FormatJS(len(constructor_info.param_infos)))
- else:
- dispatcher_emitter = self._members_emitter.Emit(
- " static $INTERFACE_NAME _create($PARAMETERS_DECLARATION) {\n"
- "$!DISPATCHER"
- " return $JS;\n"
- " }\n",
- INTERFACE_NAME=self._interface_type_info.interface_name(),
- PARAMETERS_DECLARATION=constructor_info.ParametersDeclaration(
- self._DartType),
- JS=FormatJS(len(constructor_info.param_infos)))
-
- for index, param_info in enumerate(constructor_info.param_infos):
- if param_info.is_optional:
- dispatcher_emitter.Emit(
- " if (!?$OPT_PARAM_NAME) {\n"
- " return $JS;\n"
- " }\n",
- OPT_PARAM_NAME=constructor_info.param_infos[index].name,
- JS=FormatJS(index))
+ def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
+ index = len(arguments)
+ arguments = constructor_info.ParametersAsArgumentList(index)
+ if arguments:
+ arguments = ', ' + arguments
+ self._members_emitter.Emit(
+ " static $INTERFACE_NAME $NAME($PARAMETERS) => "
+ "JS('$INTERFACE_NAME', 'new $CTOR_NAME($PLACEHOLDERS)'$ARGUMENTS);\n",
+ INTERFACE_NAME=self._interface_type_info.interface_name(),
+ NAME=name,
+ # TODO: add types to parameters.
Emily Fortuna 2013/01/28 23:01:28 nit: add username to TODO
Anton Muhin 2013/01/29 12:09:28 Done.
+ PARAMETERS=constructor_info.ParametersAsArgumentList(index),
+ CTOR_NAME=constructor_info.name or self._interface.doc_js_name,
+ PLACEHOLDERS=','.join(['#'] * index),
+ ARGUMENTS=arguments)
def SecondaryContext(self, interface):
if interface is not self._current_secondary_parent:

Powered by Google App Engine
This is Rietveld 408576698