Flutter Engine
tonic Namespace Reference

Namespaces

 DartError
 

Classes

class  DartApiScope
 
struct  DartArgHolder
 
class  DartArgIterator
 
class  DartByteData
 
class  DartClassLibrary
 
class  DartClassProvider
 
struct  DartConverter
 
struct  DartConverter< bool >
 
struct  DartConverter< const char * >
 
struct  DartConverter< Dart_Handle >
 
struct  DartConverter< DartByteData >
 
struct  DartConverter< DartConverterMapping >
 
struct  DartConverter< DartList >
 
struct  DartConverter< double >
 
struct  DartConverter< float >
 
struct  DartConverter< flutter::Paint >
 
struct  DartConverter< flutter::PaintData >
 
struct  DartConverter< flutter::RRect >
 
struct  DartConverter< int >
 
struct  DartConverter< long int >
 
struct  DartConverter< long long >
 
struct  DartConverter< PTR< T > >
 
struct  DartConverter< std::string >
 
struct  DartConverter< std::u16string >
 
struct  DartConverter< std::vector< T > >
 
struct  DartConverter< T *, typename std::enable_if< std::is_convertible< T *, const DartWrappable * >::value >::type >
 
struct  DartConverter< T, typename std::enable_if< std::is_enum< T >::value >::type >
 
struct  DartConverter< TypedList< kTypeName, ElemType > >
 
struct  DartConverter< unsigned >
 
struct  DartConverter< unsigned long >
 
struct  DartConverter< unsigned long long >
 
struct  DartConverterFloatingPoint
 
struct  DartConverterInteger
 
struct  DartConverterTypes
 
struct  DartConverterWrappable
 
class  DartDispatcher
 
struct  DartDispatcher< IndicesHolder< indices... >, ResultType(*)(ArgTypes...)>
 
struct  DartDispatcher< IndicesHolder< indices... >, ResultType(C::*)(ArgTypes...)>
 
struct  DartDispatcher< IndicesHolder< indices... >, ReturnType(C::*)(ArgTypes...) const >
 
struct  DartDispatcher< IndicesHolder< indices... >, void(*)(ArgTypes...)>
 
struct  DartDispatcher< IndicesHolder< indices... >, void(C::*)(ArgTypes...)>
 
class  DartIsolateScope
 
class  DartLibraryNatives
 
class  DartList
 
struct  DartListFactory
 
class  DartMessageHandler
 
class  DartMicrotaskQueue
 
class  DartPersistentValue
 
class  DartState
 
class  DartWrappable
 
struct  DartWrapperInfo
 
class  FileLoader
 
class  IndicesForSignature
 
struct  IndicesForSignature< ResultType(*)(ArgTypes...)>
 
struct  IndicesForSignature< ResultType(C::*)(ArgTypes...) const >
 
struct  IndicesForSignature< ResultType(C::*)(ArgTypes...)>
 
struct  IndicesGenerator
 
struct  IndicesGenerator< 0, indices... >
 
struct  IndicesHolder
 
class  PackagesMap
 
class  TypedList
 

Typedefs

using DartConverterMapping = std::unique_ptr< fml::Mapping >
 
typedef void(* DartWrappableAccepter) (DartWrappable *)
 

Enumerations

enum  DartErrorHandleType {
  kNoError,
  kUnknownErrorType,
  kApiErrorType,
  kCompilationErrorType
}
 

Functions

void Log (const char *format,...)
 
void SetLogHandler (std::function< void(const char *)> handler)
 
Dart_Handle LookupNonNullableType (const std::string &library_name, const std::string &type_name)
 
template<typename T , std::enable_if_t< std::is_same< std::string, T >::value, int > = 0>
Dart_Handle ToDartTypeHandle ()
 
template<typename T >
Dart_Handle CreateZeroInitializedDartObject (Dart_Handle type_handle_or_null=::Dart_Null())
 
template<typename T >
Dart_Handle ToDart (const T &object)
 
Dart_Handle StdStringToDart (const std::string &val)
 
