electron/native_mate/function_template.cc

36 lines
995 B
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)
2014-06-28 14:32:35 +00:00
: MATE_PERSISTENT_INIT(isolate, v8_ref_, MATE_EXTERNAL_NEW(isolate, this)) {
2014-04-15 03:04:36 +00:00
MATE_PERSISTENT_SET_WEAK(v8_ref_, this, &CallbackHolderBase::WeakCallback);
}
CallbackHolderBase::~CallbackHolderBase() {
DCHECK(v8_ref_.IsEmpty());
}
2015-05-22 11:11:02 +00:00
v8::Local<v8::External> CallbackHolderBase::GetHandle(v8::Isolate* isolate) {
2014-04-15 03:04:36 +00:00
return MATE_PERSISTENT_TO_LOCAL(v8::External, isolate, v8_ref_);
}
// static
MATE_WEAK_CALLBACK(CallbackHolderBase::WeakCallback,
v8::External,
CallbackHolderBase) {
MATE_WEAK_CALLBACK_INIT(CallbackHolderBase);
MATE_PERSISTENT_RESET(self->v8_ref_);
delete self;
}
} // namespace internal
} // namespace mate