Flutter Engine
The Flutter Engine
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
6
7#include "tonic/dart_state.h"
9
10namespace tonic {
11
13
15 : dart_state_(other.dart_state_), value_(other.value_) {
16 other.dart_state_.reset();
17 other.value_ = nullptr;
18}
19
22 : value_(nullptr) {
24}
25
27 Clear();
28}
29
32 dart_state_ = dart_state->GetWeakPtr();
34}
35
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}
65
67 if (!value_)
68 return nullptr;
69 return Dart_HandleFromPersistent(value_);
70}
71
74 Clear();
75 return local;
76}
77} // namespace tonic
void Set(DartState *dart_state, Dart_Handle value)
const std::weak_ptr< DartState > & dart_state() const
Dart_PersistentHandle value() const
DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object)
DART_EXPORT Dart_IsolateGroup Dart_CurrentIsolateGroup(void)
DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object)
uint8_t value
#define TONIC_DCHECK
Definition: macros.h:32