V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
managed.cc
1 // Copyright 2018 the V8 project 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 "src/objects/managed.h"
6 
7 namespace v8 {
8 namespace internal {
9 
10 namespace {
11 // Called by the GC in its second pass when a Managed<CppType> is
12 // garbage collected.
13 void ManagedObjectFinalizerSecondPass(const v8::WeakCallbackInfo<void>& data) {
14  auto destructor =
15  reinterpret_cast<ManagedPtrDestructor*>(data.GetParameter());
16  Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
17  isolate->UnregisterManagedPtrDestructor(destructor);
18  int64_t adjustment = 0 - static_cast<int64_t>(destructor->estimated_size_);
19  destructor->destructor_(destructor->shared_ptr_ptr_);
20  delete destructor;
21  data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory(adjustment);
22 }
23 } // namespace
24 
25 // Called by the GC in its first pass when a Managed<CppType> is
26 // garbage collected.
27 void ManagedObjectFinalizer(const v8::WeakCallbackInfo<void>& data) {
28  auto destructor =
29  reinterpret_cast<ManagedPtrDestructor*>(data.GetParameter());
30  GlobalHandles::Destroy(destructor->global_handle_location_);
31  // We need to do the main work as a second pass callback because
32  // it can trigger garbage collection. The first pass callbacks
33  // are not allowed to invoke V8 API.
34  data.SetSecondPassCallback(&ManagedObjectFinalizerSecondPass);
35 }
36 
37 } // namespace internal
38 } // namespace v8
Definition: libplatform.h:13