Skip to content

Commit 4819296

Browse files
pavelfeldmanBethGriggs
authored andcommitted
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 680ef36 commit 4819296

35 files changed

+2544
-274
lines changed

‎src/inspector/node_inspector.gypi‎

Lines changed: 4 additions & 4 deletions
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': [
@@ -86,7 +86,7 @@
8686
],
8787
'action': [
8888
'python',
89-
'tools/inspector_protocol/ConvertProtocolToJSON.py',
89+
'tools/inspector_protocol/convert_protocol_to_json.py',
9090
'<@(_inputs)',
9191
'<@(_outputs)',
9292
],
@@ -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‎

Lines changed: 22 additions & 0 deletions
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+
returnValue::parseBinary(
91+
reinterpret_cast<constuint8_t*>(message.data()),
92+
message.length());
93+
}
94+
returnparseJSON(message);
95+
}
96+
97+
ProtocolMessage jsonToMessage(String message){
98+
return message;
99+
}
100+
101+
ProtocolMessage binaryToMessage(std::vector<uint8_t> message){
102+
returnstd::string(reinterpret_cast<constchar*>(message.data()),
103+
message.size());
104+
}
105+
106+
String fromUTF8(constuint8_t* data, size_t length){
107+
returnstd::string(reinterpret_cast<constchar*>(data), length);
108+
}
109+
88110
} // namespace StringUtil
89111
} // namespace protocol
90112
} // namespace inspector

‎src/inspector/node_string.h‎

Lines changed: 32 additions & 0 deletions
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+
classStringUTF8Adapter{
24+
public:
25+
explicitStringUTF8Adapter(const std::string& string) : string_(string){}
26+
constchar* Data() const{return string_.data()}
27+
size_tlength() const{return string_.length()}
28+
29+
private:
30+
const std::string& string_;
31+
};
2132

2233
namespaceStringUtil{
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(constuint8_t* data, size_t length);
85+
7086
externsize_tkNotFound;
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+
classBinary{
94+
public:
95+
constuint8_t* data() const{UNREACHABLE()}
96+
size_tsize() const{UNREACHABLE()}
97+
String toBase64() const{UNREACHABLE()}
98+
static Binary fromBase64(const String& base64, bool* success){
99+
UNREACHABLE();
100+
}
101+
static Binary fromSpan(constuint8_t* data, size_t size){UNREACHABLE()}
102+
};
103+
72104
} // namespace protocol
73105
} // namespace inspector
74106
} // namespace node

‎src/inspector_agent.cc‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,19 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
229229
}
230230

231231
std::string dispatchProtocolMessage(const StringView& message){
232-
std::unique_ptr<protocol::DictionaryValue> parsed;
232+
std::string raw_message = protocol::StringUtil::StringViewToUtf8(message);
233+
std::unique_ptr<protocol::DictionaryValue> value =
234+
protocol::DictionaryValue::cast(protocol::StringUtil::parseMessage(
235+
raw_message, false));
236+
int call_id;
233237
std::string method;
234-
node_dispatcher_->getCommandName(
235-
protocol::StringUtil::StringViewToUtf8(message), &method, &parsed);
238+
node_dispatcher_->parseCommand(value.get(), &call_id, &method);
236239
if (v8_inspector::V8InspectorSession::canDispatchMethod(
237240
Utf8ToStringView(method)->string())){
238241
session_->dispatchProtocolMessage(message);
239242
} else{
240-
node_dispatcher_->dispatch(std::move(parsed));
243+
node_dispatcher_->dispatch(call_id, method, std::move(value),
244+
raw_message);
241245
}
242246
return method;
243247
}
@@ -277,11 +281,17 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
277281

278282
voidsendProtocolResponse(int callId,
279283
std::unique_ptr<Serializable> message) override{
280-
sendMessageToFrontend(message->serialize());
284+
sendMessageToFrontend(message->serializeToJSON());
281285
}
282286
voidsendProtocolNotification(
283287
std::unique_ptr<Serializable> message) override{
284-
sendMessageToFrontend(message->serialize());
288+
sendMessageToFrontend(message->serializeToJSON());
289+
}
290+
291+
voidfallThrough(int callId,
292+
const std::string& method,
293+
const std::string& message) override{
294+
DCHECK(false);
285295
}
286296

287297
std::unique_ptr<protocol::TracingAgent> tracing_agent_;
Lines changed: 1 addition & 1 deletion
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 renamed to tools/inspector_protocol/check_protocol_compatibility.py

Lines changed: 13 additions & 4 deletions
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__ importprint_function
4849
importcopy
4950
importos.path
5051
importoptparse
5152
importsys
5253

54+
importpdl
55+
5356
try:
5457
importjson
5558
exceptImportError:
@@ -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"andbase_type_2=="binary") or
174+
(base_type_2=="string"andbase_type_1=="binary")):
175+
return
176+
169177
ifbase_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
elifbase_type_1=="object":
@@ -228,8 +236,8 @@ def load_schema(file_name, domains):
228236
ifnotos.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
returnparsed_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
returnversion
427436

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

474483
ifarg_options.stamp:
475484
withopen(arg_options.stamp, 'a') as_:

0 commit comments

Comments
(0)