chore: modernize Value usage in converters (#34794)
* chore: modernize Value usage in converters * Date is parsed as an empty object now
This commit is contained in:
parent
d28ed0da20
commit
0ee7f14190
34 changed files with 203 additions and 829 deletions
|
@ -22,7 +22,8 @@ v8::Local<v8::Value> Converter<const extensions::Extension*>::ToV8(
|
|||
dict.Set("path", extension->path());
|
||||
dict.Set("url", extension->url());
|
||||
dict.Set("version", extension->VersionString());
|
||||
dict.Set("manifest", *(extension->manifest()->value()));
|
||||
dict.Set("manifest",
|
||||
*static_cast<const base::Value*>(extension->manifest()->value()));
|
||||
|
||||
return gin::ConvertToV8(isolate, dict);
|
||||
}
|
||||
|
|
|
@ -234,13 +234,13 @@ v8::Local<v8::Value> Converter<net::HttpRequestHeaders>::ToV8(
|
|||
bool Converter<net::HttpRequestHeaders>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
net::HttpRequestHeaders* out) {
|
||||
base::DictionaryValue dict;
|
||||
base::Value::Dict dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
|
||||
if (it.value().is_string()) {
|
||||
std::string value = it.value().GetString();
|
||||
out->SetHeader(it.key(), value);
|
||||
for (const auto it : dict) {
|
||||
if (it.second.is_string()) {
|
||||
std::string value = it.second.GetString();
|
||||
out->SetHeader(it.first, value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -7,38 +7,38 @@
|
|||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "base/values.h"
|
||||
#include "shell/common/v8_value_converter.h"
|
||||
#include "content/public/renderer/v8_value_converter.h"
|
||||
|
||||
namespace gin {
|
||||
|
||||
bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::DictionaryValue* out) {
|
||||
electron::V8ValueConverter converter;
|
||||
std::unique_ptr<base::Value> value(
|
||||
converter.FromV8Value(val, isolate->GetCurrentContext()));
|
||||
bool Converter<base::Value::Dict>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::Value::Dict* out) {
|
||||
std::unique_ptr<base::Value> value =
|
||||
content::V8ValueConverter::Create()->FromV8Value(
|
||||
val, isolate->GetCurrentContext());
|
||||
if (value && value->is_dict()) {
|
||||
out->Swap(static_cast<base::DictionaryValue*>(value.get()));
|
||||
*out = std::move(value->GetDict());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Converter<base::DictionaryValue>::ToV8(
|
||||
v8::Local<v8::Value> Converter<base::Value::Dict>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const base::DictionaryValue& val) {
|
||||
electron::V8ValueConverter converter;
|
||||
return converter.ToV8Value(&val, isolate->GetCurrentContext());
|
||||
const base::Value::Dict& val) {
|
||||
base::Value value(val.Clone());
|
||||
return content::V8ValueConverter::Create()->ToV8Value(
|
||||
&value, isolate->GetCurrentContext());
|
||||
}
|
||||
|
||||
bool Converter<base::Value>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::Value* out) {
|
||||
electron::V8ValueConverter converter;
|
||||
std::unique_ptr<base::Value> value(
|
||||
converter.FromV8Value(val, isolate->GetCurrentContext()));
|
||||
std::unique_ptr<base::Value> value =
|
||||
content::V8ValueConverter::Create()->FromV8Value(
|
||||
val, isolate->GetCurrentContext());
|
||||
if (value) {
|
||||
*out = std::move(*value);
|
||||
return true;
|
||||
|
@ -49,29 +49,30 @@ bool Converter<base::Value>::FromV8(v8::Isolate* isolate,
|
|||
|
||||
v8::Local<v8::Value> Converter<base::Value>::ToV8(v8::Isolate* isolate,
|
||||
const base::Value& val) {
|
||||
electron::V8ValueConverter converter;
|
||||
return converter.ToV8Value(&val, isolate->GetCurrentContext());
|
||||
return content::V8ValueConverter::Create()->ToV8Value(
|
||||
&val, isolate->GetCurrentContext());
|
||||
}
|
||||
|
||||
bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::ListValue* out) {
|
||||
electron::V8ValueConverter converter;
|
||||
std::unique_ptr<base::Value> value(
|
||||
converter.FromV8Value(val, isolate->GetCurrentContext()));
|
||||
bool Converter<base::Value::List>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::Value::List* out) {
|
||||
std::unique_ptr<base::Value> value =
|
||||
content::V8ValueConverter::Create()->FromV8Value(
|
||||
val, isolate->GetCurrentContext());
|
||||
if (value && value->is_list()) {
|
||||
out->Swap(static_cast<base::ListValue*>(value.get()));
|
||||
*out = std::move(value->GetList());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Converter<base::ListValue>::ToV8(
|
||||
v8::Local<v8::Value> Converter<base::Value::List>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const base::ListValue& val) {
|
||||
electron::V8ValueConverter converter;
|
||||
return converter.ToV8Value(&val, isolate->GetCurrentContext());
|
||||
const base::Value::List& val) {
|
||||
base::Value value(val.Clone());
|
||||
return content::V8ValueConverter::Create()->ToV8Value(
|
||||
&value, isolate->GetCurrentContext());
|
||||
}
|
||||
|
||||
} // namespace gin
|
||||
|
|
|
@ -5,23 +5,18 @@
|
|||
#ifndef ELECTRON_SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_H_
|
||||
#define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_H_
|
||||
|
||||
#include "base/values.h"
|
||||
#include "gin/converter.h"
|
||||
|
||||
namespace base {
|
||||
class DictionaryValue;
|
||||
class ListValue;
|
||||
class Value;
|
||||
} // namespace base
|
||||
|
||||
namespace gin {
|
||||
|
||||
template <>
|
||||
struct Converter<base::DictionaryValue> {
|
||||
struct Converter<base::Value::Dict> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::DictionaryValue* out);
|
||||
base::Value::Dict* out);
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const base::DictionaryValue& val);
|
||||
const base::Value::Dict& val);
|
||||
};
|
||||
|
||||
template <>
|
||||
|
@ -34,12 +29,12 @@ struct Converter<base::Value> {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct Converter<base::ListValue> {
|
||||
struct Converter<base::Value::List> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::ListValue* out);
|
||||
base::Value::List* out);
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const base::ListValue& val);
|
||||
const base::Value::List& val);
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue