Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
scripts.systemnative.DartiumBackend Class Reference
Inheritance diagram for scripts.systemnative.DartiumBackend:
scripts.htmldartgenerator.HtmlDartGenerator

Public Member Functions

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

Detailed Description

Generates Dart implementation for one DOM IDL interface.

Definition at line 88 of file systemnative.py.

Constructor & Destructor Documentation

◆ __init__()

def scripts.systemnative.DartiumBackend.__init__ (   self,
  interface,
  cpp_library_emitter,
  options,
  loggerParent 
)

Reimplemented from scripts.htmldartgenerator.HtmlDartGenerator.

Definition at line 91 of file systemnative.py.

91 def __init__(self, interface, cpp_library_emitter, options, loggerParent):
92 super(DartiumBackend, self).__init__(interface, options, True,
93 loggerParent)
94
95 self._interface = interface
96 self._cpp_library_emitter = cpp_library_emitter
97 self._database = options.database
98 self._template_loader = options.templates
99 self._type_registry = options.type_registry
100 self._interface_type_info = self._type_registry.TypeInfo(
101 self._interface.id)
102 self._metadata = options.metadata
103 # These get initialized by StartInterface
104 self._cpp_header_emitter = None
105 self._cpp_impl_emitter = None
106 self._members_emitter = None
107 self._cpp_declarations_emitter = None
108 self._cpp_impl_includes = None
109 self._cpp_definitions_emitter = None
110 self._cpp_resolver_emitter = None
111 self._dart_js_interop = options.dart_js_interop
112 _logger.setLevel(loggerParent.level)
113

Member Function Documentation

◆ AddIndexer()

def scripts.systemnative.DartiumBackend.AddIndexer (   self,
  element_type,
  nullable 
)
Adds all the methods required to complete implementation of List.

Definition at line 704 of file systemnative.py.

704 def AddIndexer(self, element_type, nullable):
705 """Adds all the methods required to complete implementation of List."""
706 # We would like to simply inherit the implementation of everything except
707 # length, [], and maybe []=. It is possible to extend from a base
708 # array implementation class only when there is no other implementation
709 # inheritance. There might be no implementation inheritance other than
710 # DOMBaseWrapper for many classes, but there might be some where the
711 # array-ness is introduced by a non-root interface:
712 #
713 # interface Y extends X, List<T> ...
714 #
715 # In the non-root case we have to choose between:
716 #
717 # class YImpl extends XImpl { add List<T> methods; }
718 #
719 # and
720 #
721 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
722 #
723 dart_element_type = self._DartType(element_type)
724 if self._HasNativeIndexGetter():
725 self._EmitNativeIndexGetter(dart_element_type)
726 elif self._HasExplicitIndexedGetter():
727 self._EmitExplicitIndexedGetter(dart_element_type)
728 else:
729 is_custom = any((op.id == 'item' and _IsCustom(op))
730 for op in self._interface.operations)
731
732 output_conversion = self._OutputConversion(element_type, 'item')
733 conversion_name = ''
734 if output_conversion:
735 conversion_name = output_conversion.function_name
736
737 # First emit a toplevel function to do the native call
738 # Calls to this are emitted elsewhere,
739 dart_native_name, resolver_string = \
740 self.DeriveNativeEntry("item", 'Method', 1)
741
742 # Emit the method which calls the toplevel function, along with
743 # the [] operator.
744 dart_qualified_name = \
745 self.DeriveQualifiedBlinkName(self._interface.id,
746 dart_native_name)
747
748 type_info = self._TypeInfo(element_type)
749 blinkNativeIndexed = """
750 $TYPE operator[](int index) {
751 if (index < 0 || index >= length)
752 throw new IndexError.withLength(index, length, indexable: this);
753 return _nativeIndexedGetter(index);
754 }
755
756 $TYPE _nativeIndexedGetter(int index) => $(CONVERSION_NAME)($(DART_NATIVE_NAME)(this, index));
757"""
758 blinkNativeIndexedGetter = \
759 ' $(DART_NATIVE_NAME)(this, index);\n'
760 self._members_emitter.Emit(
761 blinkNativeIndexed,
762 DART_NATIVE_NAME=dart_qualified_name,
763 TYPE=self.SecureOutputType(element_type),
764 INTERFACE=self._interface.id,
765 CONVERSION_NAME=conversion_name)
766
767 if self._HasNativeIndexSetter():
768 self._EmitNativeIndexSetter(dart_element_type)
769 else:
770 self._members_emitter.Emit(
771 '\n'
772 ' void operator[]=(int index, $TYPE value) {\n'
773 ' throw new UnsupportedError("Cannot assign element of immutable List.");\n'
774 ' }\n',
775 TYPE=dart_element_type)
776
777 self.EmitListMixin(dart_element_type, nullable)
778
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530

