Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions
tonic Namespace Reference

Namespaces

namespace  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< DartList >
 
struct  DartConverter< double >
 
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  DartConverter< void >
 
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  DartWeakPersistentValue
 
class  DartWrappable
 
struct  DartWrapperInfo
 
struct  FfiDispatcher
 
struct  FfiDispatcher< C, Return(C::*)(Args...) const, method >
 
struct  FfiDispatcher< C, Return(C::*)(Args...), method >
 
struct  FfiDispatcher< C, void(C::*)(Args...), method >
 
struct  FfiDispatcher< void, Return(*)(Args...), function >
 
struct  FfiDispatcher< void, void(*)(Args...), function >
 
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

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 Arg , typename... Args>
void WriteFfiArguments (std::ostringstream *stream)
 
template<typename Arg , typename... Args>
void WriteDartArguments (std::ostringstream *stream)
 
template<typename Arg , typename... Args>
bool AllowedInLeafCall ()
 
template<typename T >
TGetReceiver (Dart_NativeArguments args)
 
void SetUnhandledExceptionReporter (DartError::UnhandledExceptionReporter reporter)
 
bool CheckAndHandleError (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

◆ 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 67 of file dart_error.h.

67 {
72};
@ kApiErrorType
Definition dart_error.h:70
@ kCompilationErrorType
Definition dart_error.h:71
@ kUnknownErrorType
Definition dart_error.h:69
const int kNoError

Function Documentation

◆ AllowedInLeafCall()

template<typename Arg , typename... Args>
bool tonic::AllowedInLeafCall ( )

Definition at line 295 of file dart_args.h.

295 {
296 bool result = tonic::DartConverter<typename std::remove_const<
297 typename std::remove_reference<Arg>::type>::type>::AllowedInLeafCall();
298 if constexpr (sizeof...(Args) > 0) {
299 result &= AllowedInLeafCall<Args...>();
300 }
301 return result;
302}
GAsyncResult * result
bool AllowedInLeafCall()
Definition dart_args.h:295

◆ CheckAndHandleError()

bool tonic::CheckAndHandleError ( Dart_Handle  handle)

Check if a Dart_Handle is an error or exception.

If it is an error or exception, this method will return true.

If it is an unhandled error or exception, the closure in |SetUnhandledExceptionReporter| is called. The DartVMInitializer provides that closure, which checks with UIDartState::Current() if it is available and falls back to simply printing the exception and stack to an error log if the settings callback is not provided.

If UIDartState::Current() is available, it can provide an onError callback that forwards to PlatformConfiguration.instance.onError. If that callback is not set, the callback from Settings.unhandled_exception_callback is invoked. If that callback is not set, a simple error log is printed.

If the PlatformDispatcher callback throws an exception, the at least two separate exceptions and stacktraces will be handled by either the Settings.unhandled_exception_callback or the error printer: one for the original exception, and one for the exception thrown in the callback. If the callback returns false, the original exception and stacktrace are logged. If it returns true, no additional logging is done.

Leaving the PlatformDispatcher.instance.onError callback unset or returning false from it matches the behavior of Flutter applications before the introduction of PlatformDispatcher.onError, which is to print to the error log.

Dart has errors that are not considered unhandled exceptions, such as Dart_* API usage errors. In these cases, Dart_IsUnhandledException returns false but Dart_IsError returns true. Such errors are logged to stderr or some similar mechanism provided by the platform such as logcat on Android. Depending on which type of error occurs, the process may crash and the Dart isolate may be unusable. Errors that fall into this category include compilation errors, Dart API errors, and unwind errors that will terminate the Dart VM.

Historically known as LogIfError.

Definition at line 33 of file dart_error.cc.

33 {
34 // Specifically handle UnhandledExceptionErrors first. These exclude fatal
35 // errors that are shutting down the vm and compilation errors in source code.
37 Dart_Handle exception_handle = Dart_ErrorGetException(handle);
38 Dart_Handle stack_trace_handle = Dart_ErrorGetStackTrace(handle);
39
40 ReportUnhandledException(exception_handle, stack_trace_handle);
41 return true;
42 } else if (Dart_IsFatalError(handle)) {
43 // An UnwindError designed to shutdown isolates. This is thrown by
44 // Isolate.exit. This is ordinary API usage, not actually an error, so
45 // silently shut down the isolate. The actual isolate shutdown happens in
46 // DartMessageHandler::UnhandledError.
47 return true;
48 } else if (Dart_IsError(handle)) {
49 tonic::Log("Dart Error: %s", Dart_GetError(handle));
50 return true;
51 } else {
52 return false;
53 }
54}
DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT bool Dart_IsFatalError(Dart_Handle handle)
DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)
void Log(const char *format,...)
Definition log.cc:19

