Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dart_wrappable.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
8#include "tonic/dart_state.h"
11
12namespace tonic {
13
15 // Calls the destructor of dart_wrapper_ to delete WeakPersistentHandle.
16}
17
18// TODO(dnfield): Delete this. https://github.com/flutter/flutter/issues/50997
20 if (!dart_wrapper_.is_empty()) {
21 // Any previously given out wrapper must have been GCed.
22 TONIC_DCHECK(Dart_IsNull(dart_wrapper_.Get()));
23 dart_wrapper_.Clear();
24 }
25
27
30
31 Dart_Handle wrapper =
32 Dart_New(type, dart_state->private_constructor_name(), 0, nullptr);
33
35
37 wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this));
39
40 this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper.
41 dart_wrapper_.Set(dart_state, wrapper, this, sizeof(*this),
42 &FinalizeDartWrapper);
43
44 return wrapper;
45}
46
48 if (!dart_wrapper_.is_empty()) {
49 // Any previously given out wrapper must have been GCed.
50 TONIC_DCHECK(Dart_IsNull(dart_wrapper_.Get()));
51 dart_wrapper_.Clear();
52 }
53
55
57 wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this))));
58
59 this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper.
60
61 DartState* dart_state = DartState::Current();
62 dart_wrapper_.Set(dart_state, wrapper, this, sizeof(*this),
63 &FinalizeDartWrapper);
64}
65
67 TONIC_DCHECK(!dart_wrapper_.is_empty());
68 Dart_Handle wrapper = dart_wrapper_.Get();
71 dart_wrapper_.Clear();
73}
74
75void DartWrappable::FinalizeDartWrapper(void* isolate_callback_data,
76 void* peer) {
77 DartWrappable* wrappable = reinterpret_cast<DartWrappable*>(peer);
78 wrappable->ReleaseDartWrappableReference(); // Balanced in CreateDartWrapper.
79}
80
82 tonic::DartState* dart_state,
83 const tonic::DartWrapperInfo& wrapper_info) {
84 return dart_state->class_library().GetClass(wrapper_info);
85}
86
88 if (Dart_IsNull(handle)) {
89 return nullptr;
90 }
91 intptr_t peer = 0;
95 return nullptr;
96 return reinterpret_cast<DartWrappable*>(peer);
97}
98
100 int index,
101 Dart_Handle& exception) {
102 intptr_t native_fields[DartWrappable::kNumberOfNativeFields];
104 args, index, DartWrappable::kNumberOfNativeFields, native_fields);
105 if (Dart_IsError(result)) {
107 return nullptr;
108 }
109 if (!native_fields[DartWrappable::kPeerIndex])
110 return nullptr;
111 return reinterpret_cast<DartWrappable*>(
112 native_fields[DartWrappable::kPeerIndex]);
113}
114
115} // namespace tonic
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
Dart_PersistentHandle GetClass(const DartWrapperInfo &info)
static DartState * Current()
Definition dart_state.cc:56
Dart_PersistentHandle private_constructor_name()
Definition dart_state.h:56
DartClassLibrary & class_library()
Definition dart_state.h:60
void Set(DartState *dart_state, Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
Dart_Handle CreateDartWrapper(DartState *dart_state)
virtual const DartWrapperInfo & GetDartWrapperInfo() const =0
void AssociateWithDartWrapper(Dart_Handle wrappable)
virtual void ReleaseDartWrappableReference() const =0
virtual void RetainDartWrappableReference() const =0
static Dart_PersistentHandle GetTypeForWrapper(tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, int index, intptr_t *value)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
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_SetNativeInstanceField(Dart_Handle obj, int index, intptr_t value)
Dart_Handle Dart_PersistentHandle
Definition dart_api.h:259
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument(Dart_NativeArguments args, int arg_index, int num_fields, intptr_t *field_values)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
const char kInvalidArgument[]
Definition dart_error.cc:14
bool CheckAndHandleError(Dart_Handle handle)
Definition dart_error.cc:33
static DartWrappable * FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static DartWrappable * FromDart(Dart_Handle handle)
#define TONIC_CHECK(condition)
Definition macros.h:23
#define TONIC_DCHECK
Definition macros.h:32