Flutter Engine
 
Loading...
Searching...
No Matches
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

References dart_state(), Set(), and value().

◆ ~DartPersistentValue()

tonic::DartPersistentValue::~DartPersistentValue ( )

Definition at line 26 of file dart_persistent_value.cc.

References Clear().

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()) {
54 if (Dart_CurrentIsolateGroup()) {
55 Dart_DeletePersistentHandle(value_);
56 } else {
57 DartIsolateScope scope(dart_state->isolate());
58 Dart_DeletePersistentHandle(value_);
59 }
60 }
61
62 dart_state_.reset();
63 value_ = nullptr;
64}

References dart_state().

Referenced by Release(), tonic::DartState::SetIsolate(), flutter::testing::TEST_F(), and ~DartPersistentValue().

◆ dart_state()

◆ Get()

◆ is_empty()

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

Definition at line 28 of file dart_persistent_value.h.

28{ return !value_; }

Referenced by Set(), and flutter::PlatformMessageResponseDart::~PlatformMessageResponseDart().

◆ Release()

Dart_Handle tonic::DartPersistentValue::Release ( )

Definition at line 72 of file dart_persistent_value.cc.

72 {
73 Dart_Handle local = Get();
74 Clear();
75 return local;
76}

References Clear(), and Get().

◆ Set()

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

◆ value()

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

Definition at line 27 of file dart_persistent_value.h.

27{ return value_; }

Referenced by DartPersistentValue(), tonic::DartClassProvider::GetClassByName(), and Set().


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