Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
scripts.systemhtml.Dart2JSBackend Class Reference
Inheritance diagram for scripts.systemhtml.Dart2JSBackend:
scripts.htmldartgenerator.HtmlDartGenerator

Public Member Functions

 __init__ (self, interface, options, logging_level=logging.WARNING, generate_static_extensions=False)
 
 ImplementsMergedMembers (self)
 
 GenerateCallback (self, info)
 
 AdditionalImplementedInterfaces (self)
 
 NativeSpec (self)
 
 ImplementationTemplate (self)
 
 StartInterface (self, members_emitter)
 
 FinishInterface (self)
 
 HasSupportCheck (self)
 
 GetSupportCheck (self)
 
 GenerateCustomFactory (self, constructor_info)
 
 MakeFactoryCall (self, factory, method, arguments, constructor_info)
 
 IsConstructorArgumentOptional (self, argument)
 
 EmitStaticFactoryOverload (self, constructor_info, name, arguments, emitter)
 
 SecondaryContext (self, interface)
 
 HasIndexedGetter (self)
 
 AddIndexer (self, element_type, nullable)
 
 EmitAttribute (self, attribute, html_name, read_only)
 
 AmendIndexer (self, element_type)
 
 RootClassName (self)
 
 OmitOperationOverrides (self)
 
 EmitOperation (self, info, html_name, dart_js_interop=False)
 
 CustomJSMembers (self)
 
- Public Member Functions inherited from scripts.htmldartgenerator.HtmlDartGenerator
 EmitSupportCheck (self)
 
 EmitEventGetter (self, events_class_name)
 
 AddMembers (self, interface, declare_only=False, dart_js_interop=False)
 
 AddSecondaryMembers (self, interface)
 
 AddConstant (self, constant)
 
 AddAttribute (self, attribute, declare_only=False)
 
 AddOperation (self, info, declare_only=False, dart_js_interop=False)
 
 Mixins (self)
 
 AddConstructors (self, constructors, factory_name, factory_constructor_name, constructor_emitter)
 
 EmitHelpers (self, base_class, members_emitter)
 
 DeclareAttribute (self, attribute, attr_name, read_only)
 
 DeclareOperation (self, operation, return_type_name, method_name)
 
 EmitListMixin (self, element_name, nullable)
 
 SecureOutputType (self, type_name, is_dart_type=False, can_narrow_type=False, nullable=False)
 
 SecureBaseName (self, type_name)
 
 is_DOM_type (self, type_name)
 

Protected Member Functions

 _HasUnreliableFactoryConstructor (self)
 
 _IsACompatibilityConflict (self, interface, attr)
 
 _AddAttributeUsingProperties (self, attribute, html_name, read_only, rename=None, metadata=None)
 
 _AddRenamingGetter (self, attr, html_name, rename, metadata)
 
 _AddRenamingSetter (self, attr, html_name, rename)
 
 _AddConvertingGetter (self, attr, html_name, conversion)
 
 _AddConvertingSetter (self, attr, html_name, conversion)
 
 _computeResultType (self, checkType)
 
 _zeroArgs (self, argsNames)
 
 _manyArgs (self, numberArgs, argsNames)
 
 _promiseToFutureCode (self, argsNames, conversionsMapToDictionary=None)
 
 _AddDirectNativeOperation (self, info, html_name)
 
 _AddOperationWithConversions (self, info, html_name)
 
 _AddInterfaceOperation (self, info, html_name)
 
 _OperationRequiresConversions (self, operation)
 
 _OperationRequiresOutputConversion (self, operation)
 
 _OperationRequiresInputConversions (self, operation)
 
 _OutputConversion (self, idl_type, member)
 
 _InputConversion (self, idl_type, member)
 
 _HasCustomImplementation (self, member_name)
 
 _SafeToIgnoreShadowingMember (self, member_name)
 
 _RenamingAnnotation (self, idl_name, member_name)
 
 _Metadata (self, idl_type, idl_member_name, dart_type, nullable, indent=' ')
 
 _FindShadowedAttribute (self, attr)
 
- Protected Member Functions inherited from scripts.htmldartgenerator.HtmlDartGenerator
 _RemoveShadowingOperationsWithSameSignature (self, operationsByName, interface)
 
 _AddRenamedOverloads (self, interface)
 
 _AddDesiredOverloadedOperations (self, potential_added_operations, interface, original_operations_by_name)
 
 _EnsureNoMultipleTypeSignatures (self, interface, operation, operations_by_name)
 
 _GetStringRepresentation (self, interface, operation)
 
 _OperationsByName (self, interface)
 
 _GenerateOverloadDispatcher (self, info, signatures, is_void, declaration, generate_call, is_optional, emitter, can_omit_type_check=lambda type, False pos)
 
 _GenerateDispatcherBody (self, info, operations, declaration, generate_call, is_optional, can_omit_type_check=lambda type, False pos)
 
 _AddConstructor (self, constructor_info, factory_name, factory_constructor_name, constructor_emitter)
 
 _AddFutureifiedOperation (self, info, html_name)
 
 _NarrowToImplementationType (self, type_name)
 
 _NarrowInputType (self, type_name)
 
 _DartType (self, type_name)
 
 _TypeInfo (self, type_name)
 
 _CallbackConvert (self, argType, info)
 
 _ConvertArgumentTypes (self, stmts_emitter, arguments, argument_count, info)
 
 _InputType (self, type_name, info)
 

Protected Attributes

 _generate_static_extensions
 
 _database
 
 _template_loader
 
 _type_registry
 
 _renamer
 
 _metadata
 
 _interface_type_info
 
 _interface_name
 
 _current_secondary_parent
 
 _library_name
 
 _gl_constants
 
 _members_emitter
 
 _interface
 
- Protected Attributes inherited from scripts.htmldartgenerator.HtmlDartGenerator
 _dart_use_blink
 
 _database
 
 _interface
 
 _type_registry
 
 _interface_type_info
 
 _renamer
 
 _metadata
 
 _library_name
 
 _mdn_reader
 
 _DartType
 
 _members_emitter
 
 _dart_js_interop
 

Detailed Description

Generates a dart2js class for the dart:html library from a DOM IDL
interface.

Definition at line 1273 of file systemhtml.py.

Constructor & Destructor Documentation

◆ __init__()

scripts.systemhtml.Dart2JSBackend.__init__ (   self,
  interface,
  options,
  logging_level = logging.WARNING,
  generate_static_extensions = False 
)

Reimplemented from scripts.htmldartgenerator.HtmlDartGenerator.

Definition at line 1278 of file systemhtml.py.

1282 generate_static_extensions=False):
1283 super(Dart2JSBackend, self).__init__(interface, options, False, _logger)
1284
1285 self._generate_static_extensions = generate_static_extensions
1286 self._database = options.database
1287 self._template_loader = options.templates
1288 self._type_registry = options.type_registry
1289 self._renamer = options.renamer
1290 self._metadata = options.metadata
1291 self._interface_type_info = self._type_registry.TypeInfo(
1292 self._interface.id)
1293 self._interface_name = self._interface_type_info.interface_name()
1294 self._current_secondary_parent = None
1295 self._library_name = self._renamer.GetLibraryName(self._interface)
1296 # Global constants for all WebGLRenderingContextBase, WebGL2RenderingContextBase, WebGLDrawBuffers
1297 self._gl_constants = []
1298 _logger.setLevel(logging_level)
1299

Member Function Documentation

◆ _AddAttributeUsingProperties()

scripts.systemhtml.Dart2JSBackend._AddAttributeUsingProperties (   self,
  attribute,
  html_name,
  read_only,
  rename = None,
  metadata = None 
)
protected

