Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion nan_callbacks_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ReturnValue {
value_.Set(handle);
#else
value_.Set(*reinterpret_cast<const v8::Persistent<S>*>(&handle));
const_cast<Global<S> &>(handle).Reset();
#endif
}

Expand Down
1 change: 0 additions & 1 deletion nan_callbacks_pre_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class ReturnValue {
TYPE_CHECK(T, S);
value_->Dispose();
*value_ = v8::Persistent<T>::New(handle.persistent);
const_cast<Global<S> &>(handle).Reset();
}

// Fast primitive setters
Expand Down
5 changes: 3 additions & 2 deletions nan_maybe_pre_43_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class MaybeLocal {

template<typename S>
# if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION
inline MaybeLocal(v8::Local<S> that) : val_(that) {}
inline MaybeLocal(v8::Local<S> that) : // NOLINT(runtime/explicit)
val_(that) {}
# else
inline MaybeLocal(v8::Local<S> that) :
inline MaybeLocal(v8::Local<S> that) : // NOLINT(runtime/explicit)
val_(*reinterpret_cast<v8::Local<T>*>(&that)) {}

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

# endif

Expand Down
57 changes: 47 additions & 10 deletions nan_persistent_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,31 @@ template<typename T, typename M> class Persistent :
public:
inline Persistent() : v8::Persistent<T, M>() {}

template<typename S> inline Persistent(v8::Local<S> that) :
template<typename S> inline explicit Persistent(v8::Local<S> that) :

This comment was marked as off-topic.

v8::Persistent<T, M>(v8::Isolate::GetCurrent(), that) {}

template<typename S, typename M2>
inline Persistent(const v8::Persistent<S, M2> &that) :
inline explicit Persistent(const v8::Persistent<S, M2> &that) :
v8::Persistent<T, M2>(v8::Isolate::GetCurrent(), that) {}

This comment was marked as off-topic.


inline void Reset() { v8::PersistentBase<T>::Reset(); }

template <typename S>
template<typename S>
inline void Reset(const v8::Local<S> &other) {
v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
}

template <typename S>
template<typename S>
inline void Reset(const v8::PersistentBase<S> &other) {
v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
}

#if NODE_MODULE_VERSION == NODE_0_12_MODULE_VERSION
inline void Empty() {
v8::Persistent<T, M>::ClearAndLeak();
}
#endif

template<typename P>
inline void SetWeak(
P *parameter
Expand Down Expand Up @@ -62,11 +68,11 @@ class Global : public v8::Global<T> {
public:
inline Global() : v8::Global<T>() {}

template<typename S> inline Global(v8::Local<S> that) :
template<typename S> inline explicit Global(v8::Local<S> that) :
v8::Global<T>(v8::Isolate::GetCurrent(), that) {}

template<typename S>
inline Global(const v8::PersistentBase<S> &that) :
inline explicit Global(const v8::PersistentBase<S> &that) :
v8::Global<S>(v8::Isolate::GetCurrent(), that) {}

inline void Reset() { v8::PersistentBase<T>::Reset(); }
Expand All @@ -81,6 +87,8 @@ class Global : public v8::Global<T> {
v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
}

Global Pass() { return static_cast<Global&&>(*this); } // NOLINT(build/c++11)

This comment was marked as off-topic.

This comment was marked as off-topic.


template<typename P>
inline void SetWeak(
P *parameter
Expand All @@ -93,28 +101,57 @@ class Global : public v8::Global<T> {
#else
template<typename T>
class Global : public v8::UniquePersistent<T> {
struct RValue {
inline explicit RValue(v8::UniquePersistent<T> *obj) : object_(obj) {}
v8::UniquePersistent<T> *object_;
};

public:
inline Global() : v8::UniquePersistent<T>() {}

template<typename S> inline Global(v8::Local<S> that) :
template<typename S> inline explicit Global(v8::Local<S> that) :
v8::UniquePersistent<T>(v8::Isolate::GetCurrent(), that) {}

template<typename S>
inline Global(const v8::PersistentBase<S> &that) :
inline explicit Global(const v8::PersistentBase<S> &that) :
v8::UniquePersistent<S>(v8::Isolate::GetCurrent(), that) {}

inline void Reset() { v8::PersistentBase<T>::Reset(); }

template <typename S>
template<typename S>
inline void Reset(const v8::Local<S> &other) {
v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
}

template <typename S>
template<typename S>
inline void Reset(const v8::PersistentBase<S> &other) {
v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
}

#if NODE_MODULE_VERSION == NODE_0_12_MODULE_VERSION
inline void Empty() {
reinterpret_cast<v8::Persistent<T>*>(this)->ClearAndLeak();

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

}
#endif

inline Global(RValue rvalue) { // NOLINT(runtime/explicit)
std::memcpy(this, rvalue.object_, sizeof (*rvalue.object_));
# if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION
rvalue.object_->Empty();
# else
reinterpret_cast<v8::Persistent<T>*>(rvalue.object_)->ClearAndLeak();
# endif
}

template<typename S>
inline Global &operator=(v8::UniquePersistent<S> other) {
return reinterpret_cast<Global>(v8::UniquePersistent<S>::operator=(other));
}

inline operator RValue() { return RValue(this); }

This comment was marked as off-topic.

This comment was marked as off-topic.


Global Pass() { return Global(RValue(this)); }

template<typename P>
inline void SetWeak(
P *parameter
Expand Down
19 changes: 11 additions & 8 deletions nan_persistent_pre_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,32 +196,35 @@ class Global : public PersistentBase<T> {
inline Global() : PersistentBase<T>(0) { }

template <typename S>
inline Global(v8::Local<S> that)
inline explicit Global(v8::Local<S> that)
: PersistentBase<T>(v8::Persistent<T>::New(that)) {
TYPE_CHECK(T, S);
}

template <typename S>
inline Global(const PersistentBase<S> &that)
: PersistentBase<T>(that) {
inline explicit Global(const PersistentBase<S> &that) :
PersistentBase<T>(that) {
TYPE_CHECK(T, S);
}
/**
* Move constructor.
*/
inline Global(RValue rvalue)
inline Global(RValue rvalue) // NOLINT(runtime/explicit)

This comment was marked as off-topic.

: PersistentBase<T>(rvalue.object->persistent) {
rvalue.object->Reset();
rvalue.object->Empty();
}
inline ~Global() { this->Reset(); }
/**
* Move via assignment.
*/
template<typename S>
inline Global &operator=(Global<S> rhs) {
inline Global &operator=(Global<S> other) {
TYPE_CHECK(T, S);
this->Reset(rhs.persistent);
rhs.Reset();
if (!this->persistent.IsEmpty()) {
this->persistent.Dispose();
}
this->persistent = other.persistent;
other.Empty();
return *this;
}
/**
Expand Down