5#ifndef RUNTIME_VM_DART_API_IMPL_H_
6#define RUNTIME_VM_DART_API_IMPL_H_
20class FinalizablePersistentHandle;
22class PersistentHandle;
23class ReusableObjectHandleScope;
28#define CURRENT_FUNC CanonicalFunction(__FUNCTION__)
31#define CHECK_ISOLATE_GROUP(isolate_group) \
33 if ((isolate_group) == nullptr) { \
35 "%s expects there to be a current isolate group. Did you " \
36 "forget to call Dart_CreateIsolateGroup or Dart_EnterIsolate?", \
42#define CHECK_ISOLATE(isolate) \
44 if ((isolate) == nullptr) { \
46 "%s expects there to be a current isolate. Did you " \
47 "forget to call Dart_CreateIsolateGroup or Dart_EnterIsolate?", \
53#define CHECK_NO_ISOLATE(isolate) \
55 if ((isolate) != nullptr) { \
57 "%s expects there to be no current isolate. Did you " \
58 "forget to call Dart_ExitIsolate?", \
64#define CHECK_API_SCOPE(thread) \
66 Thread* tmpT = (thread); \
67 Isolate* tmpI = tmpT == nullptr ? nullptr : tmpT->isolate(); \
68 CHECK_ISOLATE(tmpI); \
69 if (tmpT->api_top_scope() == nullptr) { \
71 "%s expects to find a current scope. Did you forget to call " \
77#define DARTSCOPE(thread) \
78 Thread* T = (thread); \
80 TransitionNativeToVM transition(T); \
83#define RETURN_TYPE_ERROR(zone, dart_handle, type) \
86 Object::Handle(zone, Api::UnwrapHandle((dart_handle))); \
88 return Api::NewArgumentError("%s expects argument '%s' to be non-null.", \
89 CURRENT_FUNC, #dart_handle); \
90 } else if (tmp.IsError()) { \
93 return Api::NewArgumentError("%s expects argument '%s' to be of type %s.", \
94 CURRENT_FUNC, #dart_handle, #type); \
97#define RETURN_NULL_ERROR(parameter) \
98 return Api::NewError("%s expects argument '%s' to be non-null.", \
99 CURRENT_FUNC, #parameter)
101#define CHECK_NULL(parameter) \
102 if (parameter == nullptr) { \
103 RETURN_NULL_ERROR(parameter); \
106#define CHECK_LENGTH(length, max_elements) \
108 intptr_t len = (length); \
109 intptr_t max = (max_elements); \
110 if (len < 0 || len > max) { \
111 return Api::NewError( \
112 "%s expects argument '%s' to be in the range [0..%" Pd "].", \
113 CURRENT_FUNC, #length, max); \
117#ifdef SUPPORT_TIMELINE
118#define API_TIMELINE_DURATION(thread) \
119 TimelineBeginEndScope api_tbes(thread, Timeline::GetAPIStream(), CURRENT_FUNC)
121#define API_TIMELINE_BEGIN_END(thread) \
122 TimelineBeginEndScope api_tbes(thread, Timeline::GetAPIStream(), CURRENT_FUNC)
125#define API_TIMELINE_DURATION(thread) \
128#define API_TIMELINE_BEGIN_END(thread) \
144 DISALLOW_COPY_AND_ASSIGN(
Scope);
155#define DECLARE_UNWRAP(Type) \
156 static const Type& Unwrap##Type##Handle(Zone* zone, Dart_Handle object);
162 const ReusableObjectHandleScope& reused,
165 const ReusableObjectHandleScope& reused,
188 return !raw->IsHeapObject();
214 if (!raw->IsHeapObject()) {
242 return unwind_in_progress_error_handle_;
246 if (
object ==
nullptr)
return false;
247 return (
object == true_handle_) || (
object == false_handle_) ||
248 (
object == null_handle_) || (
object == empty_string_handle_) ||
249 (
object == no_callbacks_error_handle_) ||
250 (
object == unwind_in_progress_error_handle_);
292 intptr_t* field_values);
317 static StringPtr CallEnvironmentCallback(
Thread* thread,
const String&
name);
327 static Dart_Handle unwind_in_progress_error_handle_;
333#define START_NO_CALLBACK_SCOPE(thread) thread->IncrementNoCallbackScopeDepth()
336#define END_NO_CALLBACK_SCOPE(thread) \
338 thread->DecrementNoCallbackScopeDepth(); \
339 if (thread->no_callback_scope_depth() == 0) { \
340 thread->heap()->CheckExternalGC(thread); \
344#define CHECK_CALLBACK_STATE(thread) \
345 if (thread->no_callback_scope_depth() != 0) { \
346 return reinterpret_cast<Dart_Handle>(Api::NoCallbacksError()); \
348 if (thread->is_unwind_in_progress()) { \
349 return reinterpret_cast<Dart_Handle>(Api::UnwindInProgressError()); \
352#define ASSERT_CALLBACK_STATE(thread) \
353 ASSERT(thread->no_callback_scope_depth() == 0)
355class IsolateGroupSource;
#define CLASS_LIST_FOR_HANDLES(V)
static Dart_Handle Success()
static void SetDoubleReturnValue(NativeArguments *args, double retval)
static bool IsInstance(Dart_Handle handle)
static Dart_Handle NewHandle(Thread *thread, ObjectPtr raw)
static void SetReturnValue(NativeArguments *args, Dart_Handle retval)
static Dart_Handle UnwindInProgressError()
static bool GetNativeFieldsOfArgument(NativeArguments *args, int arg_index, int num_fields, intptr_t *field_values)
static Dart_Isolate CastIsolate(Isolate *isolate)
static ApiLocalScope * TopScope(Thread *thread)
static ObjectPtr UnwrapHandle(Dart_Handle object)
static bool GetNativeBooleanArgument(NativeArguments *args, int arg_index, bool *value)
static StringPtr GetEnvironmentValue(Thread *thread, const String &name)
static Dart_Handle False()
static intptr_t ClassId(Dart_Handle handle)
static Dart_Handle static Dart_Handle NewArgumentError(const char *format,...) PRINTF_ATTRIBUTE(1
static Dart_IsolateGroup CastIsolateGroup(IsolateGroup *isolate_group)
static bool StringGetPeerHelper(NativeArguments *args, int arg_index, void **peer)
static Dart_Handle static Dart_Handle static Dart_Handle Null()
static void InitHandles()
static bool GetNativeDoubleArgument(NativeArguments *args, int arg_index, double *value)
static const Instance & UnwrapInstanceHandle(const ReusableObjectHandleScope &reused, Dart_Handle object)
static bool IsFfiEnabled()
static Dart_Handle EmptyString()
static bool IsProtectedHandle(Dart_Handle object)
static bool GetNativeIntegerArgument(NativeArguments *args, int arg_index, int64_t *value)
static const String & UnwrapStringHandle(const ReusableObjectHandleScope &reused, Dart_Handle object)
static void SetWeakHandleReturnValue(NativeArguments *args, Dart_WeakPersistentHandle retval)
static void SetSmiReturnValue(NativeArguments *args, intptr_t retval)
static Dart_Handle True()
static bool IsValid(Dart_Handle handle)
static intptr_t SmiValue(Dart_Handle handle)
static bool GetNativeReceiver(NativeArguments *args, intptr_t *value)
static bool IsSmi(Dart_Handle handle)
static Dart_Handle NoCallbacksError()
static void SetIntegerReturnValue(NativeArguments *args, int64_t retval)
static bool IsError(Dart_Handle handle)
static Dart_Handle NewError(const char *format,...) PRINTF_ATTRIBUTE(1
static Dart_Handle CheckAndFinalizePendingClasses(Thread *thread)
static DoublePtr New(double d, Heap::Space space=Heap::kNew)
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
intptr_t GetClassId() const
static SmiPtr New(intptr_t value)
struct _Dart_Handle * Dart_Handle
struct _Dart_Isolate * Dart_Isolate
struct _Dart_IsolateGroup * Dart_IsolateGroup
struct _Dart_WeakPersistentHandle * Dart_WeakPersistentHandle
#define DECLARE_UNWRAP(Type)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
const char * CanonicalFunction(const char *func)
bool IsErrorClassId(intptr_t index)
pthread_key_t ThreadLocalKey
bool IsInternalOnlyClassId(intptr_t index)
Isolate * CreateWithinExistingIsolateGroup(IsolateGroup *group, const char *name, char **error)