Definition at line 1694 of file systemhtml.py.

1695 rename=None, metadata=None):
1696 self._AddRenamingGetter(attribute, html_name, rename, metadata)
1697 if not read_only:
1698 # No metadata for setters.
1699 self._AddRenamingSetter(attribute, html_name, rename)
1700

◆ _AddConvertingGetter()

scripts.systemhtml.Dart2JSBackend._AddConvertingGetter (   self,
  attr,
  html_name,
  conversion 
)
protected

Definition at line 1780 of file systemhtml.py.

1780 def _AddConvertingGetter(self, attr, html_name, conversion):
1781 # dynamic should not be marked with ?
1782 nullable_out = conversion.nullable_output and \
1783 not conversion.output_type == 'dynamic'
1784 # Nullability is determined by attribute compatibility.
1785 is_compat = self._mdn_reader.is_compatible(attr)
1786 nullable_in = (not is_compat or attr.type.nullable) and \
1787 not conversion.input_type == 'dynamic'
1788 self._members_emitter.Emit(
1789 '\n $(METADATA)$RETURN_TYPE$NULLABLE_OUT get $HTML_NAME => '
1790 '$CONVERT(this._get_$(HTML_NAME)$NULLASSERT);'
1791 "\n @JSName('$NAME')"
1792 '\n $(JS_METADATA)$NATIVE_TYPE$NULLABLE_IN get _get_$HTML_NAME native;'
1793 '\n',
1794 METADATA=self._metadata.GetFormattedMetadata(
1795 self._library_name, self._interface, html_name, ' '),
1796 JS_METADATA=self._Metadata(attr.type.id, html_name,
1797 conversion.input_type,
1798 conversion.nullable_output),
1799 CONVERT=conversion.function_name,
1800 HTML_NAME=html_name,
1801 NAME=attr.id,
1802 RETURN_TYPE=conversion.output_type,
1803 NULLABLE_OUT='?' if nullable_out else '',
1804 NATIVE_TYPE=conversion.input_type,
1805 NULLABLE_IN='?' if nullable_in else '',
1806 NULLASSERT='!' if nullable_in and \
1807 not conversion.nullable_input else '')
1808
static bool is_compatible(const GrSurfaceCharacterization &gsc, const GrBackendTexture &backendTex)

◆ _AddConvertingSetter()

scripts.systemhtml.Dart2JSBackend._AddConvertingSetter (   self,
  attr,
  html_name,
  conversion 
)
protected

Definition at line 1809 of file systemhtml.py.

1809 def _AddConvertingSetter(self, attr, html_name, conversion):
1810 # If the attribute is incompatible, it must be marked nullable.
1811 is_compat = self._mdn_reader.is_compatible(attr)
1812 # If the attribute is nullable, the setter should be nullable.
1813 nullable_in = ((attr.type.nullable or 'TreatNullAs' in attr.ext_attrs) \
1814 and not conversion.input_type == 'dynamic') or not is_compat
1815 nullable_out = conversion.nullable_output and \
1816 not conversion.output_type == 'dynamic'
1817 self._members_emitter.Emit(
1818 # TODO(sra): Use metadata to provide native name.
1819 '\n set $HTML_NAME($INPUT_TYPE$NULLABLE_IN value) {'
1820 '\n this._set_$HTML_NAME = $CONVERT(value$NULLASSERT);'
1821 '\n }'
1822 '\n set _set_$HTML_NAME(/*$NATIVE_TYPE$NULLABLE_OUT*/ value) {'
1823 '\n JS("void", "#.$NAME = #", this, value);'
1824 '\n }'
1825 '\n',
1826 CONVERT=conversion.function_name,
1827 HTML_NAME=html_name,
1828 NAME=attr.id,
1829 INPUT_TYPE=conversion.input_type,
1830 NULLABLE_IN='?' if nullable_in else '',
1831 NATIVE_TYPE=conversion.output_type,
1832 NULLABLE_OUT='?' if nullable_out else '',
1833 NULLASSERT='!' if nullable_in and \
1834 not conversion.nullable_input else '')
1835

◆ _AddDirectNativeOperation()

scripts.systemhtml.Dart2JSBackend._AddDirectNativeOperation (   self,
  info,
  html_name 
)
protected

Definition at line 1956 of file systemhtml.py.

1956 def _AddDirectNativeOperation(self, info, html_name):
1957 force_optional = True if html_name.startswith('_') else False
1958 resultType = self._computeResultType(info.type_name)
1959
1960 if info.type_name == 'Promise' and not (force_optional):
1961 lookupOp = "%s.%s" % (self._interface.id, html_name)
1962 promiseFound = _GetPromiseOperationType(lookupOp)
1963 promiseType = 'Future'
1964 promiseCall = 'promiseToFuture'
1965 type_description = ''
1966 if promiseFound is not (None):
1967 paramType = promiseFound.get('type')
1968 if 'maplike' in promiseFound:
1969 if paramType == 'dictionary':
1970 promiseCall = 'promiseToFuture<dynamic>'
1971 promiseType = 'Future'
1972 elif paramType:
1973 promiseCall = 'promiseToFuture<%s>' % paramType
1974 promiseType = 'Future<%s>' % paramType
1975 elif paramType == 'dictionary':
1976 # It's a dictionary so return as a Map.
1977 promiseCall = 'promiseToFutureAsMap'
1978 output_conversion = self._OutputConversion("Dictionary",
1979 None)
1980 nullability = '?' if output_conversion.nullable_output \
1981 else ''
1982 promiseType = 'Future<Map<String, dynamic>' + \
1983 nullability + '>'
1984 elif paramType:
1985 promiseCall = 'promiseToFuture<%s>' % paramType
1986 promiseType = 'Future<%s>' % paramType
1987
1988 if 'creates' in promiseFound:
1989 createsType = promiseFound['creates']
1990 type_description = 'creates:%s;' % createsType
1991
1992 argsNames = info.ParametersAsArgumentList()
1993 dictionary_argument = info.dictionaryArgumentName()
1994 codeTemplate = self._promiseToFutureCode(argsNames,
1995 dictionary_argument)
1996 if info.type_nullable:
1997 promiseType += '?'
1998 self._members_emitter.Emit(
1999 codeTemplate,
2000 RENAME=self._RenamingAnnotation(info.declared_name, html_name),
2001 METADATA=self._Metadata(info.type_name, info.declared_name,
2002 self.SecureOutputType(info.type_name,
2003 nullable=info.type_nullable),
2004 info.type_nullable),
2005 MODIFIERS='static ' if info.IsStatic() else '',
2006 TYPE=promiseType,
2007 PROMISE_CALL=promiseCall,
2008 NAME=html_name,
2009 TYPE_DESC=type_description,
2010 JSNAME=info.declared_name,
2011 PARAMS=info.ParametersAsDeclaration(self._NarrowInputType,
2012 force_optional))
2013 else:
2014 self._members_emitter.Emit(
2015 '\n'
2016 ' $RENAME$METADATA$MODIFIERS$TYPE $NAME($PARAMS) => '\
2017 'js_util.callMethod(this, \'$JSNAME\', [$ARGS]);\n'
2018 if CanUseStaticExtensions(self._interface_name, self._generate_static_extensions) else
2019 '\n $RENAME$METADATA$MODIFIERS$TYPE $NAME($PARAMS) native;\n',
2020 RENAME=self._RenamingAnnotation(info.declared_name, html_name),
2021 METADATA=self._Metadata(
2022 info.type_name, info.declared_name,
2023 self.SecureOutputType(info.type_name,
2024 nullable=info.type_nullable),
2025 info.type_nullable),
2026 MODIFIERS='static ' if info.IsStatic() else '',
2027 TYPE=self.SecureOutputType(resultType,
2028 can_narrow_type=True,
2029 nullable=info.type_nullable),
2030 NAME=html_name,
2031 PARAMS=info.ParametersAsDeclaration(self._NarrowInputType,
2032 force_optional),
2033 ARGS=info.ParametersAsArgumentList(),
2034 JSNAME=info.declared_name if info.declared_name != html_name else html_name)
2035

◆ _AddInterfaceOperation()

scripts.systemhtml.Dart2JSBackend._AddInterfaceOperation (   self,
  info,
  html_name 
)
protected

Definition at line 2148 of file systemhtml.py.

2148 def _AddInterfaceOperation(self, info, html_name):
2149 self._members_emitter.Emit(
2150 '\n'
2151 ' $TYPE $NAME($PARAMS);\n',
2152 TYPE=self.SecureOutputType(info.type_name, can_narrow_type=True,
2153 nullable=info.type_nullable),
2154 NAME=html_name,
2155 PARAMS=info.ParametersAsDeclaration(self._NarrowInputType))
2156

◆ _AddOperationWithConversions()

scripts.systemhtml.Dart2JSBackend._AddOperationWithConversions (   self,
  info,
  html_name 
)
protected

Definition at line 2036 of file systemhtml.py.

2036 def _AddOperationWithConversions(self, info, html_name):
2037 # Assert all operations have same return type.
2038 assert len(set([op.type.id for op in info.operations])) == 1
2039
2040 resultType = self._computeResultType(info.type_name)
2041
2042 output_conversion = self._OutputConversion(resultType,
2043 info.declared_name)
2044 if output_conversion:
2045 return_type = output_conversion.output_type
2046 native_return_type = output_conversion.input_type
2047 else:
2048 return_type = resultType if resultType == 'Function' else self._NarrowInputType(
2049 resultType)
2050 native_return_type = return_type
2051
2052 parameter_names = [param_info.name for param_info in info.param_infos]
2053 parameter_types = [
2054 self._InputType(param_info.type_id, info)
2055 for param_info in info.param_infos
2056 ]
2057 operations = info.operations
2058
2059 def InputType(type_name):
2060 return self._InputType(type_name, info)
2061
2062 def GenerateCall(stmts_emitter, call_emitter, version, operation,
2063 argument_count):
2064 target = '_%s_%d' % (html_name[1:] if html_name.startswith('_') else
2065 html_name, version)
2066
2067 (target_parameters, arguments,
2068 calling_params) = self._ConvertArgumentTypes(
2069 stmts_emitter, operation.arguments, argument_count, info)
2070
2071 argument_list = ', '.join(arguments)
2072 # TODO(sra): If the native method has zero type checks, we can 'inline' is
2073 # and call it directly with a JS-expression.
2074 call = '%s(%s)' % (target, argument_list)
2075
2076 if output_conversion:
2077 call = '%s(%s)' % (output_conversion.function_name, call)
2078 if output_conversion.nullable_output and not info.type_nullable:
2079 # Return type of operation is not nullable while conversion
2080 # is, so we need to assert non-null.
2081 call += '!'
2082
2083 call_emitter.Emit(call)
2084
2085 if (native_return_type == 'Future'):
2086 hashArgs = ''
2087 if argument_count > 0:
2088 if argument_count < 20:
2089 hashArgs = '#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#' [:
2090 argument_count
2091 *
2092 2
2093 -
2094 1]
2095 else:
2096 print(
2097 "ERROR: Arguments exceede 20 - please fix Python code to handle more."
2098 )
2099 self._members_emitter.Emit(
2100 ' $RENAME$METADATA$MODIFIERS$TYPE$TARGET($PARAMS) =>\n'
2101 ' promiseToFuture(JS("", "#.$JSNAME($HASH_STR)"'\
2102 ', this$CALLING_PARAMS));\n',
2103 RENAME=self._RenamingAnnotation(info.declared_name, target),
2104 METADATA=self._Metadata(info.type_name, info.declared_name,
2105 None, info.type_nullable),
2106 MODIFIERS='static ' if info.IsStatic() else '',
2107 TYPE=TypeOrNothing(native_return_type,
2108 nullable=info.type_nullable),
2109 TARGET=target,
2110 PARAMS=', '.join(target_parameters),
2111 JSNAME=operation.id,
2112 HASH_STR=hashArgs,
2113 CALLING_PARAMS=calling_params)
2114 else:
2115 self._members_emitter.Emit(
2116 ' $RENAME$METADATA$MODIFIERS$TYPE$TARGET($PARAMS) native;\n',
2117 RENAME=self._RenamingAnnotation(info.declared_name, target),
2118 METADATA=self._Metadata(info.type_name, info.declared_name,
2119 None, info.type_nullable),
2120 MODIFIERS='static ' if info.IsStatic() else '',
2121 TYPE=TypeOrNothing(native_return_type,
2122 nullable=info.type_nullable),
2123 TARGET=target,
2124 PARAMS=', '.join(target_parameters))
2125
2126 # private methods don't need named arguments.
2127 full_name = '%s.%s' % (self._interface.id, info.declared_name)
2128 force_optional = False if hasNamedFormals(full_name) and not (
2129 html_name.startswith('_')) else True
2130
2131 nullsafe_return_type = return_type;
2132 if info.type_nullable:
2133 nullsafe_return_type += '?'
2134
2135 declaration = '%s%s%s %s(%s)' % (
2136 self._Metadata(info.type_name, info.declared_name, return_type,
2137 info.type_nullable),
2138 'static ' if info.IsStatic() else '', nullsafe_return_type,
2139 html_name, info.ParametersAsDeclaration(InputType, force_optional))
2140 self._GenerateDispatcherBody(
2141 info,
2142 operations,
2143 declaration,
2144 GenerateCall,
2145 IsOptional,
2146 can_omit_type_check=lambda type, pos: type == parameter_types[pos])
2147
void print(void *str)
Definition bridge.cpp:126

◆ _AddRenamingGetter()

scripts.systemhtml.Dart2JSBackend._AddRenamingGetter (   self,
  attr,
  html_name,
  rename,
  metadata 
)
protected

Definition at line 1701 of file systemhtml.py.

1701 def _AddRenamingGetter(self, attr, html_name, rename, metadata):
1702 conversion = self._OutputConversion(attr.type.id, attr.id)
1703 if conversion:
1704 return self._AddConvertingGetter(attr, html_name, conversion)
1705 # If the attribute is incompatible, it must be marked nullable.
1706 is_compat = self._mdn_reader.is_compatible(attr)
1707 return_type = self.SecureOutputType(attr.type.id,
1708 nullable=(not is_compat) or
1709 attr.type.nullable)
1710 native_type = self._NarrowToImplementationType(attr.type.id)
1711 non_null_return_type = self.SecureOutputType(attr.type.id,
1712 nullable=False)
1713 if self._IsACompatibilityConflict(self._interface.id, attr):
1714 if not rename:
1715 rename = '@JSName(\'%s\')' % html_name
1716 template = """\n
1717 // The following getter is incompatible with some browsers but
1718 // must be made non-nullable to match the overridden method.
1719 \n $RENAME
1720 \n $METADATA
1721 \n $STATIC $TYPE get _$HTML_NAME native;
1722 \n
1723 \n $STATIC $NONNULLTYPE get $HTML_NAME => _$HTML_NAME$NULLASSERT;"""
1724 else:
1725 if CanUseStaticExtensions(self._interface_name,
1726 self._generate_static_extensions):
1727 template = """\n $RENAME
1728 \n $METADATA
1729 \n $STATIC $TYPE get $HTML_NAME => js_util.getProperty(this, '$JSNAME');
1730 \n"""
1731 else:
1732 template = """\n $RENAME
1733 \n $METADATA
1734 \n $STATIC $TYPE get $HTML_NAME native;
1735 \n"""
1736 self._members_emitter.Emit(template,
1737 RENAME=rename if rename else '',
1738 METADATA=metadata if metadata else '',
1739 HTML_NAME=html_name,
1740 STATIC='static' if attr.is_static else '',
1741 TYPE=return_type,
1742 NULLASSERT='!',
1743 NONNULLTYPE=non_null_return_type,
1744 JSNAME=rename if rename else html_name)
1745