◆ AmendIndexer()

def scripts.systemnative.DartiumBackend.AmendIndexer (   self,
  element_type 
)

Definition at line 779 of file systemnative.py.

779 def AmendIndexer(self, element_type):
780 # If interface is marked as having native indexed
781 # getter or setter, we must emit overrides as it's not
782 # guaranteed that the corresponding methods in C++ would be
783 # virtual. For example, as of time of writing, even though
784 # Uint8ClampedArray inherits from Uint8Array, ::set method
785 # is not virtual and accessing it through Uint8Array pointer
786 # would lead to wrong semantics (modulo vs. clamping.)
787 dart_element_type = self._DartType(element_type)
788
789 if self._HasNativeIndexGetter():
790 self._EmitNativeIndexGetter(dart_element_type)
791 if self._HasNativeIndexSetter():
792 self._EmitNativeIndexSetter(dart_element_type)
793

◆ CustomJSMembers()

def scripts.systemnative.DartiumBackend.CustomJSMembers (   self)

Definition at line 120 of file systemnative.py.

120 def CustomJSMembers(self):
121 return {}
122

◆ DeriveNativeEntry()

def scripts.systemnative.DartiumBackend.DeriveNativeEntry (   self,
  name,
  kind,
  count 
)

Definition at line 158 of file systemnative.py.

158 def DeriveNativeEntry(self, name, kind, count):
159 interface_id = self._interface.id
160 database = self._database
161 tag = ""
162 if kind == 'Getter':
163 tag = "%s_Getter" % name
164 blink_entry = tag
165 elif kind == 'Setter':
166 tag = "%s_Setter" % name
167 blink_entry = tag
168 elif kind == 'Constructor':
169 tag = "constructorCallback"
170 blink_entry = tag
171 elif kind == 'Method':
172 tag = "%s_Callback" % name
173 blink_entry = tag
174
175 interface_id = TypeIdToBlinkName(interface_id, database)
176
177 def mkPublic(s):
178 if s.startswith("_") or s.startswith("$"):
179 return "$" + s
180 return s
181
182 if count is not None:
183 arity = str(count)
184 dart_name = mkPublic("_".join([tag, arity]))
185 else:
186 dart_name = mkPublic(tag)
187 resolver_string = "_".join([interface_id, tag])
188
189 return (dart_name, resolver_string)
190
def TypeIdToBlinkName(interface_id, database)
Definition: systemnative.py:38
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ DeriveNativeName()

def scripts.systemnative.DartiumBackend.DeriveNativeName (   self,
  name,
  suffix = "" 
)

Definition at line 191 of file systemnative.py.

191 def DeriveNativeName(self, name, suffix=""):
192 fields = ['$' + name]
193 if suffix != "":
194 fields.append(suffix)
195 return "_".join(fields)
196

◆ DeriveQualifiedBlinkName()

def scripts.systemnative.DartiumBackend.DeriveQualifiedBlinkName (   self,
  interface_name,
  name 
)

Definition at line 197 of file systemnative.py.

197 def DeriveQualifiedBlinkName(self, interface_name, name):
198 blinkClass = DeriveQualifiedName("_blink",
199 DeriveBlinkClassName(interface_name))
200 blinkInstance = DeriveQualifiedName(blinkClass, "instance")
201 return DeriveQualifiedName(blinkInstance, name + "_")
202
def DeriveQualifiedName(library_name, name)
Definition: systemnative.py:56
def DeriveBlinkClassName(name)
Definition: systemnative.py:60

◆ EmitAttribute()

def scripts.systemnative.DartiumBackend.EmitAttribute (   self,
  attribute,
  html_name,
  read_only 
)

