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 
10 namespace tonic {
11 
13 
15  : dart_state_(other.dart_state_), value_(other.value_) {
16  other.dart_state_.reset();
17  other.value_ = nullptr;
18 }
19 
21  Dart_Handle value)
22  : value_(nullptr) {
23  Set(dart_state, value);
24 }
25 
27  Clear();
28 }
29 
32  dart_state_ = dart_state->GetWeakPtr();
33  value_ = Dart_NewPersistentHandle(value);
34 }
35 
37  if (!value_) {
38  return;
39  }
40 
41  auto dart_state = dart_state_.lock();
42  if (!dart_state) {
43  return;
44  }
45 
46  if (Dart_CurrentIsolateGroup()) {
47  Dart_DeletePersistentHandle(value_);
48  } else {
49  DartIsolateScope scope(dart_state->isolate());
50  Dart_DeletePersistentHandle(value_);
51  }
52  dart_state_.reset();
53  value_ = nullptr;
54 }
55 
56 Dart_Handle DartPersistentValue::Get() {
57  if (!value_)
58  return nullptr;
59  return Dart_HandleFromPersistent(value_);
60 }
61 
63  Dart_Handle local = Get();
64  Clear();
65  return local;
66 }
67 } // namespace tonic
#define TONIC_DCHECK
Definition: macros.h:32
Dart_PersistentHandle value() const
void Set(DartState *dart_state, Dart_Handle value)
const std::weak_ptr< DartState > & dart_state() const
std::weak_ptr< DartState > GetWeakPtr()
Definition: dart_state.cc:61