GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
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 |
|||
48 |
template <typename T> |
||
49 |
270 |
std::string ValueToHexString(T value) { |
|
50 |
270 |
std::stringstream hex; |
|
51 |
|||
52 |
270 |
hex << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex << |
|
53 |
value; |
||
54 |
270 |
return hex.str(); |
|
55 |
} |
||
56 |
|||
57 |
// Function declarations - export functions in src/node_report_module.cc |
||
58 |
void WriteReport(const v8::FunctionCallbackInfo<v8::Value>& info); |
||
59 |
void GetReport(const v8::FunctionCallbackInfo<v8::Value>& info); |
||
60 |
|||
61 |
// Node.js boot time - defined in src/node.cc |
||
62 |
extern double prog_start_time; |
||
63 |
|||
64 |
// JSON compiler definitions. |
||
65 |
class JSONWriter { |
||
66 |
public: |
||
67 |
15 |
explicit JSONWriter(std::ostream& out) : out_(out) {} |
|
68 |
|||
69 |
1071 |
inline void indent() { indent_ += 2; } |
|
70 |
1071 |
inline void deindent() { indent_ -= 2; } |
|
71 |
7450 |
inline void advance() { |
|
72 |
✓✓ | 7450 |
for (int i = 0; i < indent_; i++) out_ << ' '; |
73 |
7450 |
} |
|
74 |
|||
75 |
495 |
inline void json_start() { |
|
76 |
✓✓ | 495 |
if (state_ == kAfterValue) out_ << ','; |
77 |
495 |
out_ << '\n'; |
|
78 |
495 |
advance(); |
|
79 |
495 |
out_ << '{'; |
|
80 |
495 |
indent(); |
|
81 |
495 |
state_ = kObjectStart; |
|
82 |
495 |
} |
|
83 |
|||
84 |
480 |
inline void json_end() { |
|
85 |
480 |
out_ << '\n'; |
|
86 |
480 |
deindent(); |
|
87 |
480 |
advance(); |
|
88 |
480 |
out_ << '}'; |
|
89 |
480 |
state_ = kAfterValue; |
|
90 |
480 |
} |
|
91 |
template <typename T> |
||
92 |
473 |
inline void json_objectstart(T key) { |
|
93 |
✓✓ | 473 |
if (state_ == kAfterValue) out_ << ','; |
94 |
473 |
out_ << '\n'; |
|
95 |
473 |
advance(); |
|
96 |
473 |
write_string(key); |
|
97 |
473 |
out_ << ": {"; |
|
98 |
473 |
indent(); |
|
99 |
473 |
state_ = kObjectStart; |
|
100 |
473 |
} |
|
101 |
|||
102 |
template <typename T> |
||
103 |
103 |
inline void json_arraystart(T key) { |
|
104 |
✓✗ | 103 |
if (state_ == kAfterValue) out_ << ','; |
105 |
103 |
out_ << '\n'; |
|
106 |
103 |
advance(); |
|
107 |
103 |
write_string(key); |
|
108 |
103 |
out_ << ": ["; |
|
109 |
103 |
indent(); |
|
110 |
103 |
state_ = kObjectStart; |
|
111 |
103 |
} |
|
112 |
488 |
inline void json_objectend() { |
|
113 |
488 |
out_ << '\n'; |
|
114 |
488 |
deindent(); |
|
115 |
488 |
advance(); |
|
116 |
488 |
out_ << '}'; |
|
117 |
488 |
state_ = kAfterValue; |
|
118 |
488 |
} |
|
119 |
|||
120 |
103 |
inline void json_arrayend() { |
|
121 |
103 |
out_ << '\n'; |
|
122 |
103 |
deindent(); |
|
123 |
103 |
advance(); |
|
124 |
103 |
out_ << ']'; |
|
125 |
103 |
state_ = kAfterValue; |
|
126 |
103 |
} |
|
127 |
template <typename T, typename U> |
||
128 |
5057 |
inline void json_keyvalue(const T& key, const U& value) { |
|
129 |
✓✗✓✗ ✓✓✓✓ ✓✗✓✓ ✓✓✓✗ ✓✗✓✗ ✓✗✗✓ ✓✗✓✗ ✓✓✓✗ ✓✓✓✗ ✓✓✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ ✓✗✓✓ ✓✗✗✓ ✓✗✓✗ ✓✗✓✓ ✓✗✓✗ ✓✗✓✗ ✓✓✓✗ ✗✓✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
5057 |
if (state_ == kAfterValue) out_ << ','; |
130 |
5057 |
out_ << '\n'; |
|
131 |
5057 |
advance(); |
|
132 |
5057 |
write_string(key); |
|
133 |
5057 |
out_ << ": "; |
|
134 |
5057 |
write_value(value); |
|
135 |
5057 |
state_ = kAfterValue; |
|
136 |
5057 |
} |
|
137 |
|||
138 |
template <typename U> |
||
139 |
251 |
inline void json_element(const U& value) { |
|
140 |
✓✓ | 251 |
if (state_ == kAfterValue) out_ << ','; |
141 |
251 |
out_ << '\n'; |
|
142 |
251 |
advance(); |
|
143 |
251 |
write_value(value); |
|
144 |
251 |
state_ = kAfterValue; |
|
145 |
251 |
} |
|
146 |
|||
147 |
struct Null {}; // Usable as a JSON value. |
||
148 |
|||
149 |
private: |
||
150 |
template <typename T, |
||
151 |
typename test_for_number = typename std:: |
||
152 |
enable_if<std::numeric_limits<T>::is_specialized, bool>::type> |
||
153 |
2269 |
inline void write_value(T number) { |
|
154 |
if (std::is_same<T, bool>::value) |
||
155 |
✓✓ | 406 |
out_ << (number ? "true" : "false"); |
156 |
else |
||
157 |
1863 |
out_ << number; |
|
158 |
2269 |
} |
|
159 |
|||
160 |
7 |
inline void write_value(Null null) { out_ << "null"; } |
|
161 |
2036 |
inline void write_value(const char* str) { write_string(str); } |
|
162 |
996 |
inline void write_value(const std::string& str) { write_string(str); } |
|
163 |
|||
164 |
8665 |
inline void write_string(const std::string& str) { |
|
165 |
8665 |
out_ << '"' << EscapeJsonChars(str) << '"'; |
|
166 |
8665 |
} |
|
167 |
7669 |
inline void write_string(const char* str) { write_string(std::string(str)); } |
|
168 |
|||
169 |
enum JSONState { kObjectStart, kAfterValue }; |
||
170 |
std::ostream& out_; |
||
171 |
int indent_ = 0; |
||
172 |
int state_ = kObjectStart; |
||
173 |
}; |
||
174 |
|||
175 |
} // namespace report |
Generated by: GCOVR (Version 3.4) |