◆ _AddRenamingSetter()

scripts.systemhtml.Dart2JSBackend._AddRenamingSetter (   self,
  attr,
  html_name,
  rename 
)
protected

Definition at line 1746 of file systemhtml.py.

1746 def _AddRenamingSetter(self, attr, html_name, rename):
1747 conversion = self._InputConversion(attr.type.id, attr.id)
1748 if conversion:
1749 return self._AddConvertingSetter(attr, html_name, conversion)
1750 nullable_type = attr.type.nullable or 'TreatNullAs' in attr.ext_attrs
1751 # If this attr has an output conversion, it is possible that there is a
1752 # converting getter. We need to make sure the setter type matches the
1753 # getter type.
1754 conversion = self._OutputConversion(attr.type.id, attr.id)
1755 # If the attribute is incompatible, it must be marked nullable.
1756 is_compat = self._mdn_reader.is_compatible(attr)
1757 if (conversion and conversion.nullable_output) or not is_compat:
1758 nullable_type = True
1759 if self._IsACompatibilityConflict(self._interface.id, attr):
1760 # Force non-nullable if it's a manual conflict.
1761 nullable_type = False
1762 if CanUseStaticExtensions(self._interface_name,
1763 self._generate_static_extensions):
1764 template = """\n $RENAME
1765 \n $STATIC set $HTML_NAME($TYPE value)
1766 => js_util.setProperty(this, '$JSNAME', value);
1767 \n"""
1768 else:
1769 template = """\n $RENAME
1770 \n $STATIC set $HTML_NAME($TYPE value) native;
1771 \n"""
1772 self._members_emitter.Emit(template,
1773 RENAME=rename if rename else '',
1774 HTML_NAME=html_name,
1775 STATIC='static ' if attr.is_static else '',
1776 TYPE=self.SecureOutputType(
1777 attr.type.id, nullable=nullable_type),
1778 JSNAME=rename if rename else html_name)
1779

◆ _computeResultType()

scripts.systemhtml.Dart2JSBackend._computeResultType (   self,
  checkType 
)
protected

Definition at line 1871 of file systemhtml.py.

1871 def _computeResultType(self, checkType):
1872 # TODO(terry): Work around bug in dart2js compiler e.g.,
1873 # typedef void CustomElementConstructor();
1874 # CustomElementConstructor registerElement(String type, [Map options])
1875 # Needs to become:
1876 # Function registerElement(String type, [Map options])
1877 resultType = checkType
1878 if self._database.HasInterface(resultType):
1879 resultInterface = self._database.GetInterface(resultType)
1880 if 'Callback' in resultInterface.ext_attrs:
1881 resultType = 'Function'
1882 return resultType
1883

◆ _FindShadowedAttribute()

scripts.systemhtml.Dart2JSBackend._FindShadowedAttribute (   self,
  attr 
)
protected
Returns (attribute, superinterface) or (None, None).

Definition at line 2221 of file systemhtml.py.

2221 def _FindShadowedAttribute(self, attr):
2222 """Returns (attribute, superinterface) or (None, None)."""
2223
2224 def FindInParent(interface):
2225 """Returns matching attribute in parent, or None."""
2226 if interface.parents:
2227 parent = interface.parents[0]
2228 if IsDartCollectionType(parent.type.id):
2229 return (None, None)
2230 if IsPureInterface(parent.type.id, self._database):
2231 return (None, None)
2232 if self._database.HasInterface(parent.type.id):
2233 interfaces_to_search_in = []
2234 parent_interface_name = parent.type.id
2235 interfaces_to_search_in.append(parent_interface_name)
2236 parent_type_info = self._type_registry.TypeInfo(
2237 parent_interface_name)
2238 if parent_type_info.merged_into():
2239 # IDL parent was merged into another interface, which became a
2240 # parent interface in Dart.
2241 parent_interface_name = parent_type_info.merged_into()
2242 interfaces_to_search_in.append(parent_interface_name)
2243 elif parent_type_info.merged_interface():
2244 # IDL parent has another interface that was merged into it.
2245 interfaces_to_search_in.append(
2246 parent_type_info.merged_interface())
2247
2248 for interface_name in interfaces_to_search_in:
2249 interface = self._database.GetInterface(interface_name)
2250 attr2 = FindMatchingAttribute(interface, attr)
2251 if attr2:
2252 return (attr2, parent_interface_name)
2253
2254 return FindInParent(
2255 self._database.GetInterface(parent_interface_name))
2256 return (None, None)
2257
2258 return FindInParent(self._interface) if attr else (None, None)
2259
2260
2261# ------------------------------------------------------------------------------
2262
2263

◆ _HasCustomImplementation()

scripts.systemhtml.Dart2JSBackend._HasCustomImplementation (   self,
  member_name 
)
protected

Definition at line 2175 of file systemhtml.py.

2175 def _HasCustomImplementation(self, member_name):
2176 member_name = '%s.%s' % (self._interface.doc_js_name, member_name)
2177 return member_name in _js_custom_members
2178

◆ _HasUnreliableFactoryConstructor()

scripts.systemhtml.Dart2JSBackend._HasUnreliableFactoryConstructor (   self)
protected

Definition at line 1390 of file systemhtml.py.

1390 def _HasUnreliableFactoryConstructor(self):
1391 return self._interface.doc_js_name in _js_unreliable_element_factories
1392

◆ _InputConversion()

scripts.systemhtml.Dart2JSBackend._InputConversion (   self,
  idl_type,
  member 
)
protected

Definition at line 2172 of file systemhtml.py.

2172 def _InputConversion(self, idl_type, member):
2173 return FindConversion(idl_type, 'set', self._interface.id, member)
2174

◆ _IsACompatibilityConflict()

scripts.systemhtml.Dart2JSBackend._IsACompatibilityConflict (   self,
  interface,
  attr 
)
protected

Definition at line 1680 of file systemhtml.py.

1680 def _IsACompatibilityConflict(self, interface, attr):
1681 if interface in compat_conflicts and attr.id in compat_conflicts[
1682 interface]:
1683 is_compat = self._mdn_reader.is_compatible(attr)
1684 if is_compat or attr.type.nullable:
1685 # Only attributes that are not compatible and not nullable
1686 # belong in this list.
1687 raise ValueError(
1688 interface + '.' + attr.id +
1689 ' has no conflict between compatibility and nullability.')
1690 else:
1691 return True
1692 return False
1693

◆ _manyArgs()

scripts.systemhtml.Dart2JSBackend._manyArgs (   self,
  numberArgs,
  argsNames 
)
protected

Definition at line 1887 of file systemhtml.py.

1887 def _manyArgs(self, numberArgs, argsNames):
1888 argsPound = "#" if numberArgs == 1 else ("#, " * numberArgs)[:-2]
1889 template = ' JS("$TYPE_DESC", "#.$JSNAME(%s)", this, %s)'
1890 return template % (argsPound, argsNames)
1891

◆ _Metadata()

scripts.systemhtml.Dart2JSBackend._Metadata (   self,
  idl_type,
  idl_member_name,
  dart_type,
  nullable,
  indent = '  ' 
)
protected