Definition at line 550 of file systemnative.py.

550 def EmitAttribute(self, attribute, html_name, read_only):
551 self._AddGetter(attribute, html_name, read_only)
552 if not read_only:
553 self._AddSetter(attribute, html_name)
554

◆ EmitOperation()

def scripts.systemnative.DartiumBackend.EmitOperation (   self,
  info,
  html_name,
  dart_js_interop = False 
)
Arguments:
info: An OperationInfo object.

Definition at line 845 of file systemnative.py.

845 def EmitOperation(self, info, html_name, dart_js_interop=False):
846 """
847 Arguments:
848 info: An OperationInfo object.
849 """
850 if self._renamer.isPrivate(self._interface, info.operations[0].id):
851 # Any private operations with Maps parameters changed to any type.
852 # The public method that delegates to this private operation has already
853 # converted from Map to native (JsObject) e.g., Element.animate.
854 self._ChangePrivateOpMapArgToAny(info.operations)
855
856 return_type = self.SecureOutputType(info.type_name, False,
857 False if dart_js_interop else True)
858
859 formals = info.ParametersAsDeclaration(self._DartType)
860
861 parameters = info.ParametersAsListOfVariables(
862 None, self._type_registry if self._dart_use_blink else None,
863 dart_js_interop, self)
864
865 operation = info.operations[0]
866
867 output_conversion = self._OutputConversion(operation.type.id,
868 operation.id)
869
870 dictionary_returned = False
871 # Return type for dictionary is any (untyped).
872 if operation.type.id == 'Dictionary':
873 return_type = ''
874 dictionary_returned = True
875
876 dart_declaration = '%s%s %s(%s)' % ('static ' if info.IsStatic() else
877 '', return_type, html_name, formals)
878
879 is_custom = _IsCustom(operation)
880 has_optional_arguments = any(
881 IsOptional(argument) for argument in operation.arguments)
882 needs_dispatcher = not is_custom and (len(info.operations) > 1 or
883 has_optional_arguments)
884
885 # Operation uses blink?
886 wrap_unwrap_list = []
887 return_wrap_jso = False
888 # return type wrapped?
889 if self._dart_use_blink:
890 # Wrap the type to store the JsObject if Type is:
891 #
892 # it's a dynamic/any type
893 # - type is Object
894 #
895 # JsObject maybe stored in the Dart class.
896 return_wrap_jso = wrap_return_type_blink(
897 return_type, info.type_name, self._type_registry)
898 return_type_info = self._type_registry.TypeInfo(info.type_name)
899 # wrap_jso the returned object
900 wrap_unwrap_list.append(return_wrap_jso)
901 wrap_unwrap_list.append(self._dart_use_blink)
902
903 if info.callback_args:
904 self._AddFutureifiedOperation(info, html_name)
905 elif not needs_dispatcher:
906 # Bind directly to native implementation
907 argument_count = (0 if info.IsStatic() else 1) + len(
908 info.param_infos)
909 native_suffix = 'Callback'
910 auto_scope_setup = self._GenerateAutoSetupScope(
911 info.name, native_suffix)
912 native_entry = \
913 self.DeriveNativeEntry(operation.id, 'Method', len(info.param_infos))
914 cpp_callback_name = self._GenerateNativeBinding(
915 info.name,
916 argument_count,
917 dart_declaration,
918 info.IsStatic(),
919 return_type,
920 parameters,
921 native_suffix,
922 is_custom,
923 auto_scope_setup,
924 native_entry=native_entry,
925 wrap_unwrap_list=wrap_unwrap_list,
926 dictionary_return=dictionary_returned,
927 output_conversion=output_conversion)
928 if not is_custom:
929 self._GenerateOperationNativeCallback(
930 operation, operation.arguments, cpp_callback_name,
931 auto_scope_setup)
932 else:
933 self._GenerateDispatcher(info, info.operations, dart_declaration,
934 html_name)
935

◆ EmitStaticFactoryOverload()

def scripts.systemnative.DartiumBackend.EmitStaticFactoryOverload (   self,
  constructor_info,
  name,
  arguments 
)

Definition at line 339 of file systemnative.py.

