GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_report_module.cc Lines: 126 126 100.0 %
Date: 2020-05-27 22:15:15 Branches: 9 16 56.3 %

Line Branch Exec Source
1
#include "env.h"
2
#include "node_errors.h"
3
#include "node_internals.h"
4
#include "node_options.h"
5
#include "node_report.h"
6
#include "util-inl.h"
7
8
#include "handle_wrap.h"
9
#include "node_buffer.h"
10
#include "stream_base-inl.h"
11
#include "stream_wrap.h"
12
13
#include <v8.h>
14
#include <atomic>
15
#include <sstream>
16
17
namespace report {
18
using node::Environment;
19
using node::Mutex;
20
using node::Utf8Value;
21
using v8::Boolean;
22
using v8::Context;
23
using v8::Function;
24
using v8::FunctionCallbackInfo;
25
using v8::HandleScope;
26
using v8::Isolate;
27
using v8::Local;
28
using v8::Object;
29
using v8::String;
30
using v8::Value;
31
32
12
void WriteReport(const FunctionCallbackInfo<Value>& info) {
33
12
  Environment* env = Environment::GetCurrent(info);
34
12
  Isolate* isolate = env->isolate();
35
24
  HandleScope scope(isolate);
36
24
  std::string filename;
37
  Local<String> stackstr;
38
39
12
  CHECK_EQ(info.Length(), 4);
40
36
  String::Utf8Value message(isolate, info[0].As<String>());
41
36
  String::Utf8Value trigger(isolate, info[1].As<String>());
42
24
  stackstr = info[3].As<String>();
43
44
36
  if (info[2]->IsString())
45
4
    filename = *String::Utf8Value(isolate, info[2]);
46
47
24
  filename = TriggerNodeReport(
48
24
      isolate, env, *message, *trigger, filename, stackstr);
49
  // Return value is the report filename
50
24
  info.GetReturnValue().Set(
51
24
      String::NewFromUtf8(isolate, filename.c_str(), v8::NewStringType::kNormal)
52
          .ToLocalChecked());
53
12
}
54
55
// External JavaScript API for returning a report
56
7
void GetReport(const FunctionCallbackInfo<Value>& info) {
57
7
  Environment* env = Environment::GetCurrent(info);
58
7
  Isolate* isolate = env->isolate();
59
14
  HandleScope scope(isolate);
60
14
  std::ostringstream out;
61
62
  GetNodeReport(
63
14
      isolate, env, "JavaScript API", __func__, info[0].As<String>(), out);
64
65
  // Return value is the contents of a report as a string.
66
21
  info.GetReturnValue().Set(String::NewFromUtf8(isolate,
67
14
                                                out.str().c_str(),
68
7
                                                v8::NewStringType::kNormal)
69
                                .ToLocalChecked());
70
7
}
71
72
16
static void GetCompact(const FunctionCallbackInfo<Value>& info) {
73
32
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
74
48
  info.GetReturnValue().Set(node::per_process::cli_options->report_compact);
75
16
}
76
77
2
static void SetCompact(const FunctionCallbackInfo<Value>& info) {
78
4
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
79
2
  Environment* env = Environment::GetCurrent(info);
80
2
  Isolate* isolate = env->isolate();
81
6
  bool compact = info[0]->ToBoolean(isolate)->Value();
82
2
  node::per_process::cli_options->report_compact = compact;
83
2
}
84
85
4
static void GetDirectory(const FunctionCallbackInfo<Value>& info) {
86
8
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
87
4
  Environment* env = Environment::GetCurrent(info);
88
8
  std::string directory = node::per_process::cli_options->report_directory;
89
  auto result = String::NewFromUtf8(env->isolate(),
90
                                    directory.c_str(),
91
4
                                    v8::NewStringType::kNormal);
92
8
  info.GetReturnValue().Set(result.ToLocalChecked());
93
4
}
94
95
5
static void SetDirectory(const FunctionCallbackInfo<Value>& info) {
96
10
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
97
5
  Environment* env = Environment::GetCurrent(info);
98
15
  CHECK(info[0]->IsString());
99
15
  Utf8Value dir(env->isolate(), info[0].As<String>());
100
5
  node::per_process::cli_options->report_directory = *dir;
101
5
}
102
103
4
static void GetFilename(const FunctionCallbackInfo<Value>& info) {
104
8
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
105
4
  Environment* env = Environment::GetCurrent(info);
106
8
  std::string filename = node::per_process::cli_options->report_filename;
107
  auto result = String::NewFromUtf8(env->isolate(),
108
                                    filename.c_str(),
109
4
                                    v8::NewStringType::kNormal);
110
8
  info.GetReturnValue().Set(result.ToLocalChecked());
111
4
}
112
113
2
static void SetFilename(const FunctionCallbackInfo<Value>& info) {
114
4
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
115
2
  Environment* env = Environment::GetCurrent(info);
116
6
  CHECK(info[0]->IsString());
117
6
  Utf8Value name(env->isolate(), info[0].As<String>());
118
2
  node::per_process::cli_options->report_filename = *name;
119
2
}
120
121
15
static void GetSignal(const FunctionCallbackInfo<Value>& info) {
122
15
  Environment* env = Environment::GetCurrent(info);
123
30
  std::string signal = env->isolate_data()->options()->report_signal;
124
  auto result = String::NewFromUtf8(env->isolate(),
125
                                    signal.c_str(),
126
15
                                    v8::NewStringType::kNormal);
127
30
  info.GetReturnValue().Set(result.ToLocalChecked());
128
15
}
129
130
3
static void SetSignal(const FunctionCallbackInfo<Value>& info) {
131
3
  Environment* env = Environment::GetCurrent(info);
132
9
  CHECK(info[0]->IsString());
133
9
  Utf8Value signal(env->isolate(), info[0].As<String>());
134
3
  env->isolate_data()->options()->report_signal = *signal;
135
3
}
136
137
4
static void ShouldReportOnFatalError(const FunctionCallbackInfo<Value>& info) {
138
8
  Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
139
12
  info.GetReturnValue().Set(
140
4
      node::per_process::cli_options->report_on_fatalerror);
141
4
}
142
143
2
static void SetReportOnFatalError(const FunctionCallbackInfo<Value>& info) {
144
4
  CHECK(info[0]->IsBoolean());
145
4
  Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
146
6
  node::per_process::cli_options->report_on_fatalerror = info[0]->IsTrue();
147
2
}
148
149
4282
static void ShouldReportOnSignal(const FunctionCallbackInfo<Value>& info) {
150
4282
  Environment* env = Environment::GetCurrent(info);
151
12846
  info.GetReturnValue().Set(env->isolate_data()->options()->report_on_signal);
152
4282
}
153
154
5
static void SetReportOnSignal(const FunctionCallbackInfo<Value>& info) {
155
5
  Environment* env = Environment::GetCurrent(info);
156
10
  CHECK(info[0]->IsBoolean());
157
15
  env->isolate_data()->options()->report_on_signal = info[0]->IsTrue();
158
5
}
159
160
1424
static void ShouldReportOnUncaughtException(
161
    const FunctionCallbackInfo<Value>& info) {
162
1424
  Environment* env = Environment::GetCurrent(info);
163
4272
  info.GetReturnValue().Set(
164
2848
      env->isolate_data()->options()->report_uncaught_exception);
165
1424
}
166
167
2
static void SetReportOnUncaughtException(
168
    const FunctionCallbackInfo<Value>& info) {
169
2
  Environment* env = Environment::GetCurrent(info);
170
4
  CHECK(info[0]->IsBoolean());
171
6
  env->isolate_data()->options()->report_uncaught_exception = info[0]->IsTrue();
172
2
}
173
174
4567
static void Initialize(Local<Object> exports,
175
                       Local<Value> unused,
176
                       Local<Context> context,
177
                       void* priv) {
178
4567
  Environment* env = Environment::GetCurrent(context);
179
180
4567
  env->SetMethod(exports, "writeReport", WriteReport);
181
4567
  env->SetMethod(exports, "getReport", GetReport);
182
4567
  env->SetMethod(exports, "getCompact", GetCompact);
183
4567
  env->SetMethod(exports, "setCompact", SetCompact);
184
4567
  env->SetMethod(exports, "getDirectory", GetDirectory);
185
4567
  env->SetMethod(exports, "setDirectory", SetDirectory);
186
4567
  env->SetMethod(exports, "getFilename", GetFilename);
187
4567
  env->SetMethod(exports, "setFilename", SetFilename);
188
4567
  env->SetMethod(exports, "getSignal", GetSignal);
189
4567
  env->SetMethod(exports, "setSignal", SetSignal);
190
4567
  env->SetMethod(exports, "shouldReportOnFatalError", ShouldReportOnFatalError);
191
4567
  env->SetMethod(exports, "setReportOnFatalError", SetReportOnFatalError);
192
4567
  env->SetMethod(exports, "shouldReportOnSignal", ShouldReportOnSignal);
193
4567
  env->SetMethod(exports, "setReportOnSignal", SetReportOnSignal);
194
  env->SetMethod(exports, "shouldReportOnUncaughtException",
195
4567
                 ShouldReportOnUncaughtException);
196
  env->SetMethod(exports, "setReportOnUncaughtException",
197
4567
                 SetReportOnUncaughtException);
198
4567
}
199
200
}  // namespace report
201
202
4325
NODE_MODULE_CONTEXT_AWARE_INTERNAL(report, report::Initialize)