electron/native_mate/function_template.cc

41 lines
1.1 KiB
C++
Raw Normal View History

2014-04-15 03:04:36 +00:00
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#include "native_mate/function_template.h"
namespace mate {
namespace internal {
CallbackHolderBase::CallbackHolderBase(v8::Isolate* isolate)
2016-07-04 06:07:50 +00:00
: v8_ref_(isolate, v8::External::New(isolate, this)) {
v8_ref_.SetWeak(this, &CallbackHolderBase::FirstWeakCallback,
v8::WeakCallbackType::kParameter);
2014-04-15 03:04:36 +00:00
}
CallbackHolderBase::~CallbackHolderBase() {
DCHECK(v8_ref_.IsEmpty());
}
2015-05-22 11:11:02 +00:00
v8::Local<v8::External> CallbackHolderBase::GetHandle(v8::Isolate* isolate) {
2016-07-04 06:07:50 +00:00
return v8::Local<v8::External>::New(isolate, v8_ref_);
2014-04-15 03:04:36 +00:00
}
// static
2016-07-04 06:07:50 +00:00
void CallbackHolderBase::FirstWeakCallback(
const v8::WeakCallbackInfo<CallbackHolderBase>& data) {
data.GetParameter()->v8_ref_.Reset();
data.SetSecondPassCallback(SecondWeakCallback);
}
// static
void CallbackHolderBase::SecondWeakCallback(
const v8::WeakCallbackInfo<CallbackHolderBase>& data) {
delete data.GetParameter();
2014-04-15 03:04:36 +00:00
}
} // namespace internal
} // namespace mate