std::string StdStringFromDart (Dart_Handle handle)
 
Dart_Handle ToDart (const char *val)
 
template<typename T >
void DartReturn (T result, Dart_NativeArguments args)
 
template<typename Sig >
void DartCall (Sig func, Dart_NativeArguments args)
 
template<typename Sig >
void DartCallStatic (Sig func, Dart_NativeArguments args)
 
template<typename Sig >
void DartCallConstructor (Sig func, Dart_NativeArguments args)
 
template<typename T >
T * GetReceiver (Dart_NativeArguments args)
 
bool LogIfError (Dart_Handle handle)
 
DartErrorHandleType GetErrorHandleType (Dart_Handle handle)
 
int GetErrorExitCode (Dart_Handle handle)
 
Dart_Handle DartInvokeField (Dart_Handle target, const char *name, std::initializer_list< Dart_Handle > args)
 
Dart_Handle DartInvoke (Dart_Handle closure, std::initializer_list< Dart_Handle > args)
 
Dart_Handle DartInvokeVoid (Dart_Handle closure)
 

Typedef Documentation

◆ DartConverterMapping

using tonic::DartConverterMapping = typedef std::unique_ptr<fml::Mapping>

Definition at line 17 of file dart_converter.h.

◆ DartWrappableAccepter

typedef void(* tonic::DartWrappableAccepter) (DartWrappable *)

Definition at line 13 of file dart_wrapper_info.h.

Enumeration Type Documentation

◆ DartErrorHandleType

Enumerator
kNoError 
kUnknownErrorType 
kApiErrorType 
kCompilationErrorType 

Definition at line 18 of file dart_error.h.

Function Documentation

◆ CreateZeroInitializedDartObject()

template<typename T >
Dart_Handle tonic::CreateZeroInitializedDartObject ( Dart_Handle  type_handle_or_null = ::Dart_Null())

Definition at line 320 of file dart_converter.h.

References LogIfError(), and value.

321  {
322  if constexpr (std::is_same<std::string, T>::value) {
323  return ::Dart_EmptyString();
324  } else if constexpr (std::is_integral<T>::value) {
325  return ::Dart_NewIntegerFromUint64(0u);
326  } else if constexpr (std::is_floating_point<T>::value) {
327  return ::Dart_NewDouble(0.0);
328  } else {
329  auto object = ::Dart_New(type_handle_or_null, ::Dart_Null(), 0, nullptr);
330  LogIfError(object);
331  return object;
332  }
333  return ::Dart_Null();
334 }
uint8_t value
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ DartCall()

template<typename Sig >
void tonic::DartCall ( Sig  func,
Dart_NativeArguments  args 
)

Definition at line 198 of file dart_args.h.

References tonic::DartArgIterator::had_exception().

198  {
199  DartArgIterator it(args);
200  using Indices = typename IndicesForSignature<Sig>::type;
201  DartDispatcher<Indices, Sig> decoder(&it);
202  if (it.had_exception())
203  return;
204  decoder.Dispatch(func);
205 }
G_BEGIN_DECLS FlValue * args

◆ DartCallConstructor()

template<typename Sig >
void tonic::DartCallConstructor ( Sig  func,
Dart_NativeArguments  args 
)

Definition at line 218 of file dart_args.h.

References tonic::DartArgIterator::had_exception(), tonic::DartWrappable::kNumberOfNativeFields, tonic::DartWrappable::kPeerIndex, tonic::DartWrappable::kWrapperInfoIndex, LogIfError(), and TONIC_CHECK.

Referenced by flutter::Canvas_constructor(), flutter::ColorFilter_constructor(), flutter::Gradient_constructor(), flutter::ImageFilter_constructor(), flutter::ImageShader_constructor(), flutter::ParagraphBuilder_constructor(), flutter::Path_constructor(), flutter::PathMeasure_constructor(), flutter::PictureRecorder_constructor(), flutter::SceneBuilder_constructor(), and flutter::SemanticsUpdateBuilder_constructor().

