Skip to content

Commit d775d74

Browse files
pavelfeldmanrefack
authored andcommittedMar 4, 2019
tools: roll inspector_protocol to f67ec5
Fixes: #25808 PR-URL: #26303 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent b2abda9 commit d775d74

35 files changed

+2544
-274
lines changed
 

‎src/inspector/node_inspector.gypi

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'<(protocol_tool_path)/templates/Imported_h.template',
3535
'<(protocol_tool_path)/templates/TypeBuilder_cpp.template',
3636
'<(protocol_tool_path)/templates/TypeBuilder_h.template',
37-
'<(protocol_tool_path)/CodeGenerator.py',
37+
'<(protocol_tool_path)/code_generator.py',
3838
]
3939
},
4040
'defines': [
@@ -87,7 +87,7 @@
8787
],
8888
'action': [
8989
'python',
90-
'tools/inspector_protocol/ConvertProtocolToJSON.py',
90+
'tools/inspector_protocol/convert_protocol_to_json.py',
9191
'<@(_inputs)',
9292
'<@(_outputs)',
9393
],
@@ -105,7 +105,7 @@
105105
'process_outputs_as_sources': 1,
106106
'action': [
107107
'python',
108-
'tools/inspector_protocol/CodeGenerator.py',
108+
'tools/inspector_protocol/code_generator.py',
109109
'--jinja_dir', '<@(protocol_tool_path)/..',
110110
'--output_base', '<(SHARED_INTERMEDIATE_DIR)/src/',
111111
'--config', '<(SHARED_INTERMEDIATE_DIR)/node_protocol_config.json',
@@ -123,7 +123,7 @@
123123
],
124124
'action': [
125125
'python',
126-
'tools/inspector_protocol/ConcatenateProtocols.py',
126+
'tools/inspector_protocol/concatenate_protocols.py',
127127
'<@(_inputs)',
128128
'<@(_outputs)',
129129
],

‎src/inspector/node_string.cc

+22
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,28 @@ double toDouble(const char* buffer, size_t length, bool* ok) {
8585
return d;
8686
}
8787

88+
std::unique_ptr<Value> parseMessage(const std::string& message, bool binary) {
89+
if (binary) {
90+
return Value::parseBinary(
91+
reinterpret_cast<const uint8_t*>(message.data()),
92+
message.length());
93+
}
94+
return parseJSON(message);
95+
}
96+
97+
ProtocolMessage jsonToMessage(String message) {
98+
return message;
99+
}
100+
101+
ProtocolMessage binaryToMessage(std::vector<uint8_t> message) {
102+
return std::string(reinterpret_cast<const char*>(message.data()),
103+
message.size());
104+
}
105+
106+
String fromUTF8(const uint8_t* data, size_t length) {
107+
return std::string(reinterpret_cast<const char*>(data), length);
108+
}
109+
88110
} // namespace StringUtil
89111
} // namespace protocol
90112
} // namespace inspector

‎src/inspector/node_string.h

+32
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ class Value;
1818

1919
using String = std::string;
2020
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+
};
2132

2233
namespace StringUtil {
2334
// NOLINTNEXTLINE(runtime/references) This is V8 API...
@@ -67,8 +78,29 @@ void builderAppendQuotedString(StringBuilder& builder, const String&);
6778
std::unique_ptr<Value> parseJSON(const String&);
6879
std::unique_ptr<Value> parseJSON(v8_inspector::StringView view);
6980

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+
7086
extern size_t kNotFound;
7187
} // 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+
72104
} // namespace protocol
73105
} // namespace inspector
74106
} // namespace node

‎src/inspector_agent.cc

+16-6
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,19 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
236236
}
237237

238238
std::string dispatchProtocolMessage(const StringView& message) {
239-
std::unique_ptr<protocol::DictionaryValue> parsed;
239+
std::string raw_message = protocol::StringUtil::StringViewToUtf8(message);
240+
std::unique_ptr<protocol::DictionaryValue> value =
241+
protocol::DictionaryValue::cast(protocol::StringUtil::parseMessage(
242+
raw_message, false));
243+
int call_id;
240244
std::string method;
241-
node_dispatcher_->getCommandName(
242-
protocol::StringUtil::StringViewToUtf8(message), &method, &parsed);
245+
node_dispatcher_->parseCommand(value.get(), &call_id, &method);
243246
if (v8_inspector::V8InspectorSession::canDispatchMethod(
244247
Utf8ToStringView(method)->string())) {
245248
session_->dispatchProtocolMessage(message);
246249
} else {
247-
node_dispatcher_->dispatch(std::move(parsed));
250+
node_dispatcher_->dispatch(call_id, method, std::move(value),
251+
raw_message);
248252
}
249253
return method;
250254
}
@@ -284,11 +288,17 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
284288

