| 10 | #define NAN_OBJECT_WRAP_H_ |
| 11 | |
| 12 | class ObjectWrap { |
| 13 | public: |
| 14 | ObjectWrap() { |
| 15 | refs_ = 0; |
| 16 | } |
| 17 | |
| 18 | |
| 19 | virtual ~ObjectWrap() { |
| 20 | if (persistent().IsEmpty()) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | persistent().ClearWeak(); |
| 25 | persistent().Reset(); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | template <class T> |
| 30 | static inline T* Unwrap(v8::Local<v8::Object> object) { |
| 31 | assert(!object.IsEmpty()); |
| 32 | assert(object->InternalFieldCount() > 0); |
| 33 | // Cast to ObjectWrap before casting to T. A direct cast from void |
| 34 | // to T won't work right when T has more than one base class. |
| 35 | void* ptr = GetInternalFieldPointer(object, 0); |
| 36 | ObjectWrap* wrap = static_cast<ObjectWrap*>(ptr); |
| 37 | return static_cast<T*>(wrap); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | inline v8::Local<v8::Object> handle() const { |
| 42 | return New(handle_); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | inline Persistent<v8::Object>& persistent() { |
| 47 | return handle_; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | protected: |
| 52 | inline void Wrap(v8::Local<v8::Object> object) { |
| 53 | assert(persistent().IsEmpty()); |
| 54 | assert(object->InternalFieldCount() > 0); |
| 55 | SetInternalFieldPointer(object, 0, this); |
| 56 | persistent().Reset(object); |
| 57 | MakeWeak(); |
| 58 | } |
| 59 | |
| 60 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ |
| 61 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) |
| 62 | |
| 63 | inline void MakeWeak() { |
| 64 | persistent().v8::PersistentBase<v8::Object>::SetWeak( |
| 65 | this, WeakCallback, v8::WeakCallbackType::kParameter); |
| 66 | #if NODE_MAJOR_VERSION < 10 |
| 67 | // FIXME(bnoordhuis) Probably superfluous in older Node.js versions too. |
| 68 | persistent().MarkIndependent(); |
| 69 | #endif |
nothing calls this directly
no outgoing calls
no test coverage detected