Commit f6a76fad authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector protocol (Cleanup) (V8)

New revision: 4c2a3acaea9f2e7958081dd361f81e20e9eff5e7

This cleanup cl does not change any behavior, it just
cleans up some headers and does a class rename
(StreamingParserHandler->ParserHandler). It was reviewed
upstream
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1924792
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1925679
and does not touch V8 code. Would like to get
this in to make it easier to review subsequent changes.

Thanks!

Change-Id: Ie9fe1434bafeb4f5090244f823d1e482ff805dd0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1925721
Auto-Submit: Johannes Henkel <johannes@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65106}
parent 316036bc
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: d020a9e614d4a5116a7c71f288c0340e282e1a6e
Revision: 4c2a3acaea9f2e7958081dd361f81e20e9eff5e7
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -114,7 +114,7 @@ def read_config():
".lib.export_header": False,
".crdtp": False,
".crdtp.dir": os.path.join(inspector_protocol_dir, "crdtp"),
".crdtp.namespace": "inspector_protocol",
".crdtp.namespace": "crdtp",
}
for key_value in config_values:
parts = key_value.split("=")
......
......@@ -451,7 +451,7 @@ bool EnvelopeEncoder::EncodeStop(std::string* out) {
namespace {
template <typename C>
class CBOREncoder : public StreamingParserHandler {
class CBOREncoder : public ParserHandler {
public:
CBOREncoder(C* out, Status* status) : out_(out), status_(status) {
*status_ = Status();
......@@ -557,16 +557,14 @@ class CBOREncoder : public StreamingParserHandler {
};
} // namespace
std::unique_ptr<StreamingParserHandler> NewCBOREncoder(
std::vector<uint8_t>* out,
Status* status) {
return std::unique_ptr<StreamingParserHandler>(
std::unique_ptr<ParserHandler> NewCBOREncoder(std::vector<uint8_t>* out,
Status* status) {
return std::unique_ptr<ParserHandler>(
new CBOREncoder<std::vector<uint8_t>>(out, status));
}
std::unique_ptr<StreamingParserHandler> NewCBOREncoder(std::string* out,
Status* status) {
return std::unique_ptr<StreamingParserHandler>(
std::unique_ptr<ParserHandler> NewCBOREncoder(std::string* out,
Status* status) {
return std::unique_ptr<ParserHandler>(
new CBOREncoder<std::string>(out, status));
}
......@@ -870,21 +868,18 @@ static constexpr int kStackLimit = 300;
// to roundtrip JSON messages.
bool ParseMap(int32_t stack_depth,
CBORTokenizer* tokenizer,
StreamingParserHandler* out);
ParserHandler* out);
bool ParseArray(int32_t stack_depth,
CBORTokenizer* tokenizer,
StreamingParserHandler* out);
ParserHandler* out);
bool ParseValue(int32_t stack_depth,
CBORTokenizer* tokenizer,
StreamingParserHandler* out);
ParserHandler* out);
bool ParseEnvelope(int32_t stack_depth,
CBORTokenizer* tokenizer,
StreamingParserHandler* out);
ParserHandler* out);
void ParseUTF16String(CBORTokenizer* tokenizer, StreamingParserHandler* out) {
void ParseUTF16String(CBORTokenizer* tokenizer, ParserHandler* out) {
std::vector<uint16_t> value;
span<uint8_t> rep = tokenizer->GetString16WireRep();
for (size_t ii = 0; ii < rep.size(); ii += 2)
......@@ -893,7 +888,7 @@ void ParseUTF16String(CBORTokenizer* tokenizer, StreamingParserHandler* out) {
tokenizer->Next();
}
bool ParseUTF8String(CBORTokenizer* tokenizer, StreamingParserHandler* out) {
bool ParseUTF8String(CBORTokenizer* tokenizer, ParserHandler* out) {
assert(tokenizer->TokenTag() == CBORTokenTag::STRING8);
out->HandleString8(tokenizer->GetString8());
tokenizer->Next();
......@@ -902,7 +897,7 @@ bool ParseUTF8String(CBORTokenizer* tokenizer, StreamingParserHandler* out) {
bool ParseEnvelope(int32_t stack_depth,
CBORTokenizer* tokenizer,
StreamingParserHandler* out) {
ParserHandler* out) {
assert(tokenizer->TokenTag() == CBORTokenTag::ENVELOPE);
// Before we enter the envelope, we save the position that we
// expect to see after we're done parsing the envelope contents.
......@@ -948,7 +943,7 @@ bool ParseEnvelope(int32_t stack_depth,
bool ParseValue(int32_t stack_depth,
CBORTokenizer* tokenizer,
StreamingParserHandler* out) {
ParserHandler* out) {
if (stack_depth > kStackLimit) {
out->HandleError(
Status{Error::CBOR_STACK_LIMIT_EXCEEDED, tokenizer->Status().pos});
......@@ -1010,7 +1005,7 @@ bool ParseValue(int32_t stack_depth,
// detected.
bool ParseArray(int32_t stack_depth,
CBORTokenizer* tokenizer,
StreamingParserHandler* out) {
ParserHandler* out) {
assert(tokenizer->TokenTag() == CBORTokenTag::ARRAY_START);
tokenizer->Next();
out->HandleArrayBegin();
......@@ -1038,7 +1033,7 @@ bool ParseArray(int32_t stack_depth,
// detected.
bool ParseMap(int32_t stack_depth,
CBORTokenizer* tokenizer,
StreamingParserHandler* out) {
ParserHandler* out) {
assert(tokenizer->TokenTag() == CBORTokenTag::MAP_START);
out->HandleMapBegin();
tokenizer->Next();
......@@ -1073,7 +1068,7 @@ bool ParseMap(int32_t stack_depth,
}
} // namespace
void ParseCBOR(span<uint8_t> bytes, StreamingParserHandler* out) {
void ParseCBOR(span<uint8_t> bytes, ParserHandler* out) {
if (bytes.empty()) {
out->HandleError(Status{Error::CBOR_NO_INPUT, 0});
return;
......
......@@ -5,11 +5,8 @@
#ifndef V8_CRDTP_CBOR_H_
#define V8_CRDTP_CBOR_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
......@@ -140,11 +137,9 @@ class EnvelopeEncoder {
// that drives it. The handler will encode into |out|, and iff an error occurs
// it will set |status| to an error and clear |out|. Otherwise, |status.ok()|
// will be |true|.
std::unique_ptr<StreamingParserHandler> NewCBOREncoder(
std::vector<uint8_t>* out,
Status* status);
std::unique_ptr<StreamingParserHandler> NewCBOREncoder(std::string* out,
Status* status);
std::unique_ptr<ParserHandler> NewCBOREncoder(std::vector<uint8_t>* out,
Status* status);
std::unique_ptr<ParserHandler> NewCBOREncoder(std::string* out, Status* status);
// =============================================================================
// cbor::CBORTokenizer - for parsing individual CBOR items
......@@ -283,7 +278,7 @@ class CBORTokenizer {
// |out|. If an error occurs, sends |out->HandleError|, and parsing stops.
// The client is responsible for discarding the already received information in
// that case.
void ParseCBOR(span<uint8_t> bytes, StreamingParserHandler* out);
void ParseCBOR(span<uint8_t> bytes, ParserHandler* out);
// =============================================================================
// cbor::AppendString8EntryToMap - for limited in-place editing of messages
......
......@@ -102,7 +102,7 @@ void Base64Encode(const span<uint8_t>& in, C* out) {
// Implements a handler for JSON parser events to emit a JSON string.
template <typename C>
class JSONEncoder : public StreamingParserHandler {
class JSONEncoder : public ParserHandler {
public:
JSONEncoder(const Platform* platform, C* out, Status* status)
: platform_(platform), out_(out), status_(status) {
......@@ -343,18 +343,17 @@ class JSONEncoder : public StreamingParserHandler {
};
} // namespace
std::unique_ptr<StreamingParserHandler> NewJSONEncoder(
const Platform* platform,
std::vector<uint8_t>* out,
Status* status) {
return std::unique_ptr<StreamingParserHandler>(
std::unique_ptr<ParserHandler> NewJSONEncoder(const Platform* platform,
std::vector<uint8_t>* out,
Status* status) {
return std::unique_ptr<ParserHandler>(
new JSONEncoder<std::vector<uint8_t>>(platform, out, status));
}
std::unique_ptr<StreamingParserHandler> NewJSONEncoder(const Platform* platform,
std::string* out,
Status* status) {
return std::unique_ptr<StreamingParserHandler>(
std::unique_ptr<ParserHandler> NewJSONEncoder(const Platform* platform,
std::string* out,
Status* status) {
return std::unique_ptr<ParserHandler>(
new JSONEncoder<std::string>(platform, out, status));
}
......@@ -388,7 +387,7 @@ const char* const kFalseString = "false";
template <typename Char>
class JsonParser {
public:
JsonParser(const Platform* platform, StreamingParserHandler* handler)
JsonParser(const Platform* platform, ParserHandler* handler)
: platform_(platform), handler_(handler) {}
void Parse(const Char* start, size_t length) {
......@@ -968,20 +967,20 @@ class JsonParser {
const Char* start_pos_ = nullptr;
bool error_ = false;
const Platform* platform_;
StreamingParserHandler* handler_;
ParserHandler* handler_;
};
} // namespace
void ParseJSON(const Platform& platform,
span<uint8_t> chars,
StreamingParserHandler* handler) {
ParserHandler* handler) {
JsonParser<uint8_t> parser(&platform, handler);
parser.Parse(chars.data(), chars.size());
}
void ParseJSON(const Platform& platform,
span<uint16_t> chars,
StreamingParserHandler* handler) {
ParserHandler* handler) {
JsonParser<uint16_t> parser(&platform, handler);
parser.Parse(chars.data(), chars.size());
}
......@@ -994,7 +993,7 @@ Status ConvertCBORToJSONTmpl(const Platform& platform,
span<uint8_t> cbor,
C* json) {
Status status;
std::unique_ptr<StreamingParserHandler> json_writer =
std::unique_ptr<ParserHandler> json_writer =
NewJSONEncoder(&platform, json, &status);
cbor::ParseCBOR(cbor, json_writer.get());
return status;
......@@ -1015,8 +1014,7 @@ Status ConvertCBORToJSON(const Platform& platform,
template <typename T, typename C>
Status ConvertJSONToCBORTmpl(const Platform& platform, span<T> json, C* cbor) {
Status status;
std::unique_ptr<StreamingParserHandler> encoder =
cbor::NewCBOREncoder(cbor, &status);
std::unique_ptr<ParserHandler> encoder = cbor::NewCBOREncoder(cbor, &status);
ParseJSON(platform, json, encoder.get());
return status;
}
......
......@@ -5,14 +5,7 @@
#ifndef V8_CRDTP_JSON_H_
#define V8_CRDTP_JSON_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include "export.h"
#include "json_platform.h"
......@@ -30,13 +23,12 @@ namespace json {
// Except for calling the HandleError routine at any time, the client
// code must call the Handle* methods in an order in which they'd occur
// in valid JSON; otherwise we may crash (the code uses assert).
std::unique_ptr<StreamingParserHandler> NewJSONEncoder(
const Platform* platform,
std::vector<uint8_t>* out,
Status* status);
std::unique_ptr<StreamingParserHandler> NewJSONEncoder(const Platform* platform,
std::string* out,
Status* status);
std::unique_ptr<ParserHandler> NewJSONEncoder(const Platform* platform,
std::vector<uint8_t>* out,
Status* status);
std::unique_ptr<ParserHandler> NewJSONEncoder(const Platform* platform,
std::string* out,
Status* status);
// =============================================================================
// json::ParseJSON - for receiving streaming parser events for JSON
......@@ -44,10 +36,10 @@ std::unique_ptr<StreamingParserHandler> NewJSONEncoder(const Platform* platform,
void ParseJSON(const Platform& platform,
span<uint8_t> chars,
StreamingParserHandler* handler);
ParserHandler* handler);
void ParseJSON(const Platform& platform,
span<uint16_t> chars,
StreamingParserHandler* handler);
ParserHandler* handler);
// =============================================================================
// json::ConvertCBORToJSON, json::ConvertJSONToCBOR - for transcoding
......
......@@ -5,15 +5,7 @@
#ifndef V8_CRDTP_JSON_PLATFORM_H_
#define V8_CRDTP_JSON_PLATFORM_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include "export.h"
namespace v8_crdtp {
......
......@@ -16,8 +16,6 @@
#include "test_platform.h"
using testing::ElementsAreArray;
namespace v8_crdtp {
namespace {
class TestPlatform : public json::Platform {
......@@ -61,14 +59,14 @@ namespace json {
// json::NewJSONEncoder - for encoding streaming parser events as JSON
// =============================================================================
void WriteUTF8AsUTF16(StreamingParserHandler* writer, const std::string& utf8) {
void WriteUTF8AsUTF16(ParserHandler* writer, const std::string& utf8) {
writer->HandleString16(SpanFrom(UTF8ToUTF16(SpanFrom(utf8))));
}
TEST(JsonEncoder, OverlongEncodings) {
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
// We encode 0x7f, which is the DEL ascii character, as a 4 byte UTF8
......@@ -87,7 +85,7 @@ TEST(JsonEncoder, OverlongEncodings) {
TEST(JsonEncoder, IncompleteUtf8Sequence) {
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleArrayBegin(); // This emits [, which starts an array.
......@@ -113,7 +111,7 @@ TEST(JsonEncoder, IncompleteUtf8Sequence) {
TEST(JsonStdStringWriterTest, HelloWorld) {
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleMapBegin();
WriteUTF8AsUTF16(writer.get(), "msg1");
......@@ -157,7 +155,7 @@ TEST(JsonStdStringWriterTest, RepresentingNonFiniteValuesAsNull) {
// So in practice it's mapped to null.
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleMapBegin();
writer->HandleString8(SpanFrom("Infinity"));
......@@ -172,13 +170,13 @@ TEST(JsonStdStringWriterTest, RepresentingNonFiniteValuesAsNull) {
}
TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) {
// The encoder emits binary submitted to StreamingParserHandler::HandleBinary
// The encoder emits binary submitted to ParserHandler::HandleBinary
// as base64. The following three examples are taken from
// https://en.wikipedia.org/wiki/Base64.
{
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M', 'a', 'n'})));
EXPECT_TRUE(status.ok());
......@@ -187,7 +185,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) {
{
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M', 'a'})));
EXPECT_TRUE(status.ok());
......@@ -196,7 +194,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) {
{
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M'})));
EXPECT_TRUE(status.ok());
......@@ -205,7 +203,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) {
{ // "Hello, world.", verified with base64decode.org.
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleBinary(SpanFrom(std::vector<uint8_t>(
{'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '.'})));
......@@ -219,7 +217,7 @@ TEST(JsonStdStringWriterTest, HandlesErrors) {
// status and clears the output.
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleMapBegin();
WriteUTF8AsUTF16(writer.get(), "msg1");
......@@ -257,7 +255,7 @@ TEST(JsonStdStringWriterTest, DoubleToString) {
std::string out;
Status status;
std::unique_ptr<StreamingParserHandler> writer =
std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&platform, &out, &status);
writer->HandleArrayBegin();
writer->HandleDouble(.1);
......@@ -270,7 +268,7 @@ TEST(JsonStdStringWriterTest, DoubleToString) {
// json::ParseJSON - for receiving streaming parser events for JSON
// =============================================================================
class Log : public StreamingParserHandler {
class Log : public ParserHandler {
public:
void HandleMapBegin() override { log_ << "map begin\n"; }
......
......@@ -5,16 +5,7 @@
#ifndef V8_CRDTP_PARSER_HANDLER_H_
#define V8_CRDTP_PARSER_HANDLER_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include "export.h"
#include "span.h"
#include "status.h"
......@@ -22,9 +13,9 @@ namespace v8_crdtp {
// Handler interface for parser events emitted by a streaming parser.
// See cbor::NewCBOREncoder, cbor::ParseCBOR, json::NewJSONEncoder,
// json::ParseJSON.
class StreamingParserHandler {
class ParserHandler {
public:
virtual ~StreamingParserHandler() = default;
virtual ~ParserHandler() = default;
virtual void HandleMapBegin() = 0;
virtual void HandleMapEnd() = 0;
virtual void HandleArrayBegin() = 0;
......
......@@ -6,16 +6,11 @@
#define V8_CRDTP_SPAN_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include "export.h"
namespace v8_crdtp {
// =============================================================================
// span - sequence of bytes
......
......@@ -2,22 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "span.h"
#include <array>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include "span.h"
#include "test_platform.h"
using testing::ElementsAreArray;
namespace v8_crdtp {
// =============================================================================
// span - sequence of bytes
......
......@@ -4,13 +4,6 @@
#include "status.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <limits>
#include <stack>
namespace v8_crdtp {
// =============================================================================
// Status and Error codes
......
......@@ -2,17 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_CRDTP_ENCODING_H_
#define V8_CRDTP_ENCODING_H_
#ifndef V8_CRDTP_STATUS_H_
#define V8_CRDTP_STATUS_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include "export.h"
......@@ -20,6 +15,7 @@ namespace v8_crdtp {
// =============================================================================
// Status and Error codes
// =============================================================================
enum class Error {
OK = 0,
// JSON parsing errors - json_parser.{h,cc}.
......@@ -89,4 +85,4 @@ struct Status {
};
} // namespace v8_crdtp
#endif // V8_CRDTP_ENCODING_H_
#endif // V8_CRDTP_STATUS_H_
......@@ -3,21 +3,8 @@
// found in the LICENSE file.
#include "status.h"
#include <array>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include "test_platform.h"
using testing::ElementsAreArray;
namespace v8_crdtp {
// =============================================================================
// Status and Error codes
......
......@@ -317,13 +317,12 @@ std::unique_ptr<Serializable> InternalResponse::createErrorResponse(int callId,
void InternalResponse::AppendSerialized(std::vector<uint8_t>* out) const
{
using {{config.crdtp.namespace}}::cbor::NewCBOREncoder;
using {{config.crdtp.namespace}}::StreamingParserHandler;
using {{config.crdtp.namespace}}::ParserHandler;
using {{config.crdtp.namespace}}::Status;
using {{config.crdtp.namespace}}::SpanFrom;
Status status;
std::unique_ptr<StreamingParserHandler> encoder =
NewCBOREncoder(out, &status);
std::unique_ptr<ParserHandler> encoder = NewCBOREncoder(out, &status);
encoder->HandleMapBegin();
if (m_method) {
encoder->HandleString8(SpanFrom("method"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment