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

[DevTools] Roll inspector_protocol (v8).

New Revision: 8b7ea912e516a6daa61487c700687a9426e3a396

Update v8 files / build config accordingly.
- There's now a new library in third_party/inspector_protocol,
  bindings/bindings.h, which is configured much like encoding/encoding.h.
  It doesn't have much stuff in it yet, but will soon get more code
  that would otherwise need to go into jinja templates.
  It also comes with a new test, only a smoke test thus far.

Change-Id: I9c00a54a840c214b4bb744a3b272e5ce221954fc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1678273Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62442}
parent 3c4f9bfa
......@@ -67,9 +67,6 @@ config("inspector_config") {
configs = [ "../../:internal_config" ]
include_dirs = [
"../../include",
# For including encoding/encoding.h.
"../../third_party/inspector_protocol",
]
}
......@@ -101,6 +98,7 @@ v8_source_set("inspector") {
":inspector_string_conversions",
"../..:v8_version",
"../../third_party/inspector_protocol:encoding",
"../../third_party/inspector_protocol:bindings",
]
public_deps = [
......
......@@ -47,7 +47,10 @@
},
"encoding_lib": {
"header": "encoding/encoding.h",
"namespace": ["v8_inspector_protocol_encoding"]
"namespace": "v8_inspector_protocol_encoding"
},
"bindings_lib": {
"namespace": "v8_inspector_protocol_bindings"
}
}
......@@ -301,6 +301,7 @@ v8_source_set("unittests_sources") {
"../..:v8_libbase",
"../..:v8_libplatform",
"../../third_party/inspector_protocol:encoding_test",
"../../third_party/inspector_protocol:bindings_test",
"//build/win:default_exe_manifest",
"//testing/gmock",
"//testing/gtest",
......
......@@ -9,6 +9,13 @@ static_library("encoding") {
]
}
static_library("bindings") {
sources = [
"bindings/bindings.cc",
"bindings/bindings.h",
]
}
# encoding_test is part of the unittests, defined in
# test/unittests/BUILD.gn.
......@@ -32,3 +39,23 @@ v8_source_set("encoding_test") {
]
testonly = true
}
v8_source_set("bindings_test") {
sources = [
"bindings/bindings_test.cc",
"bindings/bindings_test_helper.h",
]
configs = [
"../..:external_config",
"../..:internal_config_base",
]
deps = [
":bindings",
"../..:v8_libbase",
"../../src/inspector:inspector_string_conversions",
"//testing/gmock",
"//testing/gtest",
]
testonly = true
}
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 83b1154a9661d22bba9a368d368214cc20880419
Revision: 8b7ea912e516a6daa61487c700687a9426e3a396
License: BSD
License File: LICENSE
Security Critical: no
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "bindings.h"
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_INSPECTOR_PROTOCOL_BINDINGS_BINDINGS_H_
#define V8_INSPECTOR_PROTOCOL_BINDINGS_BINDINGS_H_
#include <cassert>
#include <memory>
namespace v8_inspector_protocol_bindings {
namespace glue {
// =============================================================================
// glue::detail::PtrMaybe, glue::detail::ValueMaybe, templates for optional
// pointers / values which are used in ../lib/Forward_h.template.
// =============================================================================
namespace detail {
template <typename T>
class PtrMaybe {
public:
PtrMaybe() = default;
PtrMaybe(std::unique_ptr<T> value) : value_(std::move(value)) {}
PtrMaybe(PtrMaybe&& other) noexcept : value_(std::move(other.value_)) {}
void operator=(std::unique_ptr<T> value) { value_ = std::move(value); }
T* fromJust() const {
assert(value_);
return value_.get();
}
T* fromMaybe(T* default_value) const {
return value_ ? value_.get() : default_value;
}
bool isJust() const { return value_ != nullptr; }
std::unique_ptr<T> takeJust() {
assert(value_);
return std::move(value_);
}
private:
std::unique_ptr<T> value_;
};
template <typename T>
class ValueMaybe {
public:
ValueMaybe() : is_just_(false), value_() {}
ValueMaybe(T value) : is_just_(true), value_(std::move(value)) {}
ValueMaybe(ValueMaybe&& other) noexcept
: is_just_(other.is_just_), value_(std::move(other.value_)) {}
void operator=(T value) {
value_ = value;
is_just_ = true;
}
const T& fromJust() const {
assert(is_just_);
return value_;
}
const T& fromMaybe(const T& default_value) const {
return is_just_ ? value_ : default_value;
}
bool isJust() const { return is_just_; }
// TODO(johannes): |is_just_| isn't reset by this operation -
// introduce && to ensure avoiding continued usage of |this|?
T takeJust() {
assert(is_just_);
return std::move(value_);
}
private:
bool is_just_;
T value_;
};
} // namespace detail
} // namespace glue
} // namespace v8_inspector_protocol_bindings
#define PROTOCOL_DISALLOW_COPY(ClassName) \
private: \
ClassName(const ClassName&) = delete; \
ClassName& operator=(const ClassName&) = delete
#endif // V8_INSPECTOR_PROTOCOL_BINDINGS_BINDINGS_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "bindings.h"
#include <string>
#include <vector>
#include "bindings_test_helper.h"
namespace v8_inspector_protocol_bindings {
namespace glue {
// =============================================================================
// glue::detail::PtrMaybe, glue::detail::ValueMaybe, templates for optional
// pointers / values which are used in ../lib/Forward_h.template.
// =============================================================================
TEST(PtrMaybeTest, SmokeTest) {
detail::PtrMaybe<std::vector<uint32_t>> example;
EXPECT_FALSE(example.isJust());
EXPECT_TRUE(nullptr == example.fromMaybe(nullptr));
std::unique_ptr<std::vector<uint32_t>> v(new std::vector<uint32_t>);
v->push_back(42);
v->push_back(21);
example = std::move(v);
EXPECT_TRUE(example.isJust());
EXPECT_THAT(*example.fromJust(), testing::ElementsAre(42, 21));
std::unique_ptr<std::vector<uint32_t>> out = example.takeJust();
EXPECT_FALSE(example.isJust());
EXPECT_THAT(*out, testing::ElementsAre(42, 21));
}
TEST(PtrValueTest, SmokeTest) {
detail::ValueMaybe<int32_t> example;
EXPECT_FALSE(example.isJust());
EXPECT_EQ(-1, example.fromMaybe(-1));
example = 42;
EXPECT_TRUE(example.isJust());
EXPECT_EQ(42, example.fromJust());
int32_t out = example.takeJust();
EXPECT_EQ(out, 42);
}
} // namespace glue
} // namespace v8_inspector_protocol_bindings
// Copyright 2019 The V8 Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is V8 specific, to make bindings_test.cc work.
// It is not rolled from the upstream project.
#ifndef V8_INSPECTOR_PROTOCOL_BINDINGS_BINDINGS_TEST_HELPER_H_
#define V8_INSPECTOR_PROTOCOL_BINDINGS_BINDINGS_TEST_HELPER_H_
#include <string>
#include <vector>
#include "src/base/logging.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#endif // V8_INSPECTOR_PROTOCOL_BINDINGS_BINDINGS_TEST_HELPER_H_
......@@ -65,12 +65,14 @@ def read_config():
cmdline_parser.add_argument("--jinja_dir", type=unicode, required=True)
cmdline_parser.add_argument("--config", type=unicode, required=True)
cmdline_parser.add_argument("--config_value", default=[], action="append")
cmdline_parser.add_argument("--inspector_protocol_dir", type=unicode, required=True)
arg_options = cmdline_parser.parse_args()
jinja_dir = arg_options.jinja_dir
output_base = arg_options.output_base
config_file = arg_options.config
config_base = os.path.dirname(config_file)
config_values = arg_options.config_value
inspector_protocol_dir = arg_options.inspector_protocol_dir.lstrip('/')
except Exception:
# Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
exc = sys.exc_info()[1]
......@@ -103,15 +105,12 @@ def read_config():
".lib.export_header": False,
# The encoding lib consists of encoding/encoding.h and
# encoding/encoding.cc in its subdirectory, which binaries
# may link / depend on, instead of relying on the
# JINJA2 templates lib/encoding_{h,cc}.template.
# In that case, |header| identifies the include file
# and |namespace| is the namespace it's using. Usually
# inspector_protocol_encoding but for v8's copy it's
# v8_inspector_protocol_encoding.
# TODO(johannes): Migrate away from lib/encoding_{h,cc}.template
# in favor of this.
".encoding_lib": { "header": "", "namespace": []},
# must link / depend on.
".encoding_lib.header": os.path.join(inspector_protocol_dir, "encoding/encoding.h"),
".encoding_lib.namespace": "",
# Ditto for bindings, see bindings/bindings.h.
".bindings_lib.header": os.path.join(inspector_protocol_dir, "bindings/bindings.h"),
".bindings_lib.namespace": ""
}
for key_value in config_values:
parts = key_value.split("=")
......@@ -635,10 +634,8 @@ def main():
"Values_h.template",
"Object_h.template",
"ValueConversions_h.template",
"Maybe_h.template",
"DispatcherBase_h.template",
"Parser_h.template",
"encoding_h.template",
]
protocol_cpp_templates = [
......@@ -648,12 +645,10 @@ def main():
"Object_cpp.template",
"DispatcherBase_cpp.template",
"Parser_cpp.template",
"encoding_cpp.template",
]
forward_h_templates = [
"Forward_h.template",
"Allocator_h.template",
"FrontendChannel_h.template",
]
......
......@@ -33,16 +33,12 @@ template("inspector_protocol_generate") {
invoker.config_file,
"$inspector_protocol_dir/lib/base_string_adapter_cc.template",
"$inspector_protocol_dir/lib/base_string_adapter_h.template",
"$inspector_protocol_dir/lib/encoding_h.template",
"$inspector_protocol_dir/lib/encoding_cpp.template",
"$inspector_protocol_dir/lib/Allocator_h.template",
"$inspector_protocol_dir/lib/DispatcherBase_cpp.template",
"$inspector_protocol_dir/lib/DispatcherBase_h.template",
"$inspector_protocol_dir/lib/ErrorSupport_cpp.template",
"$inspector_protocol_dir/lib/ErrorSupport_h.template",
"$inspector_protocol_dir/lib/Forward_h.template",
"$inspector_protocol_dir/lib/FrontendChannel_h.template",
"$inspector_protocol_dir/lib/Maybe_h.template",
"$inspector_protocol_dir/lib/Object_cpp.template",
"$inspector_protocol_dir/lib/Object_h.template",
"$inspector_protocol_dir/lib/Parser_cpp.template",
......@@ -67,6 +63,8 @@ template("inspector_protocol_generate") {
rebase_path(invoker.out_dir, root_build_dir),
"--config",
rebase_path(invoker.config_file, root_build_dir),
"--inspector_protocol_dir",
"$inspector_protocol_dir",
]
if (defined(invoker.config_values)) {
......
......@@ -5,16 +5,12 @@
{
'variables': {
'inspector_protocol_files': [
'lib/encoding_h.template',
'lib/encoding_cpp.template',
'lib/Allocator_h.template',
'lib/DispatcherBase_cpp.template',
'lib/DispatcherBase_h.template',
'lib/ErrorSupport_cpp.template',
'lib/ErrorSupport_h.template',
'lib/Forward_h.template',
'lib/FrontendChannel_h.template',
'lib/Maybe_h.template',
'lib/Object_cpp.template',
'lib/Object_h.template',
'lib/Parser_cpp.template',
......
// This file is generated by Allocator_h.template.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef {{"_".join(config.protocol.namespace)}}_Allocator_h
#define {{"_".join(config.protocol.namespace)}}_Allocator_h
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
#define PROTOCOL_DISALLOW_COPY(ClassName) \
private: \
ClassName(const ClassName&) = delete; \
ClassName& operator=(const ClassName&) = delete
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_Allocator_h)
......@@ -18,6 +18,8 @@
#include <unordered_map>
#include <unordered_set>
#include "{{config.bindings_lib.header}}"
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
......@@ -54,6 +56,32 @@ struct ArrayTypedef<bool> { typedef std::vector<bool> type; };
template <typename T>
using Array = typename detail::ArrayTypedef<T>::type;
namespace detail {
using {{config.bindings_lib.namespace}}::glue::detail::PtrMaybe;
using {{config.bindings_lib.namespace}}::glue::detail::ValueMaybe;
template <typename T>
struct MaybeTypedef { typedef PtrMaybe<T> type; };
template <>
struct MaybeTypedef<bool> { typedef ValueMaybe<bool> type; };
template <>
struct MaybeTypedef<int> { typedef ValueMaybe<int> type; };
template <>
struct MaybeTypedef<double> { typedef ValueMaybe<double> type; };
template <>
struct MaybeTypedef<String> { typedef ValueMaybe<String> type; };
template <>
struct MaybeTypedef<Binary> { typedef ValueMaybe<Binary> type; };
} // namespace detail
template <typename T>
using Maybe = typename detail::MaybeTypedef<T>::type;
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
......
// This file is generated by Maybe_h.template.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef {{"_".join(config.protocol.namespace)}}_Maybe_h
#define {{"_".join(config.protocol.namespace)}}_Maybe_h
//#include "Forward.h"
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
namespace detail {
template<typename T>
class PtrMaybe {
public:
PtrMaybe() = default;
PtrMaybe(std::unique_ptr<T> value) : m_value(std::move(value)) { }
PtrMaybe(PtrMaybe&& other) noexcept : m_value(std::move(other.m_value)) {}
void operator=(std::unique_ptr<T> value) { m_value = std::move(value); }
T* fromJust() const { DCHECK(m_value); return m_value.get(); }
T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; }
bool isJust() const { return !!m_value; }
std::unique_ptr<T> takeJust() { DCHECK(m_value); return std::move(m_value); }
private:
std::unique_ptr<T> m_value;
};
template<typename T>
class ValueMaybe {
public:
ValueMaybe() : m_isJust(false), m_value() { }
ValueMaybe(T value) : m_isJust(true), m_value(std::move(value)) { }
ValueMaybe(ValueMaybe&& other) noexcept
: m_isJust(other.m_isJust),
m_value(std::move(other.m_value)) {}
void operator=(T value) { m_value = value; m_isJust = true; }
const T& fromJust() const { DCHECK(m_isJust); return m_value; }
const T& fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; }
bool isJust() const { return m_isJust; }
T takeJust() { DCHECK(m_isJust); return std::move(m_value); }
private:
bool m_isJust;
T m_value;
};
template <typename T>
struct MaybeTypedef { typedef PtrMaybe<T> type; };
template <>
struct MaybeTypedef<bool> { typedef ValueMaybe<bool> type; };
template <>
struct MaybeTypedef<int> { typedef ValueMaybe<int> type; };
template <>
struct MaybeTypedef<double> { typedef ValueMaybe<double> type; };
template <>
struct MaybeTypedef<String> { typedef ValueMaybe<String> type; };
template <>
struct MaybeTypedef<Binary> { typedef ValueMaybe<Binary> type; };
} // namespace detail
template <typename T>
using Maybe = typename detail::MaybeTypedef<T>::type;
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_Maybe_h)
......@@ -6,9 +6,7 @@
//#include "Values.h"
{% if config.encoding_lib.header %}
#include "{{config.encoding_lib.header}}"
{% endif %}
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
......@@ -68,29 +66,27 @@ void escapeStringForJSONInternal(const Char* str, unsigned len,
// to this constant.
static constexpr int kStackLimitValues = 1000;
{% if config.encoding_lib.namespace %}
using {{"::".join(config.encoding_lib.namespace)}}::Error;
using {{"::".join(config.encoding_lib.namespace)}}::Status;
using {{"::".join(config.encoding_lib.namespace)}}::span;
using {{config.encoding_lib.namespace}}::Error;
using {{config.encoding_lib.namespace}}::Status;
using {{config.encoding_lib.namespace}}::span;
namespace cbor {
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::CBORTokenTag;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::CBORTokenizer;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeBinary;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeDouble;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeFalse;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeFromLatin1;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeFromUTF16;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeIndefiniteLengthArrayStart;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeIndefiniteLengthMapStart;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeInt32;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeNull;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeStop;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeString8;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeTrue;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EnvelopeEncoder;
using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::InitialByteForEnvelope;
using {{config.encoding_lib.namespace}}::cbor::CBORTokenTag;
using {{config.encoding_lib.namespace}}::cbor::CBORTokenizer;
using {{config.encoding_lib.namespace}}::cbor::EncodeBinary;
using {{config.encoding_lib.namespace}}::cbor::EncodeDouble;
using {{config.encoding_lib.namespace}}::cbor::EncodeFalse;
using {{config.encoding_lib.namespace}}::cbor::EncodeFromLatin1;
using {{config.encoding_lib.namespace}}::cbor::EncodeFromUTF16;
using {{config.encoding_lib.namespace}}::cbor::EncodeIndefiniteLengthArrayStart;
using {{config.encoding_lib.namespace}}::cbor::EncodeIndefiniteLengthMapStart;
using {{config.encoding_lib.namespace}}::cbor::EncodeInt32;
using {{config.encoding_lib.namespace}}::cbor::EncodeNull;
using {{config.encoding_lib.namespace}}::cbor::EncodeStop;
using {{config.encoding_lib.namespace}}::cbor::EncodeString8;
using {{config.encoding_lib.namespace}}::cbor::EncodeTrue;
using {{config.encoding_lib.namespace}}::cbor::EnvelopeEncoder;
using {{config.encoding_lib.namespace}}::cbor::InitialByteForEnvelope;
} // namespace cbor
{% endif %}
// Below are three parsing routines for CBOR, which cover enough
// to roundtrip JSON messages.
......
This diff is collapsed.
......@@ -21,6 +21,9 @@ FILES_TO_SYNC = [
'encoding/encoding.h',
'encoding/encoding.cc',
'encoding/encoding_test.cc',
'bindings/bindings.h',
'bindings/bindings.cc',
'bindings/bindings_test.cc',
'inspector_protocol.gni',
'inspector_protocol.gypi',
'lib/*',
......@@ -143,6 +146,12 @@ def main(argv):
contents = contents.replace(
'namespace inspector_protocol_encoding',
'namespace v8_inspector_protocol_encoding')
contents = contents.replace(
'INSPECTOR_PROTOCOL_BINDINGS_BINDINGS_H_',
'V8_INSPECTOR_PROTOCOL_BINDINGS_BINDINGS_H_')
contents = contents.replace(
'namespace inspector_protocol_bindings',
'namespace v8_inspector_protocol_bindings')
open(os.path.join(dest_dir, f), 'w').write(contents)
shutil.copymode(os.path.join(src_dir, f), os.path.join(dest_dir, f))
for f in to_delete:
......
......@@ -26,6 +26,7 @@ group("v8_run_gcmole") {
"../../third_party/icu/source/",
"../../third_party/wasm-api/wasm.h",
"../../third_party/wasm-api/wasm.hh",
"../../third_party/inspector_protocol/",
"$target_gen_dir/../../",
"$target_gen_dir/../../torque-generated/",
]
......
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