Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
tonic
dart_persistent_value.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
5
#include "
tonic/dart_persistent_value.h
"
6
7
#include "
tonic/dart_state.h
"
8
#include "
tonic/scopes/dart_isolate_scope.h
"
9
10
namespace
tonic
{
11
12
DartPersistentValue::DartPersistentValue
() : value_(nullptr) {}
13
14
DartPersistentValue::DartPersistentValue
(
DartPersistentValue
&& other)
15
: dart_state_(other.dart_state_), value_(other.value_) {
16
other.dart_state_.reset();
17
other.value_ =
nullptr
;
18
}
19
20
DartPersistentValue::DartPersistentValue
(
DartState
* dart_state,
21
Dart_Handle
value)
22
: value_(nullptr) {
23
Set
(
dart_state
,
value
);
24
}
25
26
DartPersistentValue::~DartPersistentValue
() {
27
Clear
();
28
}
29
30
void
DartPersistentValue::Set
(
DartState
* dart_state,
Dart_Handle
value) {
31
TONIC_DCHECK
(
is_empty
());
32
dart_state_ =
dart_state
->GetWeakPtr();
33
value_ =
Dart_NewPersistentHandle
(
value
);
34
}
35
36
void
DartPersistentValue::Clear
() {
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
}
65
66
Dart_Handle
DartPersistentValue::Get
() {
67
if
(!value_)
68
return
nullptr
;
69
return
Dart_HandleFromPersistent
(value_);
70
}
71
72
Dart_Handle
DartPersistentValue::Release
() {
73
Dart_Handle
local =
Get
();
74
Clear
();
75
return
local;
76
}
77
}
// namespace tonic
tonic::DartIsolateScope
Definition
dart_isolate_scope.h:14
tonic::DartPersistentValue
Definition
dart_persistent_value.h:20
tonic::DartPersistentValue::~DartPersistentValue
~DartPersistentValue()
Definition
dart_persistent_value.cc:26
tonic::DartPersistentValue::Set
void Set(DartState *dart_state, Dart_Handle value)
Definition
dart_persistent_value.cc:30
tonic::DartPersistentValue::Get
Dart_Handle Get()
Definition
dart_persistent_value.cc:66
tonic::DartPersistentValue::dart_state
const std::weak_ptr< DartState > & dart_state() const
Definition
dart_persistent_value.h:35
tonic::DartPersistentValue::DartPersistentValue
DartPersistentValue()
Definition
dart_persistent_value.cc:12
tonic::DartPersistentValue::Clear
void Clear()
Definition
dart_persistent_value.cc:36
tonic::DartPersistentValue::Release
Dart_Handle Release()
Definition
dart_persistent_value.cc:72
tonic::DartPersistentValue::is_empty
bool is_empty() const
Definition
dart_persistent_value.h:28
tonic::DartPersistentValue::value
Dart_PersistentHandle value() const
Definition
dart_persistent_value.h:27
tonic::DartState
Definition
dart_state.h:28
Dart_HandleFromPersistent
DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object)
Dart_Handle
struct _Dart_Handle * Dart_Handle
Definition
dart_api.h:258
Dart_NewPersistentHandle
DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object)
Dart_CurrentIsolateGroup
DART_EXPORT Dart_IsolateGroup Dart_CurrentIsolateGroup(void)
Dart_DeletePersistentHandle
DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object)
dart_isolate_scope.h
dart_persistent_value.h
dart_state.h
tonic
Definition
image_filter.h:14
TONIC_DCHECK
#define TONIC_DCHECK
Definition
macros.h:32
Generated on Fri Apr 26 2024 06:18:16 for Flutter Engine by
1.9.8