218  {
219  DartArgIterator it(args);
220  using Indices = typename IndicesForSignature<Sig>::type;
221  using Wrappable = typename DartDispatcher<Indices, Sig>::CtorResultType;
222  Wrappable wrappable;
223  {
224  DartDispatcher<Indices, Sig> decoder(&it);
225  if (it.had_exception())
226  return;
227  wrappable = decoder.DispatchCtor(func);
228  }
229 
230  Dart_Handle wrapper = Dart_GetNativeArgument(args, 0);
231  TONIC_CHECK(!LogIfError(wrapper));
232 
233  intptr_t native_fields[DartWrappable::kNumberOfNativeFields];
234  TONIC_CHECK(!LogIfError(Dart_GetNativeFieldsOfArgument(
235  args, 0, DartWrappable::kNumberOfNativeFields, native_fields)));
236  TONIC_CHECK(!native_fields[DartWrappable::kPeerIndex]);
237  TONIC_CHECK(!native_fields[DartWrappable::kWrapperInfoIndex]);
238 
239  wrappable->AssociateWithDartWrapper(wrapper);
240 }
G_BEGIN_DECLS FlValue * args
#define TONIC_CHECK(condition)
Definition: macros.h:23
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ DartCallStatic()

template<typename Sig >
void tonic::DartCallStatic ( Sig  func,
Dart_NativeArguments  args 
)

Definition at line 208 of file dart_args.h.

References tonic::DartArgIterator::had_exception().

208  {
209  DartArgIterator it(args, 0);
210  using Indices = typename IndicesForSignature<Sig>::type;
211  DartDispatcher<Indices, Sig> decoder(&it);
212  if (it.had_exception())
213  return;
214  decoder.Dispatch(func);
215 }
G_BEGIN_DECLS FlValue * args

◆ DartInvoke()

Dart_Handle tonic::DartInvoke ( Dart_Handle  closure,
std::initializer_list< Dart_Handle >  args 
)

Definition at line 20 of file dart_invoke.cc.

References LogIfError().

Referenced by flutter::PlatformMessageResponseDart::Complete(), flutter::PlatformMessageResponseDart::CompleteEmpty(), flutter::SingleFrameCodec::getNextFrame(), flutter::ImmutableBuffer::init(), flutter::ImageDescriptor::initEncoded(), flutter::InvokeNextFrameCallback(), and flutter::Picture::RasterizeToImage().

21  {
22  int argc = args.size();
23  Dart_Handle* argv = const_cast<Dart_Handle*>(args.begin());
24  Dart_Handle handle = Dart_InvokeClosure(closure, argc, argv);
25  LogIfError(handle);
26  return handle;
27 }
G_BEGIN_DECLS FlValue * args
std::function< void()> closure
Definition: closure.h:14
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ DartInvokeField()

◆ DartInvokeVoid()

Dart_Handle tonic::DartInvokeVoid ( Dart_Handle  closure)

Definition at line 29 of file dart_invoke.cc.

References LogIfError().

29  {
30  Dart_Handle handle = Dart_InvokeClosure(closure, 0, nullptr);
31  LogIfError(handle);
32  return handle;
33 }
std::function< void()> closure
Definition: closure.h:14
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ DartReturn()

template<typename T >
void tonic::DartReturn ( result,
Dart_NativeArguments  args 
)

◆ GetErrorExitCode()

int tonic::GetErrorExitCode ( Dart_Handle  handle)

Definition at line 46 of file dart_error.cc.

Referenced by dart_runner::DartComponentController::Main().

46  {
47  if (Dart_IsCompilationError(handle)) {
48  return 254; // dart::bin::kCompilationErrorExitCode
49  } else if (Dart_IsApiError(handle)) {
50  return 253; // dart::bin::kApiErrorExitCode
51  } else if (Dart_IsError(handle)) {
52  return 255; // dart::bin::kErrorExitCode
53  } else {
54  return 0;
55  }
56 }

◆ GetErrorHandleType()

DartErrorHandleType tonic::GetErrorHandleType ( Dart_Handle  handle)

Definition at line 34 of file dart_error.cc.

