d01dc6dc11
When Chromium and V8 use the same version of inspector_protocol, any protocol change takes at least 4 patches and 3 waiting for rolls. To simplify this process we need to have two diffrent versions of inspector_protocol in Chromium and V8. Current state of inspector_protocol was extracted into separate repository [1]. This CL puts last version of inspector_protocol into third_party/inspector_protocol and removes dependency on inspector_protocol in Webkit. [1] https://chromium.googlesource.com/deps/inspector_protocol/ BUG=chromium:637032 R=dgozman@chromium.org CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel Review-Url: https://codereview.chromium.org/2447323002 Cr-Commit-Position: refs/heads/master@{#40655}
137 lines
3.6 KiB
Plaintext
137 lines
3.6 KiB
Plaintext
// 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)}}_Array_h
|
|
#define {{"_".join(config.protocol.namespace)}}_Array_h
|
|
|
|
//#include "ErrorSupport.h"
|
|
//#include "Forward.h"
|
|
//#include "ValueConversions.h"
|
|
//#include "Values.h"
|
|
|
|
{% for namespace in config.protocol.namespace %}
|
|
namespace {{namespace}} {
|
|
{% endfor %}
|
|
|
|
template<typename T>
|
|
class Array {
|
|
public:
|
|
static std::unique_ptr<Array<T>> create()
|
|
{
|
|
return wrapUnique(new Array<T>());
|
|
}
|
|
|
|
static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
|
|
{
|
|
protocol::ListValue* array = ListValue::cast(value);
|
|
if (!array) {
|
|
errors->addError("array expected");
|
|
return nullptr;
|
|
}
|
|
std::unique_ptr<Array<T>> result(new Array<T>());
|
|
errors->push();
|
|
for (size_t i = 0; i < array->size(); ++i) {
|
|
errors->setName(StringUtil::fromInteger(i));
|
|
std::unique_ptr<T> item = ValueConversions<T>::parse(array->at(i), errors);
|
|
result->m_vector.push_back(std::move(item));
|
|
}
|
|
errors->pop();
|
|
if (errors->hasErrors())
|
|
return nullptr;
|
|
return result;
|
|
}
|
|
|
|
void addItem(std::unique_ptr<T> value)
|
|
{
|
|
m_vector.push_back(std::move(value));
|
|
}
|
|
|
|
size_t length()
|
|
{
|
|
return m_vector.size();
|
|
}
|
|
|
|
T* get(size_t index)
|
|
{
|
|
return m_vector[index].get();
|
|
}
|
|
|
|
std::unique_ptr<protocol::ListValue> serialize()
|
|
{
|
|
std::unique_ptr<protocol::ListValue> result = ListValue::create();
|
|
for (auto& item : m_vector)
|
|
result->pushValue(ValueConversions<T>::serialize(item));
|
|
return result;
|
|
}
|
|
|
|
private:
|
|
std::vector<std::unique_ptr<T>> m_vector;
|
|
};
|
|
|
|
template<typename T>
|
|
class ArrayBase {
|
|
public:
|
|
static std::unique_ptr<Array<T>> create()
|
|
{
|
|
return wrapUnique(new Array<T>());
|
|
}
|
|
|
|
static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
|
|
{
|
|
protocol::ListValue* array = ListValue::cast(value);
|
|
if (!array) {
|
|
errors->addError("array expected");
|
|
return nullptr;
|
|
}
|
|
errors->push();
|
|
std::unique_ptr<Array<T>> result(new Array<T>());
|
|
for (size_t i = 0; i < array->size(); ++i) {
|
|
errors->setName(StringUtil::fromInteger(i));
|
|
T item = ValueConversions<T>::parse(array->at(i), errors);
|
|
result->m_vector.push_back(item);
|
|
}
|
|
errors->pop();
|
|
if (errors->hasErrors())
|
|
return nullptr;
|
|
return result;
|
|
}
|
|
|
|
void addItem(const T& value)
|
|
{
|
|
m_vector.push_back(value);
|
|
}
|
|
|
|
size_t length()
|
|
{
|
|
return m_vector.size();
|
|
}
|
|
|
|
T get(size_t index)
|
|
{
|
|
return m_vector[index];
|
|
}
|
|
|
|
std::unique_ptr<protocol::ListValue> serialize()
|
|
{
|
|
std::unique_ptr<protocol::ListValue> result = ListValue::create();
|
|
for (auto& item : m_vector)
|
|
result->pushValue(ValueConversions<T>::serialize(item));
|
|
return result;
|
|
}
|
|
|
|
private:
|
|
std::vector<T> m_vector;
|
|
};
|
|
|
|
template<> class Array<String> : public ArrayBase<String> {};
|
|
template<> class Array<int> : public ArrayBase<int> {};
|
|
template<> class Array<double> : public ArrayBase<double> {};
|
|
template<> class Array<bool> : public ArrayBase<bool> {};
|
|
|
|
{% for namespace in config.protocol.namespace %}
|
|
} // namespace {{namespace}}
|
|
{% endfor %}
|
|
|
|
#endif // !defined({{"_".join(config.protocol.namespace)}}_Array_h)
|