Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
tonic::DartPersistentValue Class Reference

#include <dart_persistent_value.h>

Public Member Functions

 DartPersistentValue ()
 
 DartPersistentValue (DartPersistentValue &&other)
 
 DartPersistentValue (DartState *dart_state, Dart_Handle value)
 
 ~DartPersistentValue ()
 
Dart_PersistentHandle value () const
 
bool is_empty () const
 
void Set (DartState *dart_state, Dart_Handle value)
 
void Clear ()
 
Dart_Handle Get ()
 
Dart_Handle Release ()
 
const std::weak_ptr< DartState > & dart_state () const
 

Detailed Description

Definition at line 20 of file dart_persistent_value.h.

Constructor & Destructor Documentation

◆ DartPersistentValue() [1/3]

tonic::DartPersistentValue::DartPersistentValue ( )

Definition at line 12 of file dart_persistent_value.cc.

12: value_(nullptr) {}

◆ DartPersistentValue() [2/3]

tonic::DartPersistentValue::DartPersistentValue ( DartPersistentValue &&  other)

Definition at line 14 of file dart_persistent_value.cc.

15 : dart_state_(other.dart_state_), value_(other.value_) {
16 other.dart_state_.reset();
17 other.value_ = nullptr;
18}

◆ DartPersistentValue() [3/3]

tonic::DartPersistentValue::DartPersistentValue ( DartState dart_state,
Dart_Handle  value 
)

Definition at line 20 of file dart_persistent_value.cc.

22 : value_(nullptr) {
24}
void Set(DartState *dart_state, Dart_Handle value)
const std::weak_ptr< DartState > & dart_state() const
Dart_PersistentHandle value() const

◆ ~DartPersistentValue()

tonic::DartPersistentValue::~DartPersistentValue ( )

Definition at line 26 of file dart_persistent_value.cc.

Member Function Documentation

◆ Clear()

void tonic::DartPersistentValue::Clear ( )

TODO(80155): Remove the handle even if the isolate is shutting down. This may cause memory to stick around until the isolate group is destroyed. Without this branch, if DartState::IsShuttingDown == true, this code will crash when binding the isolate.

Definition at line 36 of file dart_persistent_value.cc.

36 {
37 if (!value_) {
38 return;
39 }
40
41 auto dart_state = dart_state_.lock();
42 if (!dart_state) {
43 // The Dart isolate was collected and the persistent value has been
44 // collected with it. value_ is a dangling reference.
45 value_ = nullptr;
46 return;
47 }
48
49 /// TODO(80155): Remove the handle even if the isolate is shutting down. This
50 /// may cause memory to stick around until the isolate group is destroyed.
51 /// Without this branch, if DartState::IsShuttingDown == true, this code will
52 /// crash when binding the isolate.
53 if (!dart_state->IsShuttingDown()) {
56 } else {
57 DartIsolateScope scope(dart_state->isolate());
59 }
60 }
61
62 dart_state_.reset();
63 value_ = nullptr;
64}
DART_EXPORT Dart_IsolateGroup Dart_CurrentIsolateGroup(void)
DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object)

◆ dart_state()

const std::weak_ptr< DartState > & tonic::DartPersistentValue::dart_state ( ) const
inline

Definition at line 35 of file dart_persistent_value.h.

35{ return dart_state_; }

◆ Get()

Dart_Handle tonic::DartPersistentValue::Get ( )

Definition at line 66 of file dart_persistent_value.cc.

66 {
67 if (!value_)
68 return nullptr;
69 return Dart_HandleFromPersistent(value_);
70}
DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object)

◆ is_empty()

bool tonic::DartPersistentValue::is_empty ( ) const
inline

Definition at line 28 of file dart_persistent_value.h.

28{ return !value_; }

◆ Release()

Dart_Handle tonic::DartPersistentValue::Release ( )

Definition at line 72 of file dart_persistent_value.cc.

72 {
74 Clear();
75 return local;
76}
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258

◆ Set()

void tonic::DartPersistentValue::Set ( DartState dart_state,
Dart_Handle  value 
)

Definition at line 30 of file dart_persistent_value.cc.

30 {
32 dart_state_ = dart_state->GetWeakPtr();
34}
DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object)
#define TONIC_DCHECK
Definition: macros.h:32

◆ value()

Dart_PersistentHandle tonic::DartPersistentValue::value ( ) const
inline

Definition at line 27 of file dart_persistent_value.h.

27{ return value_; }

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