References kApiErrorType, kCompilationErrorType, kNoError, and kUnknownErrorType.

Referenced by tonic::DartMicrotaskQueue::RunMicrotasks(), and tonic::DartMessageHandler::UnhandledError().

34  {
35  if (Dart_IsCompilationError(handle)) {
36  return kCompilationErrorType;
37  } else if (Dart_IsApiError(handle)) {
38  return kApiErrorType;
39  } else if (Dart_IsError(handle)) {
40  return kUnknownErrorType;
41  } else {
42  return kNoError;
43  }
44 }

◆ GetReceiver()

template<typename T >
T* tonic::GetReceiver ( Dart_NativeArguments  args)
inline

Definition at line 170 of file dart_wrappable.h.

References ToDart(), and TONIC_DCHECK.

170  {
171  intptr_t receiver;
172  Dart_Handle result = Dart_GetNativeReceiver(args, &receiver);
173  TONIC_DCHECK(!Dart_IsError(result));
174  if (!receiver)
175  Dart_ThrowException(ToDart("Object has been disposed."));
176  return static_cast<T*>(reinterpret_cast<DartWrappable*>(receiver));
177 }
G_BEGIN_DECLS FlValue * args
#define TONIC_DCHECK
Definition: macros.h:32
Dart_Handle ToDart(const T &object)

◆ Log()

void tonic::Log ( const char *  format,
  ... 
)

Definition at line 19 of file log.cc.

References fml::size().

Referenced by tonic::FileLoader::LoadPackagesMap(), and LogIfError().

