1 // Copyright 2013 The Chromium 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.
5 #include "gin/function_template.h"
11 CallbackHolderBase::CallbackHolderBase(v8::Isolate
* isolate
)
12 : v8_ref_(isolate
, v8::External::New(isolate
, this)) {
13 v8_ref_
.SetWeak(this, &CallbackHolderBase::FirstWeakCallback
,
14 v8::WeakCallbackType::kParameter
);
17 CallbackHolderBase::~CallbackHolderBase() {
18 DCHECK(v8_ref_
.IsEmpty());
21 v8::Local
<v8::External
> CallbackHolderBase::GetHandle(v8::Isolate
* isolate
) {
22 return v8::Local
<v8::External
>::New(isolate
, v8_ref_
);
26 void CallbackHolderBase::FirstWeakCallback(
27 const v8::WeakCallbackInfo
<CallbackHolderBase
>& data
) {
28 data
.GetParameter()->v8_ref_
.Reset();
29 data
.SetSecondPassCallback(SecondWeakCallback
);
33 void CallbackHolderBase::SecondWeakCallback(
34 const v8::WeakCallbackInfo
<CallbackHolderBase
>& data
) {
35 delete data
.GetParameter();
38 } // namespace internal