1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef SRC_BASE_OBJECT_INL_H_
23 #define SRC_BASE_OBJECT_INL_H_
25 #include "base-object.h"
34 inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
35 : handle_(env->isolate(), handle),
37 assert(!handle.IsEmpty());
41 inline BaseObject::~BaseObject() {
42 assert(handle_.IsEmpty());
46 inline v8::Persistent<v8::Object>& BaseObject::persistent() {
51 inline v8::Local<v8::Object> BaseObject::object() {
52 return PersistentToLocal(env_->isolate(), handle_);
56 inline Environment* BaseObject::env() const {
61 template <typename Type>
62 inline void BaseObject::WeakCallback(
63 const v8::WeakCallbackData<v8::Object, Type>& data) {
64 Type* self = data.GetParameter();
65 self->persistent().Reset();
70 template <typename Type>
71 inline void BaseObject::MakeWeak(Type* ptr) {
72 v8::HandleScope scope(env_->isolate());
73 v8::Local<v8::Object> handle = object();
74 assert(handle->InternalFieldCount() > 0);
75 Wrap<Type>(handle, ptr);
76 handle_.MarkIndependent();
77 handle_.SetWeak<Type>(ptr, WeakCallback<Type>);
81 inline void BaseObject::ClearWeak() {
87 #endif // SRC_BASE_OBJECT_INL_H_