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