339 def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
340 constructor_callback_cpp_name = name + 'constructorCallback'
341 self._EmitConstructorInfrastructure(
342 constructor_info,
343 name,
344 'constructorCallback',
345 name,
346 arguments,
347 emit_to_native=True,
348 is_custom=False)
349
350 ext_attrs = self._interface.ext_attrs
351
352 create_function = 'create'
353 if 'NamedConstructor' in ext_attrs:
354 create_function = 'createForJSConstructor'
355 function_expression = '%s::%s' % (
356 self._interface_type_info.native_type(), create_function)
357

◆ FinishInterface()

def scripts.systemnative.DartiumBackend.FinishInterface (   self)

Definition at line 370 of file systemnative.py.

370 def FinishInterface(self):
371 interface = self._interface
372 if interface.parents:
373 supertype = '%sClassId' % interface.parents[0].type.id
374 else:
375 supertype = '-1'
376
377 self._GenerateCPPHeader()
378
379 self._cpp_impl_emitter.Emit(
380 self._template_loader.Load('cpp_implementation.template'),
381 INTERFACE=self._interface.id,
382 SUPER_INTERFACE=supertype,
383 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes),
384 CALLBACKS=self._cpp_definitions_emitter.Fragments(),
385 RESOLVER=self._cpp_resolver_emitter.Fragments(),
386 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
387 WEBCORE_CLASS_NAME_ESCAPED=self._interface_type_info.native_type().
388 replace('<', '_').replace('>', '_'),
389 DART_IMPLEMENTATION_CLASS=self._interface_type_info.
390 implementation_name(),
391 DART_IMPLEMENTATION_LIBRARY_ID='Dart%sLibraryId' %
392 self._renamer.GetLibraryId(self._interface))
393

◆ GenerateCallback()

def scripts.systemnative.DartiumBackend.GenerateCallback (   self,
  info 
)

Definition at line 137 of file systemnative.py.

137 def GenerateCallback(self, info):
138 return None
139

◆ GenerateCustomFactory()

def scripts.systemnative.DartiumBackend.GenerateCustomFactory (   self,
  constructor_info 
)

Definition at line 297 of file systemnative.py.

297 def GenerateCustomFactory(self, constructor_info):
298 if 'CustomConstructor' not in self._interface.ext_attrs:
299 return False
300
301 annotations = self._metadata.GetFormattedMetadata(
302 self._library_name, self._interface, self._interface.id, ' ')
303
304 self._members_emitter.Emit(
305 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n',
306 ANNOTATIONS=annotations,
307 CTOR=constructor_info._ConstructorFullName(self._DartType),
308 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType),
309 FACTORY_PARAMS= \
310 constructor_info.ParametersAsArgumentList())
311
312 # MutationObserver has custom _create. TODO(terry): Consider table but this is only one.
313 if self._interface.id != 'MutationObserver':
314 constructor_callback_cpp_name = 'constructorCallback'
315 self._EmitConstructorInfrastructure(
316 constructor_info,
317 "",
318 constructor_callback_cpp_name,
319 '_create',
320 is_custom=True)
321
322 self._cpp_declarations_emitter.Emit(
323 '\n'
324 'void $CPP_CALLBACK(Dart_NativeArguments);\n',
325 CPP_CALLBACK=constructor_callback_cpp_name)
326
327 return True
328

◆ GetSupportCheck()

def scripts.systemnative.DartiumBackend.GetSupportCheck (   self)

Definition at line 362 of file systemnative.py.

362 def GetSupportCheck(self):
363 # Assume that everything is supported on Dartium.
364 value = js_support_checks.get(self._interface.doc_js_name)
365 if type(value) == tuple:
366 return (value[0], 'true')
367 else:
368 return 'true'
369
GLenum type

◆ HasSupportCheck()

def scripts.systemnative.DartiumBackend.HasSupportCheck (   self)

Definition at line 358 of file systemnative.py.

358 def HasSupportCheck(self):
359 # Need to omit a support check if it is conditional in JS.
360 return self._interface.doc_js_name in js_support_checks
361

◆ ImplementationTemplate()

def scripts.systemnative.DartiumBackend.ImplementationTemplate (   self)

Definition at line 140 of file systemnative.py.

