Making callbacks be received in the right order
[chromium-blink-merge.git] / gin / function_template.cc
blob46285f9206842d7e6ceb741d3a679515076a1f3a
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"
7 namespace gin {
9 namespace internal {
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_);
25 // static
26 void CallbackHolderBase::FirstWeakCallback(
27 const v8::WeakCallbackInfo<CallbackHolderBase>& data) {
28 data.GetParameter()->v8_ref_.Reset();
29 data.SetSecondPassCallback(SecondWeakCallback);
32 // static
33 void CallbackHolderBase::SecondWeakCallback(
34 const v8::WeakCallbackInfo<CallbackHolderBase>& data) {
35 delete data.GetParameter();
38 } // namespace internal
40 } // namespace gin