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: 130 131 99.2 %
Date: 2020-08-17 22:13:26 Branches: 20 34 58.8 %

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::Context;
22
using v8::FunctionCallbackInfo;
23
using v8::HandleScope;
24
using v8::Isolate;
25
using v8::Local;
26
using v8::Object;
27
using v8::String;
28
using v8::Value;
29
30
13
void WriteReport(const FunctionCallbackInfo<Value>& info) {
31
13
  Environment* env = Environment::GetCurrent(info);
32
13
  Isolate* isolate = env->isolate();
33
26
  HandleScope scope(isolate);
34
26
  std::string filename;
35
  Local<Object> error;
36
37
13
  CHECK_EQ(info.Length(), 4);
38
39
  String::Utf8Value message(isolate, info[0].As<String>());
39
39
  String::Utf8Value trigger(isolate, info[1].As<String>());
40
41
39
  if (info[2]->IsString())
42
4
    filename = *String::Utf8Value(isolate, info[2]);
43

52
  if (!info[3].IsEmpty() && info[3]->IsObject())
44
24
    error = info[3].As<Object>();
45
  else
46
1
    error = Local<Object>();
47
48
26
  filename = TriggerNodeReport(
49
26
      isolate, env, *message, *trigger, filename, error);
50
  // Return value is the report filename
51
26
  info.GetReturnValue().Set(
52
26
      String::NewFromUtf8(isolate, filename.c_str()).ToLocalChecked());
53
13
}
54
55
// External JavaScript API for returning a report
56
8
void GetReport(const FunctionCallbackInfo<Value>& info) {
57
8
  Environment* env = Environment::GetCurrent(info);
58
8
  Isolate* isolate = env->isolate();
59
16
  HandleScope scope(isolate);
60
  Local<Object> error;
61
16
  std::ostringstream out;
62
63
8
  CHECK_EQ(info.Length(), 1);
64

32
  if (!info[0].IsEmpty() && info[0]->IsObject())
65
16
    error = info[0].As<Object>();
66
  else
67
    error = Local<Object>();
68
69
  GetNodeReport(
70
8
      isolate, env, "JavaScript API", __func__, error, out);
71
72
  // Return value is the contents of a report as a string.
73
16
  info.GetReturnValue().Set(
74
16
      String::NewFromUtf8(isolate, out.str().c_str()).ToLocalChecked());
75
8
}
76
77
17
static void GetCompact(const FunctionCallbackInfo<Value>& info) {
78
34
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
79
51
  info.GetReturnValue().Set(node::per_process::cli_options->report_compact);
80
17
}
81
82
2
static void SetCompact(const FunctionCallbackInfo<Value>& info) {
83
4
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
84
2
  Environment* env = Environment::GetCurrent(info);
85
2
  Isolate* isolate = env->isolate();
86
6
  bool compact = info[0]->ToBoolean(isolate)->Value();
87
2
  node::per_process::cli_options->report_compact = compact;
88
2
}
89
90
4
static void GetDirectory(const FunctionCallbackInfo<Value>& info) {
91
8
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
92
4
  Environment* env = Environment::GetCurrent(info);
93
8
  std::string directory = node::per_process::cli_options->report_directory;
94
4
  auto result = String::NewFromUtf8(env->isolate(), directory.c_str());
95
8
  info.GetReturnValue().Set(result.ToLocalChecked());
96
4
}
97
98
5
static void SetDirectory(const FunctionCallbackInfo<Value>& info) {
99
10
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
100
5
  Environment* env = Environment::GetCurrent(info);
101
15
  CHECK(info[0]->IsString());
102
15
  Utf8Value dir(env->isolate(), info[0].As<String>());
103
5
  node::per_process::cli_options->report_directory = *dir;
104
5
}
105
106
4
static void GetFilename(const FunctionCallbackInfo<Value>& info) {
107
8
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
108
4
  Environment* env = Environment::GetCurrent(info);
109
8
  std::string filename = node::per_process::cli_options->report_filename;
110
4
  auto result = String::NewFromUtf8(env->isolate(), filename.c_str());
111
8
  info.GetReturnValue().Set(result.ToLocalChecked());
112
4
}
113
114
2
static void SetFilename(const FunctionCallbackInfo<Value>& info) {
115
4
  node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
116
2
  Environment* env = Environment::GetCurrent(info);
117
6
  CHECK(info[0]->IsString());
118
6
  Utf8Value name(env->isolate(), info[0].As<String>());
119
2
  node::per_process::cli_options->report_filename = *name;
120
2
}
121
122
15
static void GetSignal(const FunctionCallbackInfo<Value>& info) {
123
15
  Environment* env = Environment::GetCurrent(info);
124
30
  std::string signal = env->isolate_data()->options()->report_signal;
125
15
  auto result = String::NewFromUtf8(env->isolate(), signal.c_str());
126
30
  info.GetReturnValue().Set(result.ToLocalChecked());
127
15
}
128
129
3
static void SetSignal(const FunctionCallbackInfo<Value>& info) {
130
3
  Environment* env = Environment::GetCurrent(info);
131
9
  CHECK(info[0]->IsString());
132
9
  Utf8Value signal(env->isolate(), info[0].As<String>());
133
3
  env->isolate_data()->options()->report_signal = *signal;
134
3
}
135
136
4
static void ShouldReportOnFatalError(const FunctionCallbackInfo<Value>& info) {
137
8
  Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
138
12
  info.GetReturnValue().Set(
139
4
      node::per_process::cli_options->report_on_fatalerror);
140
4
}
141
142
2
static void SetReportOnFatalError(const FunctionCallbackInfo<Value>& info) {
143
4
  CHECK(info[0]->IsBoolean());
144
4
  Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
145
6
  node::per_process::cli_options->report_on_fatalerror = info[0]->IsTrue();
146
2
}
147
148
4420
static void ShouldReportOnSignal(const FunctionCallbackInfo<Value>& info) {
149
4420
  Environment* env = Environment::GetCurrent(info);
150
13260
  info.GetReturnValue().Set(env->isolate_data()->options()->report_on_signal);
151
4420
}
152
153
5
static void SetReportOnSignal(const FunctionCallbackInfo<Value>& info) {
154
5
  Environment* env = Environment::GetCurrent(info);
155
10
  CHECK(info[0]->IsBoolean());
156
15
  env->isolate_data()->options()->report_on_signal = info[0]->IsTrue();
157
5
}
158
159
1421
static void ShouldReportOnUncaughtException(
160
    const FunctionCallbackInfo<Value>& info) {
161
1421
  Environment* env = Environment::GetCurrent(info);
162
4263
  info.GetReturnValue().Set(
163
2842
      env->isolate_data()->options()->report_uncaught_exception);
164
1421
}
165
166
2
static void SetReportOnUncaughtException(
167
    const FunctionCallbackInfo<Value>& info) {
168
2
  Environment* env = Environment::GetCurrent(info);
169
4
  CHECK(info[0]->IsBoolean());
170
6
  env->isolate_data()->options()->report_uncaught_exception = info[0]->IsTrue();
171
2
}
172
173
4750
static void Initialize(Local<Object> exports,
174
                       Local<Value> unused,
175
                       Local<Context> context,
176
                       void* priv) {
177
4750
  Environment* env = Environment::GetCurrent(context);
178
179
4750
  env->SetMethod(exports, "writeReport", WriteReport);
180
4750
  env->SetMethod(exports, "getReport", GetReport);
181
4750
  env->SetMethod(exports, "getCompact", GetCompact);
182
4750
  env->SetMethod(exports, "setCompact", SetCompact);
183
4750
  env->SetMethod(exports, "getDirectory", GetDirectory);
184
4750
  env->SetMethod(exports, "setDirectory", SetDirectory);
185
4750
  env->SetMethod(exports, "getFilename", GetFilename);
186
4750
  env->SetMethod(exports, "setFilename", SetFilename);
187
4750
  env->SetMethod(exports, "getSignal", GetSignal);
188
4750
  env->SetMethod(exports, "setSignal", SetSignal);
189
4750
  env->SetMethod(exports, "shouldReportOnFatalError", ShouldReportOnFatalError);
190
4750
  env->SetMethod(exports, "setReportOnFatalError", SetReportOnFatalError);
191
4750
  env->SetMethod(exports, "shouldReportOnSignal", ShouldReportOnSignal);
192
4750
  env->SetMethod(exports, "setReportOnSignal", SetReportOnSignal);
193
  env->SetMethod(exports, "shouldReportOnUncaughtException",
194
4750
                 ShouldReportOnUncaughtException);
195
  env->SetMethod(exports, "setReportOnUncaughtException",
196
4750
                 SetReportOnUncaughtException);
197
4750
}
198
199
}  // namespace report
200
201

17839
NODE_MODULE_CONTEXT_AWARE_INTERNAL(report, report::Initialize)