140 def ImplementationTemplate(self):
141 template = None
142 interface_name = self._interface.doc_js_name
143 if interface_name == self._interface.id or not self._database.HasInterface(
144 interface_name):
145 template_file = 'impl_%s.darttemplate' % interface_name
146 template = self._template_loader.TryLoad(template_file)
147 if not template:
148 template = self._template_loader.Load(
149 'dart_implementation.darttemplate')
150 return template
151

◆ ImplementsMergedMembers()

def scripts.systemnative.DartiumBackend.ImplementsMergedMembers (   self)

Definition at line 114 of file systemnative.py.

114 def ImplementsMergedMembers(self):
115 # We could not add merged functions to implementation class because
116 # underlying c++ object doesn't implement them. Merged functions are
117 # generated on merged interface implementation instead.
118 return False
119

◆ IsConstructorArgumentOptional()

def scripts.systemnative.DartiumBackend.IsConstructorArgumentOptional (   self,
  argument 
)

Definition at line 329 of file systemnative.py.

329 def IsConstructorArgumentOptional(self, argument):
330 return IsOptional(argument)
331

◆ MakeFactoryCall()

def scripts.systemnative.DartiumBackend.MakeFactoryCall (   self,
  factory,
  method,
  arguments,
  constructor_info 
)

Definition at line 332 of file systemnative.py.

332 def MakeFactoryCall(self, factory, method, arguments, constructor_info):
333 return emitter.Format(
334 '$FACTORY.$METHOD($ARGUMENTS)',
335 FACTORY=factory,
336 METHOD=method,
337 ARGUMENTS=arguments)
338

◆ NativeSpec()

def scripts.systemnative.DartiumBackend.NativeSpec (   self)

Definition at line 203 of file systemnative.py.

203 def NativeSpec(self):
204 return ''
205

◆ RootClassName()

def scripts.systemnative.DartiumBackend.RootClassName (   self)

Definition at line 152 of file systemnative.py.

152 def RootClassName(self):
153 return 'DartHtmlDomObject'
154

◆ SecondaryContext()

def scripts.systemnative.DartiumBackend.SecondaryContext (   self,
  interface 
)

Definition at line 995 of file systemnative.py.

995 def SecondaryContext(self, interface):
996 pass
997

◆ StartInterface()

def scripts.systemnative.DartiumBackend.StartInterface (   self,
  members_emitter 
)

Definition at line 206 of file systemnative.py.

206 def StartInterface(self, members_emitter):
207 # Create emitters for c++ implementation.
208 if not IsPureInterface(self._interface.id, self._database) and \
209 not IsCustomType(self._interface.id):
210 self._cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(
211 self._interface.id,
212 self._renamer.GetLibraryName(self._interface))
213 self._cpp_impl_emitter = \
214 self._cpp_library_emitter.CreateSourceEmitter(self._interface.id)
215 else:
216 self._cpp_header_emitter = emitter.Emitter()
217 self._cpp_impl_emitter = emitter.Emitter()
218
219 self._interface_type_info = self._TypeInfo(self._interface.id)
220 self._members_emitter = members_emitter
221
222 self._cpp_declarations_emitter = emitter.Emitter()
223
224 # This is a hack to work around a strange C++ compile error that we weren't
225 # able to track down the true cause of.
226 if self._interface.id == 'Timing':
227 self._cpp_impl_includes.add('"core/animation/TimedItem.h"')
228
229 self._cpp_definitions_emitter = emitter.Emitter()
230 self._cpp_resolver_emitter = emitter.Emitter()
231
232 # We need to revisit our treatment of typed arrays, right now
233 # it is full of hacks.
234 if self._interface.ext_attrs.get('ConstructorTemplate') == 'TypedArray':
235 self._cpp_resolver_emitter.Emit(
236 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
237 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n',
238 INTERFACE_NAME=self._interface.id)
239
240 self._cpp_impl_includes.add('"DartArrayBufferViewCustom.h"')
241 self._cpp_definitions_emitter.Emit(
242 '\n'
243 'static void constructorCallback(Dart_NativeArguments args)\n'
244 '{\n'
245 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INTERFACE_NAME)>(args);\n'
246 '}\n',
247 INTERFACE_NAME=self._interface.id)
248

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