GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/out/../src/handle_wrap.h Lines: 3 3 100.0 %
Date: 2016-11-30 Branches: 13 20 65.0 %

Line Branch Exec Source
1
#ifndef SRC_HANDLE_WRAP_H_
2
#define SRC_HANDLE_WRAP_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "async-wrap.h"
7
#include "util.h"
8
#include "uv.h"
9
#include "v8.h"
10
11
namespace node {
12
13
class Environment;
14
15
// Rules:
16
//
17
// - Do not throw from handle methods. Set errno.
18
//
19
// - MakeCallback may only be made directly off the event loop.
20
//   That is there can be no JavaScript stack frames underneath it.
21
//   (Is there any way to assert that?)
22
//
23
// - No use of v8::WeakReferenceCallback. The close callback signifies that
24
//   we're done with a handle - external resources can be freed.
25
//
26
// - Reusable?
27
//
28
// - The uv_close_cb is used to free the c++ object. The close callback
29
//   is not made into javascript land.
30
//
31
// - uv_ref, uv_unref counts are managed at this layer to avoid needless
32
//   js/c++ boundary crossing. At the javascript layer that should all be
33
//   taken care of.
34
35
class HandleWrap : public AsyncWrap {
36
 public:
37
  static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
38
  static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
39
  static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
40
  static void HasRef(const v8::FunctionCallbackInfo<v8::Value>& args);
41
42
  static inline bool IsAlive(const HandleWrap* wrap) {
43




51455
    return wrap != nullptr && wrap->state_ != kClosed;
44
  }
45
46
46
  static inline bool HasRef(const HandleWrap* wrap) {
47

46
    return IsAlive(wrap) && uv_has_ref(wrap->GetHandle());
48
  }
49
50
  inline uv_handle_t* GetHandle() const { return handle_; }
51
52
 protected:
53
  HandleWrap(Environment* env,
54
             v8::Local<v8::Object> object,
55
             uv_handle_t* handle,
56
             AsyncWrap::ProviderType provider,
57
             AsyncWrap* parent = nullptr);
58
  ~HandleWrap() override;
59
60
 private:
61
  friend class Environment;
62
  friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
63
  static void OnClose(uv_handle_t* handle);
64
  ListNode<HandleWrap> handle_wrap_queue_;
65
  enum { kInitialized, kClosing, kClosingWithCallback, kClosed } state_;
66
  uv_handle_t* const handle_;
67
};
68
69
70
}  // namespace node
71
72
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
73
74
#endif  // SRC_HANDLE_WRAP_H_