Index: tools/dom/scripts/systemhtml.py |
diff --git a/tools/dom/scripts/systemhtml.py b/tools/dom/scripts/systemhtml.py |
index 4fc7e6ef772e08d4c1f5fd78f8fcd090a2266f70..dc1d79e435d84c693f375725718513460de22b6e 100644 |
--- a/tools/dom/scripts/systemhtml.py |
+++ b/tools/dom/scripts/systemhtml.py |
@@ -463,6 +463,19 @@ js_support_checks = dict({ |
else ElemSupportStr(_html_element_constructors[key])) for key in |
_js_support_checks_basic_element_with_constructors + |
_js_support_checks_additional_element).items()) |
+ |
+ |
+# JavaScript element class names of elements for which createElement does not |
+# always return exactly the right element, either because it might not be |
+# supported, or some browser does something weird. |
+_js_unreliable_element_factories = set( |
+ _js_support_checks_basic_element_with_constructors + |
+ _js_support_checks_additional_element + |
+ [ |
+ 'HTMLEmbedElement', |
+ 'HTMLObjectElement', |
+ ]) |
+ |
# ------------------------------------------------------------------------------ |
class HtmlDartInterfaceGenerator(object): |
@@ -804,6 +817,26 @@ class Dart2JSBackend(HtmlDartGenerator): |
# Custom factory will be taken from the template. |
return self._interface.doc_js_name in _js_custom_constructors |
+ def MakeFactoryCall(self, factory, method, arguments, constructor_info): |
+ if factory is 'document' and method is 'createElement' \ |
+ and not ',' in arguments \ |
+ and not self._HasUnreliableFactoryConstructor(): |
+ return emitter.Format( |
+ "JS('returns:$INTERFACE_NAME;creates:$INTERFACE_NAME;new:true'," |
+ " '#.$METHOD(#)', $FACTORY, $ARGUMENTS)", |
+ INTERFACE_NAME=self._interface_type_info.interface_name(), |
+ FACTORY=factory, |
+ METHOD=method, |
+ ARGUMENTS=arguments) |
+ return emitter.Format( |
+ '$FACTORY.$METHOD($ARGUMENTS)', |
+ FACTORY=factory, |
+ METHOD=method, |
+ ARGUMENTS=arguments) |
+ |
+ def _HasUnreliableFactoryConstructor(self): |
+ return self._interface.doc_js_name in _js_unreliable_element_factories |
+ |
def IsConstructorArgumentOptional(self, argument): |
return argument.optional |