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.
4
5#include "gin/function_template.h"
6
7namespace gin {
8
9namespace internal {
10
11CallbackHolderBase::CallbackHolderBase(v8::Isolate* isolate)
12    : v8_ref_(isolate, v8::External::New(isolate, this)) {
13  v8_ref_.SetWeak(this, &CallbackHolderBase::WeakCallback);
14}
15
16CallbackHolderBase::~CallbackHolderBase() {
17  DCHECK(v8_ref_.IsEmpty());
18}
19
20v8::Handle<v8::External> CallbackHolderBase::GetHandle(v8::Isolate* isolate) {
21  return v8::Local<v8::External>::New(isolate, v8_ref_);
22}
23
24// static
25void CallbackHolderBase::WeakCallback(
26    const v8::WeakCallbackData<v8::External, CallbackHolderBase>& data) {
27  data.GetParameter()->v8_ref_.Reset();
28  delete data.GetParameter();
29}
30
31}  // namespace internal
32
33}  // namespace gin
34