8
8
#include " node_version.h"
9
9
#include " v8-platform.h"
10
10
#include " util.h"
11
+ #include " zlib.h"
11
12
12
13
#include " platform/v8_inspector/public/InspectorVersion.h"
13
14
#include " platform/v8_inspector/public/V8Inspector.h"
@@ -41,6 +42,10 @@ const char TAG_DISCONNECT[] = "#disconnect";
41
42
const char DEVTOOLS_PATH[] = " /node" ;
42
43
const char DEVTOOLS_HASH[] = V8_INSPECTOR_REVISION;
43
44
45
+ static const uint8_t PROTOCOL_JSON[] = {
46
+ #include " v8_inspector_protocol_json.h" // NOLINT(build/include_order)
47
+ };
48
+
44
49
void PrintDebuggerReadyMessage (int port) {
45
50
fprintf (stderr, " Debugger listening on port %d.\n "
46
51
" Warning: This is an experimental feature and could change at any time.\n "
@@ -161,6 +166,27 @@ void SendTargentsListResponse(InspectorSocket* socket,
161
166
SendHttpResponse (socket, buffer.data (), len);
162
167
}
163
168
169
+ void SendProtocolJson (InspectorSocket* socket) {
170
+ z_stream strm;
171
+ strm.zalloc = Z_NULL;
172
+ strm.zfree = Z_NULL;
173
+ strm.opaque = Z_NULL;
174
+ CHECK_EQ (Z_OK, inflateInit (&strm));
175
+ static const size_t kDecompressedSize =
176
+ PROTOCOL_JSON[0 ] * 0x10000u +
177
+ PROTOCOL_JSON[1 ] * 0x100u +
178
+ PROTOCOL_JSON[2 ];
179
+ strm.next_in = PROTOCOL_JSON + 3 ;
180
+ strm.avail_in = sizeof (PROTOCOL_JSON) - 3 ;
181
+ std::vector<char > data (kDecompressedSize );
182
+ strm.next_out = reinterpret_cast <Byte *>(&data[0 ]);
183
+ strm.avail_out = data.size ();
184
+ CHECK_EQ (Z_STREAM_END, inflate (&strm, Z_FINISH));
185
+ CHECK_EQ (0 , strm.avail_out );
186
+ CHECK_EQ (Z_OK, inflateEnd (&strm));
187
+ SendHttpResponse (socket, &data[0 ], data.size ());
188
+ }
189
+
164
190
const char * match_path_segment (const char * path, const char * expected) {
165
191
size_t len = strlen (expected);
166
192
if (StringEqualNoCaseN (path, expected, len)) {
@@ -179,6 +205,8 @@ bool RespondToGet(InspectorSocket* socket, const std::string& script_name_,
179
205
180
206
if (match_path_segment (command, " list" ) || command[0 ] == ' \0 ' ) {
181
207
SendTargentsListResponse (socket, script_name_, script_path_, port);
208
+ } else if (match_path_segment (command, " protocol" )) {
209
+ SendProtocolJson (socket);
182
210
} else if (match_path_segment (command, " version" )) {
183
211
SendVersionResponse (socket);
184
212
} else {
0 commit comments