19  {
20  va_list ap;
21  va_start(ap, format);
22  int result = vsnprintf(nullptr, 0, format, ap);
23  va_end(ap);
24 
25  if (result < 0) {
26  return;
27  }
28 
29  int size = result + 1;
30  std::unique_ptr<char[]> message(new char[size]);
31  va_start(ap, format);
32  result = vsnprintf(message.get(), size, format, ap);
33  va_end(ap);
34 
35  if (result < 0) {
36  return;
37  }
38 
39  if (log_handler) {
40  log_handler(message.get());
41  } else {
42  printf("%s\n", message.get());
43  }
44 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ LogIfError()

bool tonic::LogIfError ( Dart_Handle  handle)

Definition at line 15 of file dart_error.cc.

References Log(), and StdStringFromDart().

Referenced by tonic::DartWrappable::AssociateWithDartWrapper(), flutter::PlatformConfiguration::BeginFrame(), zircon::dart::HandleWaiter::Cancel(), tonic::DartWrappable::ClearDartWrapper(), flutter_runner::IsolateConfigurator::ConfigureCurrentIsolate(), flutter_runner::CreateCompilationTrace(), tonic::DartWrappable::CreateDartWrapper(), CreateZeroInitializedDartObject(), tonic::DartByteData::DartByteData(), DartCallConstructor(), DartInvoke(), DartInvokeVoid(), flutter::PlatformConfiguration::DispatchPlatformMessage(), flutter::Window::DispatchPointerDataPacket(), flutter::PlatformConfiguration::DispatchSemanticsAction(), tonic::DartConverter< flutter::RRect >::FromArguments(), tonic::DartConverter< flutter::Paint >::FromArguments(), tonic::DartConverter< DartByteData >::FromArguments(), tonic::DartConverter< DartList >::FromArguments(), tonic::DartConverter< TypedList< kTypeName, ElemType > >::FromArguments(), flutter::DartIsolate::GetServiceId(), dart_runner::InitBuiltinLibrariesForIsolate(), flutter::DartIO::InitForIsolate(), zircon::dart::Initialize(), fuchsia::dart::Initialize(), flutter::InvokeMainEntrypoint(), LookupNonNullableType(), dart_runner::DartComponentController::Main(), tonic::DartListFactory< T, Enable >::NewList(), tonic::DartMessageHandler::OnHandleMessage(), flutter::DartIsolate::PrepareForRunningFromPrecompiledCode(), flutter::PlatformConfiguration::ReportTimings(), tonic::DartMicrotaskQueue::RunMicrotasks(), zircon::dart::Handle::ScheduleCallback(), flutter::UIDartState::ScheduleMicrotask(), tonic::DartList::Set(), flutter::testing::TestDartNativeResolver::SetNativeResolverForIsolate(), flutter::testing::TEST_F(), tonic::DartConverter< TypedList< kTypeName, ElemType > >::ToDart(), tonic::TypedList< kTypeName, ElemType >::TypedList(), flutter::PlatformConfiguration::UpdateAccessibilityFeatures(), flutter::PlatformConfiguration::UpdateLifecycleState(), flutter::PlatformConfiguration::UpdateLocales(), flutter::PlatformConfiguration::UpdateSemanticsEnabled(), flutter::PlatformConfiguration::UpdateUserSettingsData(), flutter::Window::UpdateWindowMetrics(), and zircon::dart::System::VmoMap().

15  {
16  if (Dart_IsUnhandledExceptionError(handle)) {
17  Dart_Handle exception_handle = Dart_ErrorGetException(handle);
18  const std::string exception =
19  tonic::StdStringFromDart(Dart_ToString(exception_handle));
20  Dart_Handle stack_trace_handle = Dart_ErrorGetStackTrace(handle);
21  const std::string stack_trace =
22  tonic::StdStringFromDart(Dart_ToString(stack_trace_handle));
23  tonic::Log("Dart Unhandled Exception: %s, stack trace: %s",
24  exception.c_str(), stack_trace.c_str());
25  return true;
26  } else if (Dart_IsError(handle)) {
27  tonic::Log("Dart Error: %s", Dart_GetError(handle));
28  return true;
29  } else {
30  return false;
31  }
32 }
void Log(const char *format,...)
Definition: log.cc:19
std::string StdStringFromDart(Dart_Handle handle)

◆ LookupNonNullableType()

Dart_Handle tonic::LookupNonNullableType ( const std::string &  library_name,
const std::string &  type_name 
)
inline

Definition at line 284 of file dart_converter.h.

References LogIfError(), ToDart(), and value.

Referenced by ToDartTypeHandle().

285  {
286  auto library =
287  Dart_LookupLibrary(DartConverter<std::string>::ToDart(library_name));
288  if (LogIfError(library)) {
289  return library;
290  }
291  auto type_string = DartConverter<std::string>::ToDart(type_name);
292  if (LogIfError(type_string)) {
293  return type_string;
294  }
295  auto type = Dart_GetNonNullableType(library, type_string, 0, nullptr);
296  if (LogIfError(type)) {
297  return type;
298  }
299  return type;
300 }
Dart_Handle ToDart(const char *val)
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ SetLogHandler()

void tonic::SetLogHandler ( std::function< void(const char *)>  handler)

Definition at line 46 of file log.cc.

Referenced by flutter::PerformInitializationTasks().

46  {
47  log_handler = handler;
48 }

◆ StdStringFromDart()

std::string tonic::StdStringFromDart ( Dart_Handle  handle)
inline

◆ StdStringToDart()

Dart_Handle tonic::StdStringToDart ( const std::string &  val)
inline

◆ ToDart() [1/2]

template<typename T >
Dart_Handle tonic::ToDart ( const T &  object)

Definition at line 442 of file dart_converter.h.

References ToDart().

Referenced by flutter::CanvasPath::addPath(), flutter::CanvasPath::addPathWithMatrix(), flutter::ParagraphBuilder::addText(), zircon::dart::HandleWaiter::Cancel(), zircon::dart::System::ChannelCreate(), zircon::dart::System::ChannelFromFile(), zircon::dart::System::ChannelQueryAndRead(), flutter::Canvas::clipPath(), flutter::ComputePlatformResolvedLocale(), flutter_runner::IsolateConfigurator::ConfigureCurrentIsolate(), flutter::Canvas::Create(), zircon::dart::Handle::CreateInvalid(), tonic::DartByteData::DartByteData(), tonic::DartClassProvider::DartClassProvider(), flutter::PlatformConfiguration::DidCreateIsolate(), flutter::PlatformConfiguration::DispatchPlatformMessage(), flutter::PlatformConfiguration::DispatchSemanticsAction(), flutter::Canvas::drawAtlas(), flutter::Canvas::drawImage(), flutter::Canvas::drawImageNine(), flutter::Canvas::drawImageRect(), flutter::Canvas::drawPath(), flutter::Canvas::drawPicture(), flutter::Canvas::drawShadow(), flutter::Canvas::drawVertices(), zircon::dart::Handle::Duplicate(), flutter::EncodeImage(), zircon::dart::System::EventpairCreate(), flutter::CanvasPath::extendWithPath(), flutter::CanvasPath::extendWithPathAndMatrix(), tonic::DartClassProvider::GetClassByName(), flutter::MultiFrameCodec::getNextFrame(), flutter::SingleFrameCodec::getNextFrame(), GetReceiver(), flutter::GetVMServiceAssetsArchiveCallback(), dart_runner::GetVMServiceAssetsArchiveCallback(), flutter::ImmutableBuffer::init(), dart_runner::InitBuiltinLibrariesForIsolate(), flutter::InitDartAsync(), flutter::InitDartCore(), flutter::InitDartInternal(), flutter::InitDartIO(), flutter::ImageDescriptor::initEncoded(), flutter::DartUI::InitForIsolate(), flutter::DartIO::InitForIsolate(), zircon::dart::Initialize(), fuchsia::dart::Initialize(), flutter::ImageShader::initWithImage(), flutter::DartRuntimeHooks::Install(), flutter::InvokeFunction(), flutter::InvokeMainEntrypoint(), flutter::InvokeNextFrameCallback(), flutter::DartCallbackCache::LoadCacheFromDisk(), dart_runner::DartComponentController::Main(), flutter::Picture::RasterizeToImage(), flutter::DartIsolate::RunFromLibrary(), zircon::dart::Handle::ScheduleCallback(), tonic::DartConverter< DartConverterMapping >::SetReturnValue(), tonic::DartConverter< std::string >::SetReturnValue(), tonic::DartConverter< std::u16string >::SetReturnValue(), tonic::DartConverter< const char * >::SetReturnValue(), tonic::DartConverter< std::vector< T > >::SetReturnValue(), zircon::dart::System::SocketCreate(), zircon::dart::System::SocketRead(), zircon::dart::System::SocketWrite(), flutter::testing::TEST_F(), flutter::UIDartState::ThrowIfUIOperationsProhibited(), tonic::DartConverter< PTR< T > >::ToDart(), flutter::Picture::toImage(), flutter::Scene::toImage(), tonic::TypedList< kTypeName, ElemType >::TypedList(), flutter::PlatformConfiguration::UpdateAccessibilityFeatures(), flutter::PlatformConfiguration::UpdateSemanticsEnabled(), flutter::Window::UpdateWindowMetrics(), zircon::dart::System::VmoCreate(), zircon::dart::System::VmoFromFile(), zircon::dart::System::VmoGetSize(), zircon::dart::System::VmoMap(), zircon::dart::System::VmoRead(), and flutter::Window::Window().

442  {
443  return DartConverter<T>::ToDart(object);
444 }
Dart_Handle ToDart(const char *val)

◆ ToDart() [2/2]

Dart_Handle tonic::ToDart ( const char *  val)
inline

Definition at line 458 of file dart_converter.h.

Referenced by LookupNonNullableType(), StdStringToDart(), and ToDart().

458  {
459  return Dart_NewStringFromCString(val);
460 }

◆ ToDartTypeHandle()

template<typename T , std::enable_if_t< std::is_same< std::string, T >::value, int > = 0>
Dart_Handle tonic::ToDartTypeHandle ( )

Definition at line 304 of file dart_converter.h.

References LookupNonNullableType(), and value.

304  {
305  return LookupNonNullableType("dart:core", "String");
306 }
Dart_Handle LookupNonNullableType(const std::string &library_name, const std::string &type_name)