Flutter Engine
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.

References Set().

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

◆ ~DartPersistentValue()

tonic::DartPersistentValue::~DartPersistentValue ( )

Definition at line 26 of file dart_persistent_value.cc.

References Clear().

26  {
27  Clear();
28 }

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.

References dart_state().

Referenced by is_empty(), Release(), tonic::DartState::SetIsolate(), and ~DartPersistentValue().

36  {
37  if (!value_) {
38  return;
39  }
40 
41  auto dart_state = dart_state_.lock();
42  if (!dart_state) {
43  return;
44  }
45 
46  /// TODO(80155): Remove the handle even if the isolate is shutting down. This
47  /// may cause memory to stick around until the isolate group is destroyed.
48  /// Without this branch, if DartState::IsShuttingDown == true, this code will
49  /// crash when binding the isolate.
50  if (!dart_state->IsShuttingDown()) {
51  if (Dart_CurrentIsolateGroup()) {
52  Dart_DeletePersistentHandle(value_);
53  } else {
54  DartIsolateScope scope(dart_state->isolate());
55  Dart_DeletePersistentHandle(value_);
56  }
57  }
58 
59  dart_state_.reset();
60  value_ = nullptr;
61 }
const std::weak_ptr< DartState > & dart_state() const

◆ dart_state()

◆ Get()

◆ is_empty()

◆ Release()

Dart_Handle tonic::DartPersistentValue::Release ( )

Definition at line 69 of file dart_persistent_value.cc.

References Clear(), and Get().

Referenced by zircon::dart::HandleWaiter::Cancel(), and is_empty().

69  {
70  Dart_Handle local = Get();
71  Clear();
72  return local;
73 }

◆ Set()

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

Definition at line 30 of file dart_persistent_value.cc.

References tonic::DartState::GetWeakPtr(), is_empty(), and TONIC_DCHECK.

Referenced by tonic::DartClassProvider::DartClassProvider(), DartPersistentValue(), flutter::PlatformConfiguration::DidCreateIsolate(), is_empty(), tonic::DartState::SetIsolate(), and flutter::Window::Window().

30  {
32  dart_state_ = dart_state->GetWeakPtr();
33  value_ = Dart_NewPersistentHandle(value);
34 }
#define TONIC_DCHECK
Definition: macros.h:32
Dart_PersistentHandle value() const
const std::weak_ptr< DartState > & dart_state() const

◆ value()

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

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