v8/third_party/inspector_protocol/lib/ValueConversions_h.template
kozyatinskiy d01dc6dc11 [inspector] use own copy of third_party/inspector_protocol
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}
2016-10-28 18:20:47 +00:00

172 lines
4.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)}}_ValueConversions_h
#define {{"_".join(config.protocol.namespace)}}_ValueConversions_h
//#include "ErrorSupport.h"
//#include "Forward.h"
//#include "Values.h"
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
template<typename T>
struct ValueConversions {
static std::unique_ptr<T> parse(protocol::Value* value, ErrorSupport* errors)
{
return T::parse(value, errors);
}
static std::unique_ptr<protocol::Value> serialize(T* value)
{
return value->serialize();
}
static std::unique_ptr<protocol::Value> serialize(const std::unique_ptr<T>& value)
{
return value->serialize();
}
};
template<>
struct ValueConversions<bool> {
static bool parse(protocol::Value* value, ErrorSupport* errors)
{
bool result = false;
bool success = value ? value->asBoolean(&result) : false;
if (!success)
errors->addError("boolean value expected");
return result;
}
static std::unique_ptr<protocol::Value> serialize(bool value)
{
return FundamentalValue::create(value);
}
};
template<>
struct ValueConversions<int> {
static int parse(protocol::Value* value, ErrorSupport* errors)
{
int result = 0;
bool success = value ? value->asInteger(&result) : false;
if (!success)
errors->addError("integer value expected");
return result;
}
static std::unique_ptr<protocol::Value> serialize(int value)
{
return FundamentalValue::create(value);
}
};
template<>
struct ValueConversions<double> {
static double parse(protocol::Value* value, ErrorSupport* errors)
{
double result = 0;
bool success = value ? value->asDouble(&result) : false;
if (!success)
errors->addError("double value expected");
return result;
}
static std::unique_ptr<protocol::Value> serialize(double value)
{
return FundamentalValue::create(value);
}
};
template<>
struct ValueConversions<String> {
static String parse(protocol::Value* value, ErrorSupport* errors)
{
String result;
bool success = value ? value->asString(&result) : false;
if (!success)
errors->addError("string value expected");
return result;
}
static std::unique_ptr<protocol::Value> serialize(const String& value)
{
return StringValue::create(value);
}
};
template<>
struct ValueConversions<Value> {
static std::unique_ptr<Value> parse(protocol::Value* value, ErrorSupport* errors)
{
bool success = !!value;
if (!success) {
errors->addError("value expected");
return nullptr;
}
return value->clone();
}
static std::unique_ptr<protocol::Value> serialize(Value* value)
{
return value->clone();
}
static std::unique_ptr<protocol::Value> serialize(const std::unique_ptr<Value>& value)
{
return value->clone();
}
};
template<>
struct ValueConversions<DictionaryValue> {
static std::unique_ptr<DictionaryValue> parse(protocol::Value* value, ErrorSupport* errors)
{
bool success = value && value->type() == protocol::Value::TypeObject;
if (!success)
errors->addError("object expected");
return DictionaryValue::cast(value->clone());
}
static std::unique_ptr<protocol::Value> serialize(DictionaryValue* value)
{
return value->clone();
}
static std::unique_ptr<protocol::Value> serialize(const std::unique_ptr<DictionaryValue>& value)
{
return value->clone();
}
};
template<>
struct ValueConversions<ListValue> {
static std::unique_ptr<ListValue> parse(protocol::Value* value, ErrorSupport* errors)
{
bool success = value && value->type() == protocol::Value::TypeArray;
if (!success)
errors->addError("list expected");
return ListValue::cast(value->clone());
}
static std::unique_ptr<protocol::Value> serialize(ListValue* value)
{
return value->clone();
}
static std::unique_ptr<protocol::Value> serialize(const std::unique_ptr<ListValue>& value)
{
return value->clone();
}
};
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_ValueConversions_h)