Definition at line 2188 of file systemhtml.py.

2189 indent=' '):
2190 anns = self._metadata.GetDart2JSMetadata(
2191 idl_type, self._library_name, self._interface, idl_member_name)
2192
2193 if not self._metadata.AnyConversionAnnotations(
2194 idl_type, self._interface.id, idl_member_name):
2195 return_type = self.SecureOutputType(idl_type)
2196 native_type = self._NarrowToImplementationType(idl_type)
2197
2198 null_union = '' if not nullable else '|Null'
2199 if native_type != return_type:
2200 anns = anns + [
2201 "@Returns('%s%s')" % (native_type, null_union),
2202 "@Creates('%s')" % native_type,
2203 ]
2204 if dart_type == 'dynamic' or dart_type == 'Object?':
2205 # We emit non-nullable Object annotations but exclude nullable
2206 # Object annotations since that's the default.
2207
2208 def js_type_annotation(ann):
2209 return re.search('^@.*Returns', ann) or re.search(
2210 '^@.*Creates', ann)
2211
2212 if not list(filter(js_type_annotation, anns)):
2213 _logger.warn('Member with wildcard native type: %s.%s' %
2214 (self._interface.id, idl_member_name))
2215
2216 return self._metadata.FormatMetadata(anns, indent)
2217

◆ _OperationRequiresConversions()

scripts.systemhtml.Dart2JSBackend._OperationRequiresConversions (   self,
  operation 
)
protected

Definition at line 2157 of file systemhtml.py.

2157 def _OperationRequiresConversions(self, operation):
2158 return (self._OperationRequiresOutputConversion(operation) or
2159 self._OperationRequiresInputConversions(operation))
2160

◆ _OperationRequiresInputConversions()

scripts.systemhtml.Dart2JSBackend._OperationRequiresInputConversions (   self,
  operation 
)
protected

Definition at line 2164 of file systemhtml.py.

2164 def _OperationRequiresInputConversions(self, operation):
2165 return any(
2166 self._InputConversion(arg.type.id, operation.id)
2167 for arg in operation.arguments)
2168

◆ _OperationRequiresOutputConversion()

scripts.systemhtml.Dart2JSBackend._OperationRequiresOutputConversion (   self,
  operation 
)
protected

Definition at line 2161 of file systemhtml.py.

2161 def _OperationRequiresOutputConversion(self, operation):
2162 return self._OutputConversion(operation.type.id, operation.id)
2163

◆ _OutputConversion()

scripts.systemhtml.Dart2JSBackend._OutputConversion (   self,
  idl_type,
  member 
)
protected

Definition at line 2169 of file systemhtml.py.

2169 def _OutputConversion(self, idl_type, member):
2170 return FindConversion(idl_type, 'get', self._interface.id, member)
2171

◆ _promiseToFutureCode()

scripts.systemhtml.Dart2JSBackend._promiseToFutureCode (   self,
  argsNames,
  conversionsMapToDictionary = None 
)
protected

Definition at line 1895 of file systemhtml.py.

1895 def _promiseToFutureCode(self, argsNames, conversionsMapToDictionary=None):
1896 numberArgs = argsNames.count(',') + 1
1897 jsCall = self._zeroArgs(argsNames) if len(argsNames) == 0 else \
1898 self._manyArgs(numberArgs, argsNames)
1899
1900 futureTemplate = []
1901 if conversionsMapToDictionary is None:
1902 futureTemplate = [
1903 '\n'
1904 ' $RENAME$METADATA$MODIFIERS $TYPE $NAME($PARAMS) => $PROMISE_CALL(',
1905 jsCall, ');\n'
1906 ]
1907 else:
1908 mapArg = conversionsMapToDictionary[0]
1909 tempVariable = '%s_dict' % mapArg
1910 mapArgOptional = conversionsMapToDictionary[1]
1911
1912 if argsNames.endswith('%s' % mapArg):
1913 argsNames = '%s_dict' % argsNames
1914 jsCall = self._zeroArgs(argsNames) if len(argsNames) == 0 else \
1915 self._manyArgs(numberArgs, argsNames)
1916 if mapArgOptional:
1917 futureTemplate = [
1918 # We will need to convert the Map argument to a Dictionary, test if mapArg is there (optional) then convert.
1919 '\n'
1920 ' $RENAME$METADATA$MODIFIERS $TYPE $NAME($PARAMS) {\n',
1921 ' var ',
1922 tempVariable,
1923 ' = null;\n',
1924 ' if (',
1925 mapArg,
1926 ' != null) {\n',
1927 ' ',
1928 tempVariable,
1929 ' = convertDartToNative_Dictionary(',
1930 mapArg,
1931 ');\n',
1932 ' }\n',
1933 ' return $PROMISE_CALL(',
1934 jsCall,
1935 ');\n',
1936 ' }\n'
1937 ]
1938 else:
1939 futureTemplate = [
1940 # We will need to convert the Map argument to a Dictionary, the Map argument is not optional.
1941 '\n'
1942 ' $RENAME$METADATA$MODIFIERS $TYPE $NAME($PARAMS) {\n',
1943 ' var ',
1944 tempVariable,
1945 ' = convertDartToNative_Dictionary(',
1946 mapArg,
1947 ');\n',
1948 ' return $PROMISE_CALL(',
1949 jsCall,
1950 ');\n',
1951 ' }\n'
1952 ]
1953
1954 return "".join(futureTemplate)
1955

◆ _RenamingAnnotation()

scripts.systemhtml.Dart2JSBackend._RenamingAnnotation (   self,
  idl_name,
  member_name 
)
protected

Definition at line 2183 of file systemhtml.py.

2183 def _RenamingAnnotation(self, idl_name, member_name):
2184 if member_name != idl_name:
2185 return "@JSName('%s')\n " % idl_name
2186 return ''
2187

◆ _SafeToIgnoreShadowingMember()

scripts.systemhtml.Dart2JSBackend._SafeToIgnoreShadowingMember (   self,
  member_name 
)
protected

Definition at line 2179 of file systemhtml.py.

2179 def _SafeToIgnoreShadowingMember(self, member_name):
2180 member_name = '%s.%s' % (self._interface.doc_js_name, member_name)
2181 return member_name in _safe_to_ignore_shadowing_members
2182

◆ _zeroArgs()

scripts.systemhtml.Dart2JSBackend._zeroArgs (   self,
  argsNames 
)
protected

Definition at line 1884 of file systemhtml.py.

1884 def _zeroArgs(self, argsNames):
1885 return 'JS("$TYPE_DESC", "#.$JSNAME()", this)'
1886

◆ AddIndexer()

scripts.systemhtml.Dart2JSBackend.AddIndexer (   self,
  element_type,
  nullable 
)
Adds all the methods required to complete implementation of List.

Definition at line 1440 of file systemhtml.py.

