Flutter Engine
Loading...
Searching...
No Matches
dart_weak_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_weak_persistent_value.h
"
6
7
#include "
tonic/dart_state.h
"
8
#include "
tonic/scopes/dart_isolate_scope.h
"
9
10
namespace
tonic
{
11
12
DartWeakPersistentValue::DartWeakPersistentValue
() :
handle_
(nullptr) {}
13
14
DartWeakPersistentValue::~DartWeakPersistentValue
() {
15
Clear
();
16
}
17
18
void
DartWeakPersistentValue::Set
(
DartState
* dart_state,
19
Dart_Handle
object
,
20
void
* peer,
21
intptr_t external_allocation_size,
22
Dart_HandleFinalizer
callback
) {
23
TONIC_DCHECK
(
is_empty
());
24
dart_state_ =
dart_state
->GetWeakPtr();
25
handle_ = Dart_NewWeakPersistentHandle(
object
, peer, external_allocation_size,
26
callback
);
27
}
28
29
void
DartWeakPersistentValue::Clear
() {
30
if
(!handle_) {
31
return
;
32
}
33
34
auto
dart_state
= dart_state_.lock();
35
if
(!
dart_state
) {
36
// The DartVM that the handle used to belong to has been shut down and that
37
// handle has already been deleted.
38
handle_ =
nullptr
;
39
return
;
40
}
41
42
// The DartVM frees the handles during shutdown and calls the finalizers.
43
// Freeing handles during shutdown would fail.
44
if
(!
dart_state
->IsShuttingDown()) {
45
if
(Dart_CurrentIsolateGroup()) {
46
Dart_DeleteWeakPersistentHandle(handle_);
47
}
else
{
48
// If we are not on the mutator thread, this will fail. The caller must
49
// ensure to be on the mutator thread.
50
DartIsolateScope
scope(
dart_state
->isolate());
51
Dart_DeleteWeakPersistentHandle(handle_);
52
}
53
}
54
// If it's shutting down, the handle will be deleted already.
55
56
dart_state_.reset();
57
handle_ =
nullptr
;
58
}
59
60
Dart_Handle
DartWeakPersistentValue::Get
() {
61
auto
dart_state
= dart_state_.lock();
62
TONIC_DCHECK
(
dart_state
);
63
TONIC_DCHECK
(!
dart_state
->IsShuttingDown());
64
if
(!handle_) {
65
return
nullptr
;
66
}
67
return
Dart_HandleFromWeakPersistent(handle_);
68
}
69
70
}
// namespace tonic
tonic::DartIsolateScope
Definition
dart_isolate_scope.h:14
tonic::DartState
Definition
dart_state.h:28
tonic::DartWeakPersistentValue::dart_state
const std::weak_ptr< DartState > & dart_state() const
Definition
dart_weak_persistent_value.h:37
tonic::DartWeakPersistentValue::~DartWeakPersistentValue
~DartWeakPersistentValue()
Definition
dart_weak_persistent_value.cc:14
tonic::DartWeakPersistentValue::Clear
void Clear()
Definition
dart_weak_persistent_value.cc:29
tonic::DartWeakPersistentValue::Set
void Set(DartState *dart_state, Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
Definition
dart_weak_persistent_value.cc:18
tonic::DartWeakPersistentValue::Get
Dart_Handle Get()
Definition
dart_weak_persistent_value.cc:60
tonic::DartWeakPersistentValue::DartWeakPersistentValue
DartWeakPersistentValue()
Definition
dart_weak_persistent_value.cc:12
tonic::DartWeakPersistentValue::is_empty
bool is_empty() const
Definition
dart_weak_persistent_value.h:27
dart_isolate_scope.h
dart_state.h
dart_weak_persistent_value.h
callback
FlutterDesktopBinaryReply callback
Definition
flutter_windows_view_unittests.cc:52
tonic
Definition
image_filter.h:15
handle_
fuchsia::ui::composition::ParentViewportWatcherHandle handle_
Definition
platform_view_unittest.cc:334
TONIC_DCHECK
#define TONIC_DCHECK
Definition
macros.h:32
third_party
tonic
dart_weak_persistent_value.cc
Generated on Thu Nov 6 2025 16:11:30 for Flutter Engine by
1.9.8