GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/signal_wrap.cc Lines: 43 50 86.0 %
Date: 2019-03-02 22:23:06 Branches: 8 16 50.0 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#include "async_wrap-inl.h"
23
#include "env-inl.h"
24
#include "handle_wrap.h"
25
#include "node_process.h"
26
#include "util-inl.h"
27
#include "v8.h"
28
29
namespace node {
30
31
using v8::Context;
32
using v8::FunctionCallbackInfo;
33
using v8::FunctionTemplate;
34
using v8::HandleScope;
35
using v8::Integer;
36
using v8::Local;
37
using v8::Object;
38
using v8::String;
39
using v8::Value;
40
41
namespace {
42
43
118
class SignalWrap : public HandleWrap {
44
 public:
45
53
  static void Initialize(Local<Object> target,
46
                         Local<Value> unused,
47
                         Local<Context> context,
48
                         void* priv) {
49
53
    Environment* env = Environment::GetCurrent(context);
50
53
    Local<FunctionTemplate> constructor = env->NewFunctionTemplate(New);
51
106
    constructor->InstanceTemplate()->SetInternalFieldCount(1);
52
    Local<String> signalString =
53
53
        FIXED_ONE_BYTE_STRING(env->isolate(), "Signal");
54
53
    constructor->SetClassName(signalString);
55
106
    constructor->Inherit(HandleWrap::GetConstructorTemplate(env));
56
57
53
    env->SetProtoMethod(constructor, "start", Start);
58
53
    env->SetProtoMethod(constructor, "stop", Stop);
59
60
    target->Set(env->context(), signalString,
61
265
                constructor->GetFunction(env->context()).ToLocalChecked())
62
106
                .FromJust();
63
53
  }
64
65
  SET_NO_MEMORY_INFO()
66
  SET_MEMORY_INFO_NAME(SignalWrap)
67
  SET_SELF_SIZE(SignalWrap)
68
69
 private:
70
98
  static void New(const FunctionCallbackInfo<Value>& args) {
71
    // This constructor should not be exposed to public javascript.
72
    // Therefore we assert that we are not trying to call this as a
73
    // normal function.
74
98
    CHECK(args.IsConstructCall());
75
98
    Environment* env = Environment::GetCurrent(args);
76
98
    new SignalWrap(env, args.This());
77
98
  }
78
79
98
  SignalWrap(Environment* env, Local<Object> object)
80
      : HandleWrap(env,
81
                   object,
82
                   reinterpret_cast<uv_handle_t*>(&handle_),
83
98
                   AsyncWrap::PROVIDER_SIGNALWRAP) {
84
98
    int r = uv_signal_init(env->event_loop(), &handle_);
85
98
    CHECK_EQ(r, 0);
86
98
  }
87
88
96
  static void Start(const FunctionCallbackInfo<Value>& args) {
89
    SignalWrap* wrap;
90
97
    ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
91
96
    Environment* env = wrap->env();
92
    int signum;
93
384
    if (!args[0]->Int32Value(env->context()).To(&signum)) return;
94
#if defined(__POSIX__) && HAVE_INSPECTOR
95
96
    if (signum == SIGPROF) {
96
1
      Environment* env = Environment::GetCurrent(args);
97
1
      if (env->inspector_agent()->IsListening()) {
98
        ProcessEmitWarning(env,
99
1
                           "process.on(SIGPROF) is reserved while debugging");
100
1
        return;
101
      }
102
    }
103
#endif
104
    int err = uv_signal_start(
105
        &wrap->handle_,
106
129
        [](uv_signal_t* handle, int signum) {
107
17
          SignalWrap* wrap = ContainerOf(&SignalWrap::handle_, handle);
108
17
          Environment* env = wrap->env();
109
17
          HandleScope handle_scope(env->isolate());
110
17
          Context::Scope context_scope(env->context());
111
17
          Local<Value> arg = Integer::New(env->isolate(), signum);
112
17
          wrap->MakeCallback(env->onsignal_string(), 1, &arg);
113
129
        },
114
95
        signum);
115
190
    args.GetReturnValue().Set(err);
116
  }
117
118
  static void Stop(const FunctionCallbackInfo<Value>& args) {
119
    SignalWrap* wrap;
120
    ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
121
    int err = uv_signal_stop(&wrap->handle_);
122
    args.GetReturnValue().Set(err);
123
  }
124
125
  uv_signal_t handle_;
126
};
127
128
129
}  // anonymous namespace
130
}  // namespace node
131
132
133
4292
NODE_MODULE_CONTEXT_AWARE_INTERNAL(signal_wrap, node::SignalWrap::Initialize)