1440 def AddIndexer(self, element_type, nullable):
1441 """Adds all the methods required to complete implementation of List."""
1442 # We would like to simply inherit the implementation of everything except
1443 # length, [], and maybe []=. It is possible to extend from a base
1444 # array implementation class only when there is no other implementation
1445 # inheritance. There might be no implementation inheritance other than
1446 # DOMBaseWrapper for many classes, but there might be some where the
1447 # array-ness is introduced by a non-root interface:
1448 #
1449 # interface Y extends X, List<T> ...
1450 #
1451 # In the non-root case we have to choose between:
1452 #
1453 # class YImpl extends XImpl { add List<T> methods; }
1454 #
1455 # and
1456 #
1457 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
1458 #
1459
1460 has_indexed_getter = self.HasIndexedGetter()
1461
1462 indexed_getter = False
1463 indexed_getter_nullable = nullable
1464 if has_indexed_getter:
1465 indexed_getter = ('JS("%s%s", "#[#]", this, index)' %
1466 (self.SecureOutputType(element_type),
1467 "|Null" if nullable else ""))
1468 else:
1469 for op in self._interface.operations:
1470 if op.id == 'getItem':
1471 indexed_getter = 'this.getItem(index)'
1472 indexed_getter_nullable = OperationTypeIsNullable(op)
1473 break
1474 if not indexed_getter:
1475 for op in self._interface.operations:
1476 if op.id == 'item':
1477 indexed_getter = 'this.item(index)'
1478 indexed_getter_nullable = OperationTypeIsNullable(op)
1479 break
1480
1481 if indexed_getter:
1482 self._members_emitter.Emit(
1483 '\n'
1484 ' $TYPE operator[](int index) {\n'
1485 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n'
1486 ' index, index, length))\n'
1487 ' throw new IndexError.withLength(index, length, indexable: this);\n'
1488 ' return $INDEXED_GETTER$NULLASSERT;\n'
1489 ' }',
1490 INDEXED_GETTER=indexed_getter,
1491 TYPE=self.SecureOutputType(element_type,
1492 is_dart_type=False,
1493 can_narrow_type=True,
1494 nullable=nullable),
1495 # If the type of the operation is not nullable but the getter
1496 # is, we must assert non-null.
1497 NULLASSERT='!' if not nullable and indexed_getter_nullable \
1498 else '')
1499
1500 if 'CustomIndexedSetter' in self._interface.ext_attrs:
1501 self._members_emitter.Emit(
1502 '\n'
1503 ' void operator[]=(int index, $TYPE$NULLABLE value) {'
1504 ' JS("void", "#[#] = #", this, index, value); }',
1505 TYPE=self._NarrowInputType(element_type),
1506 NULLABLE='?' if nullable else '')
1507 else:
1508 theType = self._NarrowInputType(element_type)
1509 if theType == 'DomRectList':
1510 theType = ''
1511
1512 self._members_emitter.Emit(
1513 '\n'
1514 ' void operator[]=(int index, $TYPE$NULLABLE value) {\n'
1515 ' throw new UnsupportedError("Cannot assign element of immutable List.");\n'
1516 ' }\n',
1517 TYPE=theType,
1518 NULLABLE='?' if nullable else '')
1519
1520 self.EmitListMixin(self._DartType(element_type), nullable)
1521

◆ AdditionalImplementedInterfaces()

scripts.systemhtml.Dart2JSBackend.AdditionalImplementedInterfaces (   self)

Reimplemented from scripts.htmldartgenerator.HtmlDartGenerator.

Definition at line 1306 of file systemhtml.py.

1306 def AdditionalImplementedInterfaces(self):
1307 implements = super(Dart2JSBackend,
1308 self).AdditionalImplementedInterfaces()
1309 if self._interface_type_info.list_item_type() and self.HasIndexedGetter(
1310 ):
1311 item_type = self._type_registry.TypeInfo(
1312 self._interface_type_info.list_item_type()).dart_type()
1313 if self._interface_type_info.list_item_type_nullable():
1314 item_type += '?'
1315 implements.append('JavaScriptIndexingBehavior<%s>' % item_type)
1316 return implements
1317

◆ AmendIndexer()

scripts.systemhtml.Dart2JSBackend.AmendIndexer (   self,
  element_type 
)

Definition at line 1836 of file systemhtml.py.

1836 def AmendIndexer(self, element_type):
1837 pass
1838

◆ CustomJSMembers()

scripts.systemhtml.Dart2JSBackend.CustomJSMembers (   self)

Definition at line 2218 of file systemhtml.py.

2218 def CustomJSMembers(self):
2219 return _js_custom_members
2220

◆ EmitAttribute()

scripts.systemhtml.Dart2JSBackend.EmitAttribute (   self,
  attribute,
  html_name,
  read_only 
)

Definition at line 1522 of file systemhtml.py.

1522 def EmitAttribute(self, attribute, html_name, read_only):
1523 if self._HasCustomImplementation(attribute.id):
1524 return
1525
1526 if IsPureInterface(self._interface.id, self._database):
1527 self._AddAttributeUsingProperties(attribute, html_name, read_only)
1528 return
1529
1530 output_type = self.SecureOutputType(attribute.type.id,
1531 can_narrow_type=read_only,
1532 nullable=attribute.type.nullable)
1533
1534 rename = self._RenamingAnnotation(attribute.id, html_name)
1535 metadata = self._Metadata(attribute.type.id, attribute.id, output_type,
1536 attribute.type.nullable)
1537
1538 is_compat = self._mdn_reader.is_compatible(attribute)
1539
1540 # If the attribute is shadowing, we can't generate a shadowing
1541 # getter or setter (Issue 1633).
1542 # TODO(sra): _FindShadowedAttribute does not take into account the html
1543 # renaming. We should be looking for another attribute that has the
1544 # same html_name. Two attributes with the same IDL name might not match
1545 # if one is renamed.
1546 # TODO(srujzs): Determine if logic behind shadowing is still true here
1547 # and below with the transition to natives.
1548 (super_attribute,
1549 super_attribute_interface) = self._FindShadowedAttribute(attribute)
1550
1551 if super_attribute:
1552 if is_compat is None:
1553 # If there is no compatibility info on this attribute, we use
1554 # the parent attribute's compatibility info.
1555 is_compat = self._mdn_reader.is_compatible(super_attribute)
1556 self._mdn_reader.set_compatible(attribute, is_compat)
1557 if read_only or self._SafeToIgnoreShadowingMember(html_name):
1558 if attribute.type.id == super_attribute.type.id:
1559 # Compatible attribute, use the superclass property. This
1560 # works because JavaScript will do its own dynamic dispatch.
1561
1562 # Nullability is determined by attribute compatibility.
1563 nullable = not is_compat or attribute.type.nullable
1564 self._members_emitter.Emit(
1565 '\n'
1566 ' // Use implementation from $SUPER.\n'
1567 ' // $GET_TYPE get $NAME native;\n'
1568 ' // void set $NAME($SET_TYPE value) native;\n',
1569 SUPER=super_attribute_interface,
1570 NAME=html_name,
1571 GET_TYPE=self.SecureOutputType(attribute.type.id,
1572 can_narrow_type=read_only,
1573 nullable=nullable),
1574 SET_TYPE=self.SecureOutputType(attribute.type.id,
1575 can_narrow_type=read_only,
1576 nullable=nullable or \
1577 'TreatNullAs' in attribute.ext_attrs))
1578 return
1579 self._members_emitter.Emit('\n // Shadowing definition.')
1580 self._AddAttributeUsingProperties(attribute, html_name, read_only,
1581 rename, metadata)
1582 return
1583
1584 # If the attribute is shadowed incompatibly in a subclass then we also
1585 # can't just generate it as a getter/setter. In particular, this happens
1586 # with DomMatrixReadOnly and its subclass DomMatrix. Force the
1587 # superclass to generate getters. Hardcoding the known problem classes
1588 # for now.
1589 # TODO(alanknight): Fix this more generally.
1590 if (self._interface.id == 'DOMMatrixReadOnly' or
1591 self._interface.id == 'DOMPointReadOnly' or
1592 self._interface.id == 'DOMRectReadOnly'):
1593 self._AddAttributeUsingProperties(attribute, html_name, read_only,
1594 rename, metadata)
1595 return
1596
1597 # If the type has a conversion we need a getter or setter to contain the
1598 # conversion code.
1599 if (self._OutputConversion(attribute.type.id, attribute.id) or
1600 self._InputConversion(attribute.type.id, attribute.id)):
1601 self._AddAttributeUsingProperties(attribute, html_name, read_only,
1602 rename, metadata)
1603 return
1604
1605 input_type = self._NarrowInputType(attribute.type.id)
1606 if attribute.type.nullable or not is_compat:
1607 input_type += '?'
1608 if not read_only:
1609 if attribute.type.id == 'Promise':
1610 _logger.warn('R/W member is a Promise: %s.%s' %
1611 (self._interface.id, html_name))
1612 self._AddAttributeUsingProperties(attribute, html_name, read_only,
1613 rename, metadata)
1614 else:
1615 if attribute.type.id == 'Promise':
1616 lookupOp = "%s.%s" % (self._interface.id, html_name)
1617 promiseFound = _GetPromiseAttributeType(lookupOp)
1618 promiseType = 'Future'
1619 promiseCall = 'promiseToFuture'
1620 type_description = ''
1621 if promiseFound is not (None):
1622 paramType = promiseFound.get('type')
1623 if 'maplike' in promiseFound:
1624 promiseCall = 'promiseToFuture<dynamic>'
1625 promiseType = 'Future'
1626 elif paramType == 'dictionary':
1627 # It's a dictionary so return as a Map.
1628 promiseCall = 'promiseToFutureAsMap'
1629 output_conversion = self._OutputConversion("Dictionary",
1630 None)
1631 nullability = '?' if output_conversion.nullable_output \
1632 else ''
1633 promiseType = 'Future<Map<String, dynamic>' + \
1634 nullability + '>'
1635 elif paramType:
1636 promiseCall = 'promiseToFuture<%s>' % paramType
1637 promiseType = 'Future<%s>' % paramType
1638
1639 if 'creates' in promiseFound:
1640 createsType = promiseFound['creates']
1641 type_description = 'creates:%s;' % createsType
1642
1643 if attribute.type.nullable:
1644 promiseType += '?'
1645
1646 template = '\n $RENAME$(ANNOTATIONS)$TYPE get $NAME => '\
1647 '$PROMISE_CALL(JS("$TYPE_DESC", "#.$NAME", this));\n'
1648
1649 self._members_emitter.Emit(
1650 template,
1651 RENAME=rename,
1652 ANNOTATIONS=metadata,
1653 TYPE=promiseType,
1654 PROMISE_CALL=promiseCall,
1655 TYPE_DESC=type_description,
1656 NAME=html_name,)
1657 else:
1658 # Need to use a getter for list.length properties so we can
1659 # add a setter which throws an exception, satisfying List
1660 # API.
1661 if self._interface_type_info.list_item_type() and \
1662 html_name == 'length':
1663 template = (
1664 '\n $RENAME$(ANNOTATIONS)$TYPE get $NAME => ' +
1665 'JS("$TYPE", "#.$NAME", this);\n')
1666 self._members_emitter.Emit(
1667 template,
1668 RENAME=rename,
1669 ANNOTATIONS=metadata,
1670 NAME=html_name,
1671 TYPE=input_type
1672 if output_type == 'double' else output_type)
1673 else:
1674 # Transform to native getters/setters.
1675 # TODO(srujzs): Should the logic for types and doubles from
1676 # above and before stay the same here?
1677 self._AddAttributeUsingProperties(attribute, html_name,
1678 read_only, rename, metadata)
1679

