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::WeakCallback
);
16 CallbackHolderBase::~CallbackHolderBase() {
17 DCHECK(v8_ref_
.IsEmpty());
20 v8::Handle
<v8::External
> CallbackHolderBase::GetHandle(v8::Isolate
* isolate
) {
21 return v8::Local
<v8::External
>::New(isolate
, v8_ref_
);
25 void CallbackHolderBase::WeakCallback(
26 const v8::WeakCallbackData
<v8::External
, CallbackHolderBase
>& data
) {
27 data
.GetParameter()->v8_ref_
.Reset();
28 delete data
.GetParameter();
31 } // namespace internal