◆ CreateZeroInitializedDartObject()

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

Definition at line 432 of file dart_converter.h.

433 {
434 if constexpr (std::is_same<std::string, T>::value) {
435 return ::Dart_EmptyString();
436 } else if constexpr (std::is_integral<T>::value) {
437 return ::Dart_NewIntegerFromUint64(0u);
438 } else if constexpr (std::is_floating_point<T>::value) {
439 return ::Dart_NewDouble(0.0);
440 } else {
441 auto object = ::Dart_New(type_handle_or_null, ::Dart_Null(), 0, nullptr);
442 CheckAndHandleError(object);
443 return object;
444 }
445 return ::Dart_Null();
446}
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_New(Dart_Handle type, Dart_Handle constructor_name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_Null(void)
bool CheckAndHandleError(Dart_Handle handle)
Definition dart_error.cc:33

◆ DartCall()

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

Definition at line 210 of file dart_args.h.

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

◆ DartCallConstructor()

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

Definition at line 230 of file dart_args.h.

230 {
232 using Indices = typename IndicesForSignature<Sig>::type;
233 using Wrappable = typename DartDispatcher<Indices, Sig>::CtorResultType;
234 Wrappable wrappable;
235 {
236 DartDispatcher<Indices, Sig> decoder(&it);
237 if (it.had_exception())
238 return;
239 wrappable = decoder.DispatchCtor(func);
240 }
241
243 TONIC_CHECK(!CheckAndHandleError(wrapper));
244
245 intptr_t native_fields[DartWrappable::kNumberOfNativeFields];
246 TONIC_CHECK(!CheckAndHandleError(Dart_GetNativeFieldsOfArgument(
247 args, 0, DartWrappable::kNumberOfNativeFields, native_fields)));
248 TONIC_CHECK(!native_fields[DartWrappable::kPeerIndex]);
249
250 wrappable->AssociateWithDartWrapper(wrapper);
251}
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument(Dart_NativeArguments args, int arg_index, int num_fields, intptr_t *field_values)
#define TONIC_CHECK(condition)
Definition macros.h:23

◆ DartCallStatic()

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

Definition at line 220 of file dart_args.h.

220 {
221 DartArgIterator it(args, 0);
222 using Indices = typename IndicesForSignature<Sig>::type;
223 DartDispatcher<Indices, Sig> decoder(&it);
224 if (it.had_exception())
225 return;
226 decoder.Dispatch(func);
227}

◆ DartInvoke()

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

Definition at line 20 of file dart_invoke.cc.

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 CheckAndHandleError(handle);
26 return handle;
27}
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, int number_of_arguments, Dart_Handle *arguments)
char ** argv
Definition library.h:9

◆ DartInvokeField()

Dart_Handle tonic::DartInvokeField ( Dart_Handle  target,
const char *  name,
std::initializer_list< Dart_Handle args 
)

Definition at line 12 of file dart_invoke.cc.

14 {
16 return Dart_Invoke(target, field, args.size(),
17 const_cast<Dart_Handle*>(args.begin()));
18}
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
uint32_t * target
const char * name
Definition fuchsia.cc:50

◆ DartInvokeVoid()

Dart_Handle tonic::DartInvokeVoid ( Dart_Handle  closure)

Definition at line 29 of file dart_invoke.cc.

29 {
30 Dart_Handle handle = Dart_InvokeClosure(closure, 0, nullptr);
31 CheckAndHandleError(handle);
32 return handle;
33}

◆ DartReturn()

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

Definition at line 99 of file dart_args.h.

99 {
101}

◆ GetErrorExitCode()

int tonic::GetErrorExitCode ( Dart_Handle  handle)

Definition at line 68 of file dart_error.cc.

68 {
69 if (Dart_IsCompilationError(handle)) {
70 return 254; // dart::bin::kCompilationErrorExitCode
71 } else if (Dart_IsApiError(handle)) {
72 return 253; // dart::bin::kApiErrorExitCode
73 } else if (Dart_IsError(handle)) {
74 return 255; // dart::bin::kErrorExitCode
75 } else {
76 return 0;
77 }
78}
DART_EXPORT bool Dart_IsApiError(Dart_Handle handle)
DART_EXPORT bool Dart_IsCompilationError(Dart_Handle handle)