◆ EmitOperation()

scripts.systemhtml.Dart2JSBackend.EmitOperation (   self,
  info,
  html_name,
  dart_js_interop = False 
)
Arguments:
info: An OperationInfo object.

Definition at line 1845 of file systemhtml.py.

1845 def EmitOperation(self, info, html_name, dart_js_interop=False):
1846 """
1847 Arguments:
1848 info: An OperationInfo object.
1849 """
1850 if self._HasCustomImplementation(info.name):
1851 return
1852
1853 if IsPureInterface(self._interface.id, self._database):
1854 self._AddInterfaceOperation(info, html_name)
1855 elif info.callback_args:
1856 self._AddFutureifiedOperation(info, html_name)
1857 else:
1858 if any(
1859 self._OperationRequiresConversions(op)
1860 for op in info.overloads):
1861 lookupOp = "%s.%s" % (self._interface.id, html_name)
1862 if (_GetPromiseOperationType(lookupOp) or info.type_name == 'Promise') and \
1863 not _IsPromiseOperationGenerateCall(lookupOp):
1864 self._AddDirectNativeOperation(info, html_name)
1865 else:
1866 # Any conversions needed?
1867 self._AddOperationWithConversions(info, html_name)
1868 else:
1869 self._AddDirectNativeOperation(info, html_name)
1870

◆ EmitStaticFactoryOverload()

scripts.systemhtml.Dart2JSBackend.EmitStaticFactoryOverload (   self,
  constructor_info,
  name,
  arguments,
  emitter 
)

Definition at line 1396 of file systemhtml.py.

1397 emitter):
1398 if self._interface_type_info.has_generated_interface():
1399 # Use dart_type name, we're generating.
1400 interface_name = self._interface_type_info.interface_name()
1401 else:
1402 # Use the implementation name the interface is suppressed.
1403 interface_name = self._interface_type_info.implementation_name()
1404
1405 index = len(arguments)
1406 arguments = constructor_info.ParametersAsArgumentList(index)
1407 if arguments:
1408 arguments = ', ' + arguments
1409 (emitter if (emitter != None) else self._members_emitter).Emit(
1410 " static $INTERFACE_NAME $NAME($PARAMETERS) => "
1411 "JS('$INTERFACE_NAME', 'new $CTOR_NAME($PLACEHOLDERS)'$ARGUMENTS);\n",
1412 INTERFACE_NAME=interface_name,
1413 NAME=name,
1414 # TODO(antonm): add types to parameters.
1415 PARAMETERS=constructor_info.ParametersAsArgumentList(index),
1416 CTOR_NAME=constructor_info.name or self._interface.doc_js_name,
1417 PLACEHOLDERS=','.join(['#'] * index),
1418 ARGUMENTS=arguments)
1419

◆ FinishInterface()

scripts.systemhtml.Dart2JSBackend.FinishInterface (   self)

Definition at line 1344 of file systemhtml.py.

1344 def FinishInterface(self):
1345 pass
1346

◆ GenerateCallback()

scripts.systemhtml.Dart2JSBackend.GenerateCallback (   self,
  info 
)

Definition at line 1303 of file systemhtml.py.

1303 def GenerateCallback(self, info):
1304 pass
1305

◆ GenerateCustomFactory()

scripts.systemhtml.Dart2JSBackend.GenerateCustomFactory (   self,
  constructor_info 
)

Definition at line 1366 of file systemhtml.py.

1366 def GenerateCustomFactory(self, constructor_info):
1367 # Custom factory will be taken from the template.
1368 return self._interface.doc_js_name in _js_custom_constructors
1369

◆ GetSupportCheck()

scripts.systemhtml.Dart2JSBackend.GetSupportCheck (   self)
Return a tuple of the support check function signature and the support
test itself. If no parameters are supplied, we assume the default.

Definition at line 1350 of file systemhtml.py.

1350 def GetSupportCheck(self):
1351 """Return a tuple of the support check function signature and the support
1352 test itself. If no parameters are supplied, we assume the default."""
1353 if self._interface.doc_js_name in _js_support_checks_additional_element:
1354 if self._interface.doc_js_name in _svg_element_constructors:
1355 lib_prefix = 'Svg'
1356 constructors = _svg_element_constructors
1357 else:
1358 lib_prefix = ''
1359 constructors = _html_element_constructors
1360 return (js_support_checks.get(self._interface.doc_js_name) +
1361 " && (new %sElement.tag('%s') is %s)" %
1362 (lib_prefix, constructors[self._interface.doc_js_name],
1363 self._renamer.RenameInterface(self._interface)))
1364 return js_support_checks.get(self._interface.doc_js_name)
1365

