| Index: tools/dom/scripts/systemhtml.py
|
| diff --git a/tools/dom/scripts/systemhtml.py b/tools/dom/scripts/systemhtml.py
|
| index 8767e18e6a7948bebe1d19b0dd5ae4f717e470b5..1b0063a021da6d04ba96bf7ae71595381fb232da 100644
|
| --- a/tools/dom/scripts/systemhtml.py
|
| +++ b/tools/dom/scripts/systemhtml.py
|
| @@ -522,56 +522,33 @@ 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 GenerateCustomFactory(self, constructor_info):
|
| + # Custom factory will be taken from the template.
|
| + 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(antonm): add types to parameters.
|
| + 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:
|
|
|