GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/inspector/node_string.h Lines: 22 29 75.9 %
Date: 2019-05-05 22:32:45 Branches: 0 0 - %

Line Branch Exec Source
1
// Bridges V8 Inspector generated code with the std::string used by the Node
2
// Compare to V8 counterpart - deps/v8/src/inspector/string-util.h
3
#ifndef SRC_INSPECTOR_NODE_STRING_H_
4
#define SRC_INSPECTOR_NODE_STRING_H_
5
6
#include "util.h"
7
#include "v8-inspector.h"
8
9
#include <cstring>
10
#include <sstream>
11
#include <string>
12
13
namespace node {
14
namespace inspector {
15
namespace protocol {
16
17
class Value;
18
19
using String = std::string;
20
using StringBuilder = std::ostringstream;
21
using ProtocolMessage = std::string;
22
23
class StringUTF8Adapter {
24
 public:
25
  explicit StringUTF8Adapter(const std::string& string) : string_(string) { }
26
  const char* Data() const { return string_.data(); }
27
  size_t length() const { return string_.length(); }
28
29
 private:
30
  const std::string& string_;
31
};
32
33
namespace StringUtil {
34
// NOLINTNEXTLINE(runtime/references) This is V8 API...
35
629306
inline void builderAppend(StringBuilder& builder, char c) {
36
629306
  builder.put(c);
37
629308
}
38
39
// NOLINTNEXTLINE(runtime/references)
40
8866
inline void builderAppend(StringBuilder& builder, const char* value,
41
                          size_t length) {
42
8866
  builder.write(value, length);
43
8866
}
44
45
// NOLINTNEXTLINE(runtime/references)
46
8862
inline void builderAppend(StringBuilder& builder, const char* value) {
47
8862
  builderAppend(builder, value, std::strlen(value));
48
8862
}
49
50
// NOLINTNEXTLINE(runtime/references)
51
134
inline void builderAppend(StringBuilder& builder, const String& string) {
52
134
  builder << string;
53
134
}
54
55
// NOLINTNEXTLINE(runtime/references)
56
57516
inline void builderReserve(StringBuilder& builder, size_t) {
57
  // ostringstream does not have a counterpart
58
57516
}
59
17
inline String substring(const String& string, size_t start, size_t count) {
60
17
  return string.substr(start, count);
61
}
62
21
inline String fromInteger(int n) {
63
21
  return std::to_string(n);
64
}
65
57517
inline String builderToString(const StringBuilder& builder) {
66
57517
  return builder.str();
67
}
68
17
inline size_t find(const String& string, const char* substring) {
69
17
  return string.find(substring);
70
}
71
String fromDouble(double d);
72
double toDouble(const char* buffer, size_t length, bool* ok);
73
74
String StringViewToUtf8(v8_inspector::StringView view);
75
76
// NOLINTNEXTLINE(runtime/references)
77
void builderAppendQuotedString(StringBuilder& builder, const String&);
78
std::unique_ptr<Value> parseJSON(const String&);
79
std::unique_ptr<Value> parseJSON(v8_inspector::StringView view);
80
81
std::unique_ptr<Value> parseMessage(const std::string& message, bool binary);
82
ProtocolMessage jsonToMessage(String message);
83
ProtocolMessage binaryToMessage(std::vector<uint8_t> message);
84
String fromUTF8(const uint8_t* data, size_t length);
85
86
extern size_t kNotFound;
87
}  // namespace StringUtil
88
89
// A read-only sequence of uninterpreted bytes with reference-counted storage.
90
// Though the templates for generating the protocol bindings reference
91
// this type, js_protocol.pdl doesn't have a field of type 'binary', so
92
// therefore it's unnecessary to provide an implementation here.
93
class Binary {
94
 public:
95
  const uint8_t* data() const { UNREACHABLE(); }
96
  size_t size() const { UNREACHABLE(); }
97
  String toBase64() const { UNREACHABLE(); }
98
  static Binary fromBase64(const String& base64, bool* success) {
99
    UNREACHABLE();
100
  }
101
  static Binary fromSpan(const uint8_t* data, size_t size) { UNREACHABLE(); }
102
};
103
104
}  // namespace protocol
105
}  // namespace inspector
106
}  // namespace node
107
108
#endif  // SRC_INSPECTOR_NODE_STRING_H_