◆ GetErrorHandleType()

DartErrorHandleType tonic::GetErrorHandleType ( Dart_Handle  handle)

Definition at line 56 of file dart_error.cc.

56 {
57 if (Dart_IsCompilationError(handle)) {
59 } else if (Dart_IsApiError(handle)) {
60 return kApiErrorType;
61 } else if (Dart_IsError(handle)) {
62 return kUnknownErrorType;
63 } else {
64 return kNoError;
65 }
66}

◆ GetReceiver()

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

Definition at line 198 of file dart_wrappable.h.

198 {
199 intptr_t receiver;
202 if (!receiver)
203 Dart_ThrowException(ToDart("Object has been disposed."));
204 return static_cast<T*>(reinterpret_cast<DartWrappable*>(receiver));
205}
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, intptr_t *value)
Dart_Handle ToDart(const T &object)
#define T
#define TONIC_DCHECK
Definition macros.h:32

◆ Log()

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

Definition at line 19 of file log.cc.

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 = std::make_unique<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}
uint32_t uint32_t * format
Win32Message message
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1

◆ LookupNonNullableType()

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

Definition at line 396 of file dart_converter.h.

397 {
398 auto library =
400 if (CheckAndHandleError(library)) {
401 return library;
402 }
403 auto type_string = DartConverter<std::string>::ToDart(type_name);
404 if (CheckAndHandleError(type_string)) {
405 return type_string;
406 }
407 auto type = Dart_GetNonNullableType(library, type_string, 0, nullptr);
409 return type;
410 }
411 return type;
412}
DART_EXPORT Dart_Handle Dart_GetNonNullableType(Dart_Handle library, Dart_Handle class_name, intptr_t number_of_type_arguments, Dart_Handle *type_arguments)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)

◆ SetLogHandler()

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

Definition at line 46 of file log.cc.

46 {
47 log_handler = handler;
48}

◆ SetUnhandledExceptionReporter()

void tonic::SetUnhandledExceptionReporter ( DartError::UnhandledExceptionReporter  reporter)

The fallback mechanism to log errors if the platform configuration error handler returns false.

Normally, UIDartState registers with this method in its constructor.

Definition at line 28 of file dart_error.cc.

29 {
30 log_unhandled_exception.store(reporter);
31}
reporter

◆ StdStringFromDart()

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

Definition at line 590 of file dart_converter.h.

590 {
592}

◆ StdStringToDart()

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

Definition at line 586 of file dart_converter.h.

586 {
588}

◆ ToDart() [1/2]

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

Definition at line 595 of file dart_converter.h.

595 {
596 return Dart_NewStringFromCString(val);
597}

◆ ToDart() [2/2]

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

Definition at line 579 of file dart_converter.h.

579 {
580 return DartConverter<T>::ToDart(object);
581}

◆ ToDartTypeHandle()

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

Definition at line 416 of file dart_converter.h.

416 {
417 return LookupNonNullableType("dart:core", "String");
418}
Dart_Handle LookupNonNullableType(const std::string &library_name, const std::string &type_name)

◆ WriteDartArguments()

template<typename Arg , typename... Args>
void tonic::WriteDartArguments ( std::ostringstream *  stream)

Definition at line 283 of file dart_args.h.

283 {
284 *stream << tonic::DartConverter<
285 typename std::remove_const<typename std::remove_reference<Arg>::type>::
286 type>::GetDartRepresentation();
287 if constexpr (sizeof...(Args) > 0) {
288 *stream << ", ";
289 WriteDartArguments<Args...>(stream);
290 }
291}
void WriteDartArguments(std::ostringstream *stream)
Definition dart_args.h:283

◆ WriteFfiArguments()

template<typename Arg , typename... Args>
void tonic::WriteFfiArguments ( std::ostringstream *  stream)

Definition at line 270 of file dart_args.h.

270 {
271 *stream << tonic::DartConverter<typename std::remove_const<
272 typename std::remove_reference<Arg>::type>::type>::GetFfiRepresentation();
273 if constexpr (sizeof...(Args) > 0) {
274 *stream << ", ";
275 WriteFfiArguments<Args...>(stream);
276 }
277}
void WriteFfiArguments(std::ostringstream *stream)
Definition dart_args.h:270