Skip to content

Commit 6f6942d

Browse files
powdercloudCommit Bot
authored andcommitted
[DevTools] Roll inspector_protocol (v8)
New revision: d2fc9b958e1eeb1e956f3e2208afa9923bdc9b67 To roll this I need to update some call sites; this is because the Serializable interface is changing. Upstream change / review was here: https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1879870 Change-Id: I93c4747609c6003baf1c160a68b8fb6bb07ac565 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1879519 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Johannes Henkel <johannes@chromium.org> Cr-Commit-Position: refs/heads/master@{#64618}
1 parent 6b70b09 commit 6f6942d

10 files changed

Lines changed: 79 additions & 56 deletions

src/inspector/v8-inspector-session-impl.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protocol::DictionaryValue* V8InspectorSessionImpl::agentState(
163163

164164
std::unique_ptr<StringBuffer> V8InspectorSessionImpl::serializeForFrontend(
165165
std::unique_ptr<protocol::Serializable> message) {
166-
std::vector<uint8_t> cbor = message->serializeToBinary();
166+
std::vector<uint8_t> cbor = std::move(*message).TakeSerialized();
167167
if (use_binary_protocol_)
168168
return std::unique_ptr<StringBuffer>(
169169
new BinaryStringBuffer(std::move(cbor)));
@@ -366,9 +366,7 @@ void V8InspectorSessionImpl::dispatchProtocolMessage(
366366
}
367367

368368
std::vector<uint8_t> V8InspectorSessionImpl::state() {
369-
std::vector<uint8_t> out;
370-
m_state->writeBinary(&out);
371-
return out;
369+
return std::move(*m_state).TakeSerialized();
372370
}
373371

374372
std::vector<std::unique_ptr<protocol::Schema::API::Domain>>

third_party/inspector_protocol/README.v8

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: bbc72612409377752c8fd2e7a63a1a5947b7dc4b
5+
Revision: d2fc9b958e1eeb1e956f3e2208afa9923bdc9b67
66
License: BSD
77
License File: LICENSE
88
Security Critical: no

third_party/inspector_protocol/lib/DispatcherBase_cpp.template

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ public:
142142
return std::unique_ptr<ProtocolError>(new ProtocolError(code, errorMessage));
143143
}
144144

145-
std::vector<uint8_t> serializeToBinary() override
145+
void AppendSerialized(std::vector<uint8_t>* out) const override
146146
{
147-
return serialize()->serializeToBinary();
147+
toDictionary()->AppendSerialized(out);
148148
}
149149

150150
~ProtocolError() override {}
@@ -156,7 +156,7 @@ private:
156156
{
157157
}
158158

159-
std::unique_ptr<DictionaryValue> serialize() {
159+
std::unique_ptr<DictionaryValue> toDictionary() const {
160160
std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create();
161161
error->setInteger("code", m_code);
162162
error->setString("message", m_errorMessage);
@@ -299,13 +299,13 @@ UberDispatcher::~UberDispatcher() = default;
299299
// static
300300
std::unique_ptr<Serializable> InternalResponse::createResponse(int callId, std::unique_ptr<Serializable> params)
301301
{
302-
return std::unique_ptr<Serializable>(new InternalResponse(callId, String(), std::move(params)));
302+
return std::unique_ptr<Serializable>(new InternalResponse(callId, nullptr, std::move(params)));
303303
}
304304

305305
// static
306-
std::unique_ptr<Serializable> InternalResponse::createNotification(const String& notification, std::unique_ptr<Serializable> params)
306+
std::unique_ptr<Serializable> InternalResponse::createNotification(const char* method, std::unique_ptr<Serializable> params)
307307
{
308-
return std::unique_ptr<Serializable>(new InternalResponse(0, notification, std::move(params)));
308+
return std::unique_ptr<Serializable>(new InternalResponse(0, method, std::move(params)));
309309
}
310310

311311
// static
@@ -314,23 +314,39 @@ std::unique_ptr<Serializable> InternalResponse::createErrorResponse(int callId,
314314
return ProtocolError::createErrorResponse(callId, code, message, nullptr);
315315
}
316316

317-
std::vector<uint8_t> InternalResponse::serializeToBinary()
317+
void InternalResponse::AppendSerialized(std::vector<uint8_t>* out) const
318318
{
319-
std::unique_ptr<DictionaryValue> result = DictionaryValue::create();
320-
std::unique_ptr<Serializable> params(m_params ? std::move(m_params) : DictionaryValue::create());
321-
if (m_notification.length()) {
322-
result->setString("method", m_notification);
323-
result->setValue("params", SerializedValue::fromBinary(params->serializeToBinary()));
319+
using {{config.encoding_lib.namespace}}::cbor::NewCBOREncoder;
320+
using {{config.encoding_lib.namespace}}::StreamingParserHandler;
321+
using {{config.encoding_lib.namespace}}::Status;
322+
using {{config.encoding_lib.namespace}}::SpanFrom;
323+
324+
Status status;
325+
std::unique_ptr<StreamingParserHandler> encoder =
326+
NewCBOREncoder(out, &status);
327+
encoder->HandleMapBegin();
328+
if (m_method) {
329+
encoder->HandleString8(SpanFrom("method"));
330+
encoder->HandleString8(SpanFrom(m_method));
331+
encoder->HandleString8(SpanFrom("params"));
324332
} else {
325-
result->setInteger("id", m_callId);
326-
result->setValue("result", SerializedValue::fromBinary(params->serializeToBinary()));
333+
encoder->HandleString8(SpanFrom("id"));
334+
encoder->HandleInt32(m_callId);
335+
encoder->HandleString8(SpanFrom("result"));
327336
}
328-
return result->serializeToBinary();
337+
if (m_params) {
338+
m_params->AppendSerialized(out);
339+
} else {
340+
encoder->HandleMapBegin();
341+
encoder->HandleMapEnd();
342+
}
343+
encoder->HandleMapEnd();
344+
DCHECK(status.ok());
329345
}
330346

331-
InternalResponse::InternalResponse(int callId, const String& notification, std::unique_ptr<Serializable> params)
347+
InternalResponse::InternalResponse(int callId, const char* method, std::unique_ptr<Serializable> params)
332348
: m_callId(callId)
333-
, m_notification(notification)
349+
, m_method(method)
334350
, m_params(params ? std::move(params) : nullptr)
335351
{
336352
}

third_party/inspector_protocol/lib/DispatcherBase_h.template

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,18 @@ class InternalResponse : public Serializable {
129129
PROTOCOL_DISALLOW_COPY(InternalResponse);
130130
public:
131131
static std::unique_ptr<Serializable> createResponse(int callId, std::unique_ptr<Serializable> params);
132-
static std::unique_ptr<Serializable> createNotification(const String& notification, std::unique_ptr<Serializable> params = nullptr);
132+
static std::unique_ptr<Serializable> createNotification(const char* method, std::unique_ptr<Serializable> params = nullptr);
133133
static std::unique_ptr<Serializable> createErrorResponse(int callId, DispatchResponse::ErrorCode code, const String& message);
134134

135-
std::vector<uint8_t> serializeToBinary() override;
135+
void AppendSerialized(std::vector<uint8_t>* out) const override;
136136

137137
~InternalResponse() override {}
138138

139139
private:
140-
InternalResponse(int callId, const String& notification, std::unique_ptr<Serializable> params);
140+
InternalResponse(int callId, const char* method, std::unique_ptr<Serializable> params);
141141

142142
int m_callId;
143-
String m_notification;
143+
const char* m_method = nullptr;
144144
std::unique_ptr<Serializable> m_params;
145145
};
146146

@@ -153,11 +153,15 @@ public:
153153

154154
~InternalRawNotification() override {}
155155

156-
std::vector<uint8_t> serializeToBinary() override
157-
{
156+
std::vector<uint8_t> TakeSerialized() && override {
158157
return std::move(m_binaryNotification);
159158
}
160159

160+
void AppendSerialized(std::vector<uint8_t>* out) const override
161+
{
162+
out->insert(out->end(), m_binaryNotification.begin(), m_binaryNotification.end());
163+
}
164+
161165
private:
162166
explicit InternalRawNotification(std::vector<uint8_t> notification)
163167
: m_binaryNotification(std::move(notification)) { }

third_party/inspector_protocol/lib/FrontendChannel_h.template

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ namespace {{namespace}} {
1313

1414
class {{config.lib.export_macro}} Serializable {
1515
public:
16-
virtual std::vector<uint8_t> serializeToBinary() = 0;
16+
virtual std::vector<uint8_t> TakeSerialized() && {
17+
std::vector<uint8_t> out;
18+
AppendSerialized(&out);
19+
return out;
20+
}
21+
virtual void AppendSerialized(std::vector<uint8_t>* out) const = 0;
1722
virtual ~Serializable() = default;
1823
};
1924

third_party/inspector_protocol/lib/Values_cpp.template

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void Value::writeJSON(StringBuilder* output) const
281281
StringUtil::builderAppend(*output, nullValueString, 4);
282282
}
283283

284-
void Value::writeBinary(std::vector<uint8_t>* bytes) const {
284+
void Value::AppendSerialized(std::vector<uint8_t>* bytes) const {
285285
DCHECK(m_type == TypeNull);
286286
bytes->push_back(cbor::EncodeNull());
287287
}
@@ -299,12 +299,6 @@ String Value::toJSONString() const
299299
return StringUtil::builderToString(result);
300300
}
301301

302-
std::vector<uint8_t> Value::serializeToBinary() {
303-
std::vector<uint8_t> bytes;
304-
writeBinary(&bytes);
305-
return bytes;
306-
}
307-
308302
bool FundamentalValue::asBoolean(bool* output) const
309303
{
310304
if (type() != TypeBoolean)
@@ -353,7 +347,7 @@ void FundamentalValue::writeJSON(StringBuilder* output) const
353347
}
354348
}
355349

356-
void FundamentalValue::writeBinary(std::vector<uint8_t>* bytes) const {
350+
void FundamentalValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
357351
switch (type()) {
358352
case TypeDouble:
359353
cbor::EncodeDouble(m_doubleValue, bytes);
@@ -422,7 +416,7 @@ void EncodeString(const String& s, std::vector<uint8_t>* out) {
422416
}
423417
} // namespace
424418

425-
void StringValue::writeBinary(std::vector<uint8_t>* bytes) const {
419+
void StringValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
426420
EncodeString(m_stringValue, bytes);
427421
}
428422

@@ -443,7 +437,7 @@ void BinaryValue::writeJSON(StringBuilder* output) const
443437
StringUtil::builderAppendQuotedString(*output, m_binaryValue.toBase64());
444438
}
445439

446-
void BinaryValue::writeBinary(std::vector<uint8_t>* bytes) const {
440+
void BinaryValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
447441
cbor::EncodeBinary(span<uint8_t>(m_binaryValue.data(),
448442
m_binaryValue.size()), bytes);
449443
}
@@ -459,7 +453,11 @@ void SerializedValue::writeJSON(StringBuilder* output) const
459453
StringUtil::builderAppend(*output, m_serializedJSON);
460454
}
461455

462-
void SerializedValue::writeBinary(std::vector<uint8_t>* output) const
456+
std::vector<uint8_t> SerializedValue::TakeSerialized() && {
457+
return std::move(m_serializedBinary);
458+
}
459+
460+
void SerializedValue::AppendSerialized(std::vector<uint8_t>* output) const
463461
{
464462
DCHECK(type() == TypeSerialized);
465463
output->insert(output->end(), m_serializedBinary.begin(), m_serializedBinary.end());
@@ -607,7 +605,7 @@ void DictionaryValue::writeJSON(StringBuilder* output) const
607605
StringUtil::builderAppend(*output, '}');
608606
}
609607

610-
void DictionaryValue::writeBinary(std::vector<uint8_t>* bytes) const {
608+
void DictionaryValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
611609
cbor::EnvelopeEncoder encoder;
612610
encoder.EncodeStart(bytes);
613611
bytes->push_back(cbor::EncodeIndefiniteLengthMapStart());
@@ -616,7 +614,7 @@ void DictionaryValue::writeBinary(std::vector<uint8_t>* bytes) const {
616614
Dictionary::const_iterator value = m_data.find(key);
617615
DCHECK(value != m_data.cend() && value->second);
618616
EncodeString(key, bytes);
619-
value->second->writeBinary(bytes);
617+
value->second->AppendSerialized(bytes);
620618
}
621619
bytes->push_back(cbor::EncodeStop());
622620
encoder.EncodeStop(bytes);
@@ -656,12 +654,12 @@ void ListValue::writeJSON(StringBuilder* output) const
656654
StringUtil::builderAppend(*output, ']');
657655
}
658656

659-
void ListValue::writeBinary(std::vector<uint8_t>* bytes) const {
657+
void ListValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
660658
cbor::EnvelopeEncoder encoder;
661659
encoder.EncodeStart(bytes);
662660
bytes->push_back(cbor::EncodeIndefiniteLengthArrayStart());
663661
for (size_t i = 0; i < m_data.size(); ++i) {
664-
m_data[i]->writeBinary(bytes);
662+
m_data[i]->AppendSerialized(bytes);
665663
}
666664
bytes->push_back(cbor::EncodeStop());
667665
encoder.EncodeStop(bytes);

third_party/inspector_protocol/lib/Values_h.template

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ public:
5454
virtual bool asBinary(Binary* output) const;
5555

5656
virtual void writeJSON(StringBuilder* output) const;
57-
virtual void writeBinary(std::vector<uint8_t>* bytes) const;
57+
virtual void AppendSerialized(std::vector<uint8_t>* bytes) const override;
5858
virtual std::unique_ptr<Value> clone() const;
5959
String toJSONString() const;
60-
std::vector<uint8_t> serializeToBinary() override;
6160

6261
protected:
6362
Value() : m_type(TypeNull) { }
@@ -91,7 +90,7 @@ public:
9190
bool asDouble(double* output) const override;
9291
bool asInteger(int* output) const override;
9392
void writeJSON(StringBuilder* output) const override;
94-
void writeBinary(std::vector<uint8_t>* bytes) const override;
93+
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
9594
std::unique_ptr<Value> clone() const override;
9695

9796
private:
@@ -120,7 +119,7 @@ public:
120119

121120
bool asString(String* output) const override;
122121
void writeJSON(StringBuilder* output) const override;
123-
void writeBinary(std::vector<uint8_t>* bytes) const override;
122+
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
124123
std::unique_ptr<Value> clone() const override;
125124

126125
private:
@@ -139,7 +138,7 @@ public:
139138

140139
bool asBinary(Binary* output) const override;
141140
void writeJSON(StringBuilder* output) const override;
142-
void writeBinary(std::vector<uint8_t>* bytes) const override;
141+
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
143142
std::unique_ptr<Value> clone() const override;
144143

145144
private:
@@ -161,7 +160,8 @@ public:
161160
}
162161

163162
void writeJSON(StringBuilder* output) const override;
164-
void writeBinary(std::vector<uint8_t>* bytes) const override;
163+
std::vector<uint8_t> TakeSerialized() && override;
164+
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
165165
std::unique_ptr<Value> clone() const override;
166166

167167
private:
@@ -194,7 +194,7 @@ public:
194194
}
195195

196196
void writeJSON(StringBuilder* output) const override;
197-
void writeBinary(std::vector<uint8_t>* bytes) const override;
197+
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
198198
std::unique_ptr<Value> clone() const override;
199199

200200
size_t size() const { return m_data.size(); }
@@ -263,7 +263,7 @@ public:
263263
~ListValue() override;
264264

265265
void writeJSON(StringBuilder* output) const override;
266-
void writeBinary(std::vector<uint8_t>* bytes) const override;
266+
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
267267
std::unique_ptr<Value> clone() const override;
268268

269269
void pushValue(std::unique_ptr<Value>);

third_party/inspector_protocol/templates/Imported_h.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public:
3434
String local_json = ({{config.imported.from_imported_string % "std::move(json)"}});
3535
StringUtil::builderAppend(*output, local_json);
3636
}
37-
void writeBinary(std::vector<uint8_t>* output) const override {
37+
void AppendSerialized(std::vector<uint8_t>* output) const override {
3838
m_exported->writeBinary(output);
3939
}
4040
std::unique_ptr<Value> clone() const override {
@@ -61,7 +61,7 @@ struct ValueConversions<{{"::".join(config.imported.namespace)}}::{{domain.domai
6161
}
6262

6363
std::vector<uint8_t> binary;
64-
value->writeBinary(&binary);
64+
value->AppendSerialized(&binary);
6565
auto result = {{"::".join(config.imported.namespace)}}::{{domain.domain}}::API::{{type.id}}::fromBinary(binary.data(), binary.size());
6666
if (!result)
6767
errors->addError("cannot parse");

third_party/inspector_protocol/templates/TypeBuilder_cpp.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const
107107

108108
void {{type.id}}::writeBinary(std::vector<uint8_t>* out) const
109109
{
110-
toValue()->writeBinary(out);
110+
toValue()->AppendSerialized(out);
111111
}
112112

113113
// static

third_party/inspector_protocol/templates/TypeBuilder_h.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ public:
100100
{% endfor %}
101101

102102
std::unique_ptr<protocol::DictionaryValue> toValue() const;
103-
std::vector<uint8_t> serializeToBinary() override { return toValue()->serializeToBinary(); }
103+
void AppendSerialized(std::vector<uint8_t>* out) const override {
104+
toValue()->AppendSerialized(out);
105+
}
104106
String toJSON() const { return toValue()->toJSONString(); }
105107
std::unique_ptr<{{type.id}}> clone() const;
106108
{% if protocol.is_exported(domain.domain, type.id) %}

0 commit comments

Comments
 (0)