GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/signal_wrap.cc Lines: 43 50 86.0 %
Date: 2019-01-07 12:15:22 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 "util-inl.h"
26
#include "v8.h"
27
28
namespace node {
29
30
using v8::Context;
31
using v8::FunctionCallbackInfo;
32
using v8::FunctionTemplate;
33
using v8::HandleScope;
34
using v8::Integer;
35
using v8::Local;
36
using v8::Object;
37
using v8::String;
38
using v8::Value;
39
40
namespace {
41
42
114
class SignalWrap : public HandleWrap {
43
 public:
44
54
  static void Initialize(Local<Object> target,
45
                         Local<Value> unused,
46
                         Local<Context> context,
47
                         void* priv) {
48
54
    Environment* env = Environment::GetCurrent(context);
49
54
    Local<FunctionTemplate> constructor = env->NewFunctionTemplate(New);
50
108
    constructor->InstanceTemplate()->SetInternalFieldCount(1);
51
    Local<String> signalString =
52
54
        FIXED_ONE_BYTE_STRING(env->isolate(), "Signal");
53
54
    constructor->SetClassName(signalString);
54
108
    constructor->Inherit(HandleWrap::GetConstructorTemplate(env));
55
56
54
    env->SetProtoMethod(constructor, "start", Start);
57
54
    env->SetProtoMethod(constructor, "stop", Stop);
58
59
    target->Set(env->context(), signalString,
60
270
                constructor->GetFunction(env->context()).ToLocalChecked())
61
108
                .FromJust();
62
54
  }
63
64
  SET_NO_MEMORY_INFO()
65
  SET_MEMORY_INFO_NAME(SignalWrap)
66
  SET_SELF_SIZE(SignalWrap)
67
68
 private:
69
101
  static void New(const FunctionCallbackInfo<Value>& args) {
70
    // This constructor should not be exposed to public javascript.
71
    // Therefore we assert that we are not trying to call this as a
72
    // normal function.
73
101
    CHECK(args.IsConstructCall());
74
101
    Environment* env = Environment::GetCurrent(args);
75
101
    new SignalWrap(env, args.This());
76
101
  }
77
78
101
  SignalWrap(Environment* env, Local<Object> object)
79
      : HandleWrap(env,
80
                   object,
81
                   reinterpret_cast<uv_handle_t*>(&handle_),
82
101
                   AsyncWrap::PROVIDER_SIGNALWRAP) {
83
101
    int r = uv_signal_init(env->event_loop(), &handle_);
84
101
    CHECK_EQ(r, 0);
85
101
  }
86
87
99
  static void Start(const FunctionCallbackInfo<Value>& args) {
88
    SignalWrap* wrap;
89
100
    ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
90
99
    Environment* env = wrap->env();
91
    int signum;
92
396
    if (!args[0]->Int32Value(env->context()).To(&signum)) return;
93
#if defined(__POSIX__) && HAVE_INSPECTOR
94
99
    if (signum == SIGPROF) {
95
1
      Environment* env = Environment::GetCurrent(args);
96
1
      if (env->inspector_agent()->IsListening()) {
97
        ProcessEmitWarning(env,
98
1
                           "process.on(SIGPROF) is reserved while debugging");
99
1
        return;
100
      }
101
    }
102
#endif
103
98
    int err = uv_signal_start(&wrap->handle_, OnSignal, signum);
104
196
    args.GetReturnValue().Set(err);
105
  }
106
107
  static void Stop(const FunctionCallbackInfo<Value>& args) {
108
    SignalWrap* wrap;
109
    ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
110
    int err = uv_signal_stop(&wrap->handle_);
111
    args.GetReturnValue().Set(err);
112
  }
113
114
17
  static void OnSignal(uv_signal_t* handle, int signum) {
115
17
    SignalWrap* wrap = ContainerOf(&SignalWrap::handle_, handle);
116
17
    Environment* env = wrap->env();
117
17
    HandleScope handle_scope(env->isolate());
118
17
    Context::Scope context_scope(env->context());
119
120
17
    Local<Value> arg = Integer::New(env->isolate(), signum);
121
34
    wrap->MakeCallback(env->onsignal_string(), 1, &arg);
122
17
  }
123
124
  uv_signal_t handle_;
125
};
126
127
128
}  // anonymous namespace
129
}  // namespace node
130
131
132
3596
NODE_MODULE_CONTEXT_AWARE_INTERNAL(signal_wrap, node::SignalWrap::Initialize)