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: 106 106 100.0 %
Date: 2019-09-13 22:28:55 Branches: 11 20 55.0 %

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

20123
NODE_MODULE_CONTEXT_AWARE_INTERNAL(report, report::Initialize)