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.h Lines: 88 88 100.0 %
Date: 2020-02-27 22:14:15 Branches: 73 112 65.2 %

Line Branch Exec Source
1
#pragma once
2
3
#include "node.h"
4
#include "node_buffer.h"
5
#include "uv.h"
6
#include "v8.h"
7
#include "util.h"
8
9
#ifndef _WIN32
10
#include <sys/types.h>
11
#include <unistd.h>
12
#endif
13
14
#include <climits>
15
#include <cstdio>
16
#include <cstdlib>
17
#include <cstring>
18
#include <iomanip>
19
#include <iostream>
20
#include <sstream>
21
#include <limits>
22
#include <algorithm>
23
#include <queue>
24
#include <string>
25
#include <utility>
26
#include <vector>
27
28
namespace report {
29
30
// Function declarations - functions in src/node_report.cc
31
std::string TriggerNodeReport(v8::Isolate* isolate,
32
                              node::Environment* env,
33
                              const char* message,
34
                              const char* trigger,
35
                              const std::string& name,
36
                              v8::Local<v8::String> stackstr);
37
void GetNodeReport(v8::Isolate* isolate,
38
                   node::Environment* env,
39
                   const char* message,
40
                   const char* trigger,
41
                   v8::Local<v8::String> stackstr,
42
                   std::ostream& out);
43
44
// Function declarations - utility functions in src/node_report_utils.cc
45
void WalkHandle(uv_handle_t* h, void* arg);
46
std::string EscapeJsonChars(const std::string& str);
47
std::string Reindent(const std::string& str, int indentation);
48
49
template <typename T>
50
344
std::string ValueToHexString(T value) {
51
688
  std::stringstream hex;
52
53
344
  hex << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex <<
54
    value;
55
688
  return hex.str();
56
}
57
58
// Function declarations - export functions in src/node_report_module.cc
59
void WriteReport(const v8::FunctionCallbackInfo<v8::Value>& info);
60
void GetReport(const v8::FunctionCallbackInfo<v8::Value>& info);
61
62
// Node.js boot time - defined in src/node.cc
63
extern double prog_start_time;
64
65
// JSON compiler definitions.
66
class JSONWriter {
67
 public:
68
19
  explicit JSONWriter(std::ostream& out) : out_(out) {}
69
70
1374
  inline void indent() { indent_ += 2; }
71
1374
  inline void deindent() { indent_ -= 2; }
72
9519
  inline void advance() {
73
9519
    for (int i = 0; i < indent_; i++) out_ << ' ';
74
9519
  }
75
76
629
  inline void json_start() {
77
629
    if (state_ == kAfterValue) out_ << ',';
78
629
    out_ << '\n';
79
629
    advance();
80
629
    out_ << '{';
81
629
    indent();
82
629
    state_ = kObjectStart;
83
629
  }
84
85
610
  inline void json_end() {
86
610
    out_ << '\n';
87
610
    deindent();
88
610
    advance();
89
610
    out_ << '}';
90
610
    state_ = kAfterValue;
91
610
  }
92
  template <typename T>
93
597
  inline void json_objectstart(T key) {
94
597
    if (state_ == kAfterValue) out_ << ',';
95
597
    out_ << '\n';
96
597
    advance();
97
597
    write_string(key);
98
597
    out_ << ": {";
99
597
    indent();
100
597
    state_ = kObjectStart;
101
597
  }
102
103
  template <typename T>
104
148
  inline void json_arraystart(T key) {
105
148
    if (state_ == kAfterValue) out_ << ',';
106
148
    out_ << '\n';
107
148
    advance();
108
148
    write_string(key);
109
148
    out_ << ": [";
110
148
    indent();
111
148
    state_ = kObjectStart;
112
148
  }
113
616
  inline void json_objectend() {
114
616
    out_ << '\n';
115
616
    deindent();
116
616
    advance();
117
616
    out_ << '}';
118
616
    state_ = kAfterValue;
119
616
  }
120
121
148
  inline void json_arrayend() {
122
148
    out_ << '\n';
123
148
    deindent();
124
148
    advance();
125
148
    out_ << ']';
126
148
    state_ = kAfterValue;
127
148
  }
128
  template <typename T, typename U>
129
6489
  inline void json_keyvalue(const T& key, const U& value) {
130
























6489
    if (state_ == kAfterValue) out_ << ',';
131
6489
    out_ << '\n';
132
6489
    advance();
133
6489
    write_string(key);
134
6489
    out_ << ": ";
135
6489
    write_value(value);
136
6489
    state_ = kAfterValue;
137
6489
  }
138
139
  template <typename U>
140
282
  inline void json_element(const U& value) {
141

282
    if (state_ == kAfterValue) out_ << ',';
142
282
    out_ << '\n';
143
282
    advance();
144
282
    write_value(value);
145
282
    state_ = kAfterValue;
146
282
  }
147
148
  struct Null {};  // Usable as a JSON value.
149
150
2
  struct ForeignJSON {
151
    std::string as_string;
152
  };
153
154
 private:
155
  template <typename T,
156
            typename test_for_number = typename std::
157
                enable_if<std::numeric_limits<T>::is_specialized, bool>::type>
158
2900
  inline void write_value(T number) {
159
    if (std::is_same<T, bool>::value)
160
526
      out_ << (number ? "true" : "false");
161
    else
162
2374
      out_ << number;
163
2900
  }
164
165
11
  inline void write_value(Null null) { out_ << "null"; }
166
2658
  inline void write_value(const char* str) { write_string(str); }
167
1200
  inline void write_value(const std::string& str) { write_string(str); }
168
169
2
  inline void write_value(const ForeignJSON& json) {
170
2
    out_ << Reindent(json.as_string, indent_);
171
2
  }
172
173
11092
  inline void write_string(const std::string& str) {
174
11092
    out_ << '"' << EscapeJsonChars(str) << '"';
175
11092
  }
176
9892
  inline void write_string(const char* str) { write_string(std::string(str)); }
177
178
  enum JSONState { kObjectStart, kAfterValue };
179
  std::ostream& out_;
180
  int indent_ = 0;
181
  int state_ = kObjectStart;
182
};
183
184
}  // namespace report