◆ HasIndexedGetter()

scripts.systemhtml.Dart2JSBackend.HasIndexedGetter (   self)

Definition at line 1426 of file systemhtml.py.

1426 def HasIndexedGetter(self):
1427 ext_attrs = self._interface.ext_attrs
1428 has_indexed_getter = 'CustomIndexedGetter' in ext_attrs
1429 for operation in self._interface.operations:
1430 if operation.id == 'item' and 'getter' in operation.specials \
1431 and not self._OperationRequiresConversions(operation):
1432 has_indexed_getter = True
1433 break
1434 if operation.id == '__getter__' and 'getter' in operation.specials \
1435 and not self._OperationRequiresConversions(operation):
1436 has_indexed_getter = True
1437 break
1438 return has_indexed_getter
1439

◆ HasSupportCheck()

scripts.systemhtml.Dart2JSBackend.HasSupportCheck (   self)

Definition at line 1347 of file systemhtml.py.

1347 def HasSupportCheck(self):
1348 return self._interface.doc_js_name in js_support_checks
1349

◆ ImplementationTemplate()

scripts.systemhtml.Dart2JSBackend.ImplementationTemplate (   self)

Definition at line 1322 of file systemhtml.py.

1322 def ImplementationTemplate(self):
1323 template_file = ('impl_%s.darttemplate' % self._interface.doc_js_name)
1324 template_file_content = self._template_loader.TryLoad(template_file)
1325 if not (template_file_content):
1326 if self._interface.isMaplike and self._interface.isMaplike_ro:
1327 # TODO(terry): There are no mutable maplikes yet.
1328 template_file_content = self._template_loader.Load(
1329 'dart2js_maplike_impl.darttemplate')
1330
1331 else:
1332 if CanUseStaticExtensions(self._interface_name,
1333 self._generate_static_extensions):
1334 template_file_content = self._template_loader.Load(
1335 'dart2js_static_extension_impl.darttemplate')
1336 else:
1337 template_file_content = self._template_loader.Load(
1338 'dart2js_impl.darttemplate')
1339 return template_file_content
1340

◆ ImplementsMergedMembers()

scripts.systemhtml.Dart2JSBackend.ImplementsMergedMembers (   self)

Definition at line 1300 of file systemhtml.py.

1300 def ImplementsMergedMembers(self):
1301 return True
1302

◆ IsConstructorArgumentOptional()

scripts.systemhtml.Dart2JSBackend.IsConstructorArgumentOptional (   self,
  argument 
)

Definition at line 1393 of file systemhtml.py.

1393 def IsConstructorArgumentOptional(self, argument):
1394 return argument.optional
1395

◆ MakeFactoryCall()

scripts.systemhtml.Dart2JSBackend.MakeFactoryCall (   self,
  factory,
  method,
  arguments,
  constructor_info 
)

Definition at line 1370 of file systemhtml.py.

1370 def MakeFactoryCall(self, factory, method, arguments, constructor_info):
1371 if factory is 'document' and method is 'createElement' \
1372 and not ',' in arguments \
1373 and not self._HasUnreliableFactoryConstructor():
1374 return emitter.Format(
1375 "JS$CAST("
1376 "'returns:$INTERFACE_NAME;creates:$INTERFACE_NAME;new:true',"
1377 " '#.$METHOD(#)', $FACTORY, $ARGUMENTS)",
1378 CAST='<' + self._interface_type_info.interface_name() + '>',
1379 INTERFACE_NAME=self._interface_type_info.interface_name(),
1380 FACTORY=factory,
1381 METHOD=method,
1382 ARGUMENTS=arguments)
1383 return emitter.Format('$FACTORY.$METHOD($ARGUMENTS)$CAST',
1384 FACTORY=factory,
1385 METHOD=method,
1386 ARGUMENTS=arguments,
1387 CAST=' as ' +
1388 self._interface_type_info.interface_name())
1389

◆ NativeSpec()

scripts.systemhtml.Dart2JSBackend.NativeSpec (   self)

Definition at line 1318 of file systemhtml.py.

1318 def NativeSpec(self):
1319 native_spec = MakeNativeSpec(self._interface.javascript_binding_name)
1320 return '@Native("%s")\n' % native_spec
1321

◆ OmitOperationOverrides()

scripts.systemhtml.Dart2JSBackend.OmitOperationOverrides (   self)

Reimplemented from scripts.htmldartgenerator.HtmlDartGenerator.

Definition at line 1842 of file systemhtml.py.

1842 def OmitOperationOverrides(self):
1843 return True
1844

◆ RootClassName()

scripts.systemhtml.Dart2JSBackend.RootClassName (   self)

Definition at line 1839 of file systemhtml.py.

1839 def RootClassName(self):
1840 return 'JavaScriptObject'
1841

◆ SecondaryContext()

scripts.systemhtml.Dart2JSBackend.SecondaryContext (   self,
  interface 
)

Definition at line 1420 of file systemhtml.py.

1420 def SecondaryContext(self, interface):
1421 if interface is not self._current_secondary_parent:
1422 self._current_secondary_parent = interface
1423 self._members_emitter.Emit(
1424 '\n // From $WHERE\n', WHERE=interface.id)
1425

◆ StartInterface()

scripts.systemhtml.Dart2JSBackend.StartInterface (   self,
  members_emitter 
)

Definition at line 1341 of file systemhtml.py.

1341 def StartInterface(self, members_emitter):
1342 self._members_emitter = members_emitter
1343

Member Data Documentation

◆ _current_secondary_parent

scripts.systemhtml.Dart2JSBackend._current_secondary_parent
protected

Definition at line 1294 of file systemhtml.py.

◆ _database

scripts.systemhtml.Dart2JSBackend._database
protected

Definition at line 1286 of file systemhtml.py.

◆ _generate_static_extensions

scripts.systemhtml.Dart2JSBackend._generate_static_extensions
protected

Definition at line 1285 of file systemhtml.py.

◆ _gl_constants

scripts.systemhtml.Dart2JSBackend._gl_constants
protected

Definition at line 1297 of file systemhtml.py.

◆ _interface

scripts.systemhtml.Dart2JSBackend._interface
protected

Definition at line 1363 of file systemhtml.py.

◆ _interface_name

scripts.systemhtml.Dart2JSBackend._interface_name
protected

Definition at line 1293 of file systemhtml.py.

◆ _interface_type_info

scripts.systemhtml.Dart2JSBackend._interface_type_info
protected

Definition at line 1291 of file systemhtml.py.

◆ _library_name

scripts.systemhtml.Dart2JSBackend._library_name
protected

Definition at line 1295 of file systemhtml.py.

◆ _members_emitter

scripts.systemhtml.Dart2JSBackend._members_emitter
protected

Definition at line 1342 of file systemhtml.py.

◆ _metadata

scripts.systemhtml.Dart2JSBackend._metadata
protected

Definition at line 1290 of file systemhtml.py.

◆ _renamer

scripts.systemhtml.Dart2JSBackend._renamer
protected

Definition at line 1289 of file systemhtml.py.

◆ _template_loader

scripts.systemhtml.Dart2JSBackend._template_loader
protected

Definition at line 1287 of file systemhtml.py.

◆ _type_registry

scripts.systemhtml.Dart2JSBackend._type_registry
protected

Definition at line 1288 of file systemhtml.py.


The documentation for this class was generated from the following file: