#ifndef SRC_NODE_PERSISTENT_H_ #define SRC_NODE_PERSISTENT_H_ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "v8.h" namespace node { template struct ResetInDestructorPersistentTraits { static const bool kResetInDestructor = true; template // Disallow copy semantics by leaving this unimplemented. inline static void Copy( const v8::Persistent&, v8::Persistent>*); }; // v8::Persistent does not reset the object slot in its destructor. That is // acknowledged as a flaw in the V8 API and expected to change in the future // but for now node::Persistent is the easier and safer alternative. template using Persistent = v8::Persistent>; class PersistentToLocal { public: // If persistent.IsWeak() == false, then do not call persistent.Reset() // while the returned Local is still in scope, it will destroy the // reference to the object. template static inline v8::Local Default( v8::Isolate* isolate, const Persistent& persistent) { if (persistent.IsWeak()) { return PersistentToLocal::Weak(isolate, persistent); } else { return PersistentToLocal::Strong(persistent); } } // Unchecked conversion from a non-weak Persistent to Local, // use with care! // // Do not call persistent.Reset() while the returned Local is still in // scope, it will destroy the reference to the object. template static inline v8::Local Strong( const Persistent& persistent) { return *reinterpret_cast*>( const_cast*>(&persistent)); } template static inline v8::Local Weak( v8::Isolate* isolate, const Persistent& persistent) { return v8::Local::New(isolate, persistent); } }; } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_PERSISTENT_H_