285289
void sendProtocolResponse(int callId,
286290
std::unique_ptr<Serializable> message) override {
287-
sendMessageToFrontend(message->serialize());
291+
sendMessageToFrontend(message->serializeToJSON());
288292
}
289293
void sendProtocolNotification(
290294
std::unique_ptr<Serializable> message) override {
291-
sendMessageToFrontend(message->serialize());
295+
sendMessageToFrontend(message->serializeToJSON());
296+
}
297+
298+
void fallThrough(int callId,
299+
const std::string& method,
300+
const std::string& message) override {
301+
DCHECK(false);
292302
}
293303

294304
std::unique_ptr<protocol::TracingAgent> tracing_agent_;

‎tools/inspector_protocol/README.v8 ‎tools/inspector_protocol/README.node

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Name: inspector protocol
22
Short Name: inspector_protocol
33
URL: https://chromium.googlesource.com/deps/inspector_protocol/
44
Version: 0
5-
Revision: 752d4abd13119010cf30e454e8ef9b5fb7ef43a3
5+
Revision: f67ec5180f476830e839226b5ca948e43070fdab
66
License: BSD
77
License File: LICENSE
88
Security Critical: no

‎tools/inspector_protocol/CheckProtocolCompatibility.py ‎tools/inspector_protocol/check_protocol_compatibility.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@
4545
#
4646
# Adding --show_changes to the command line prints out a list of valid public API changes.
4747

48+
from __future__ import print_function
4849
import copy
4950
import os.path
5051
import optparse
5152
import sys
5253

54+
import pdl
55+
5356
try:
5457
import json
5558
except ImportError:
@@ -166,6 +169,11 @@ def compare_types(context, kind, type_1, type_2, types_map_1, types_map_2, depth
166169
base_type_1 = type_1["type"]
167170
base_type_2 = type_2["type"]
168171

172+
# Binary and string have the same wire representation in JSON.
173+
if ((base_type_1 == "string" and base_type_2 == "binary") or
174+
(base_type_2 == "string" and base_type_1 == "binary")):
175+
return
176+
169177
if base_type_1 != base_type_2:
170178
errors.append("%s: %s base type mismatch, '%s' vs '%s'" % (context, kind, base_type_1, base_type_2))
171179
elif base_type_1 == "object":
@@ -228,8 +236,8 @@ def load_schema(file_name, domains):
228236
if not os.path.isfile(file_name):
229237
return
230238
input_file = open(file_name, "r")
231-
json_string = input_file.read()
232-
parsed_json = json.loads(json_string)
239+
parsed_json = pdl.loads(input_file.read(), file_name)
240+
input_file.close()
233241
domains += parsed_json["domains"]
234242
return parsed_json["version"]
235243

@@ -422,6 +430,7 @@ def load_domains_and_baselines(file_name, domains, baseline_domains):
422430
version = load_schema(os.path.normpath(file_name), domains)
423431
suffix = "-%s.%s.json" % (version["major"], version["minor"])
424432
baseline_file = file_name.replace(".json", suffix)
433+
baseline_file = file_name.replace(".pdl", suffix)
425434
load_schema(os.path.normpath(baseline_file), baseline_domains)
426435
return version
427436

@@ -467,9 +476,9 @@ def main():
467476
if arg_options.show_changes:
468477
changes = compare_schemas(domains, baseline_domains, True)
469478
if len(changes) > 0:
470-
print " Public changes since %s:" % version
479+
print(" Public changes since %s:" % version)
471480
for change in changes:
472-
print " %s" % change
481+
print(" %s" % change)
473482

474483
if arg_options.stamp:
475484
with open(arg_options.stamp, 'a') as _:

0 commit comments

Comments
 (0)
Please sign in to comment.