Skip to content

Commit

Permalink
Enable creating Locals from Globals under Node 0.10.
Browse files Browse the repository at this point in the history
Fixes #470
  • Loading branch information
kkoopa committed Oct 8, 2015
1 parent eab6d82 commit 9bf9b8b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nan_implementation_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,9 @@ inline v8::Local<T> New(Persistent<T, M> const& p) {
return v8::Local<T>::New(v8::Isolate::GetCurrent(), p);
}

template <typename T>
inline v8::Local<T> New(Global<T> const& p) {
return v8::Local<T>::New(v8::Isolate::GetCurrent(), p);
}

#endif // NAN_IMPLEMENTATION_12_INL_H_
5 changes: 5 additions & 0 deletions nan_implementation_pre_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,9 @@ inline v8::Local<T> New(Persistent<T, M> const& p) {
return v8::Local<T>::New(p.persistent);
}

template <typename T>
inline v8::Local<T> New(Global<T> const& p) {
return v8::Local<T>::New(p.persistent);
}

#endif // NAN_IMPLEMENTATION_PRE_12_INL_H_
2 changes: 2 additions & 0 deletions nan_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ template <typename T> inline v8::Local<T> New(v8::Persistent<T> const& p);
#endif
template <typename T, typename M>
inline v8::Local<T> New(Persistent<T, M> const& p);
template <typename T>
inline v8::Local<T> New(Global<T> const& p);

inline
imp::Factory<v8::Boolean>::return_t
Expand Down
4 changes: 4 additions & 0 deletions nan_persistent_pre_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
template<typename T>
class PersistentBase {
v8::Persistent<T> persistent;
template<typename U>
friend v8::Local<U> New(const PersistentBase<U> &p);
template<typename U, typename M>
friend v8::Local<U> New(const Persistent<U, M> &p);
template<typename U>
friend v8::Local<U> New(const Global<U> &p);
template<typename S> friend class ReturnValue;

public:
Expand Down
14 changes: 14 additions & 0 deletions test/cpp/nannew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,19 @@ NAN_METHOD(testPersistents) {
info.GetReturnValue().SetUndefined();
}

NAN_METHOD(testGlobals) {
Tap t(info[0]);

t.plan(1);

Nan::Global<String> p;
p.Reset(New("foo").ToLocalChecked());
t.ok(_( assertType<String>( New(p))));
p.Reset();

info.GetReturnValue().SetUndefined();
}

//==============================================================================
// Regression Tests
//==============================================================================
Expand Down Expand Up @@ -473,6 +486,7 @@ NAN_MODULE_INIT(Init) {
NAN_EXPORT(target, testStringObject);

NAN_EXPORT(target, testPersistents);
NAN_EXPORT(target, testGlobals);

NAN_EXPORT(target, testRegression212);
NAN_EXPORT(target, testRegression242);
Expand Down

0 comments on commit 9bf9b8b

Please sign in to comment.