Flutter Engine
The Flutter Engine
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
6
7#include "tonic/dart_state.h"
9
10namespace tonic {
11
13
15 Clear();
16}
17
19 Dart_Handle object,
20 void* peer,
21 intptr_t external_allocation_size,
24 dart_state_ = dart_state->GetWeakPtr();
25 handle_ = Dart_NewWeakPersistentHandle(object, peer, external_allocation_size,
26 callback);
27}
28
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()) {
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());
52 }
53 }
54 // If it's shutting down, the handle will be deleted already.
55
56 dart_state_.reset();
57 handle_ = nullptr;
58}
59
61 auto dart_state = dart_state_.lock();
63 TONIC_DCHECK(!dart_state->IsShuttingDown());
64 if (!handle_) {
65 return nullptr;
66 }
67 return Dart_HandleFromWeakPersistent(handle_);
68}
69
70} // namespace tonic
const std::weak_ptr< DartState > & dart_state() const
void Set(DartState *dart_state, Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
void(* Dart_HandleFinalizer)(void *isolate_callback_data, void *peer)
Definition: dart_api.h:265
DART_EXPORT void Dart_DeleteWeakPersistentHandle(Dart_WeakPersistentHandle object)
DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
DART_EXPORT Dart_IsolateGroup Dart_CurrentIsolateGroup(void)
DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
fuchsia::ui::composition::ParentViewportWatcherHandle handle_
#define TONIC_DCHECK
Definition: macros.h:32