2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-04-17 05:45:14 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2014-04-17 05:45:14 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2019-10-30 05:30:59 +00:00
|
|
|
#include <utility>
|
2018-09-13 00:25:56 +00:00
|
|
|
|
2022-07-05 15:25:18 +00:00
|
|
|
#include "content/public/renderer/v8_value_converter.h"
|
2014-04-17 05:45:14 +00:00
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
namespace gin {
|
2014-04-17 05:45:14 +00:00
|
|
|
|
2022-07-05 15:25:18 +00:00
|
|
|
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());
|
2018-04-10 14:05:36 +00:00
|
|
|
if (value && value->is_dict()) {
|
2022-07-05 15:25:18 +00:00
|
|
|
*out = std::move(value->GetDict());
|
2014-04-22 15:07:21 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 15:25:18 +00:00
|
|
|
v8::Local<v8::Value> Converter<base::Value::Dict>::ToV8(
|
2015-06-05 05:24:47 +00:00
|
|
|
v8::Isolate* isolate,
|
2022-07-05 15:25:18 +00:00
|
|
|
const base::Value::Dict& val) {
|
|
|
|
base::Value value(val.Clone());
|
|
|
|
return content::V8ValueConverter::Create()->ToV8Value(
|
2022-07-20 11:03:34 +00:00
|
|
|
value, isolate->GetCurrentContext());
|
2015-06-05 05:24:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 21:23:07 +00:00
|
|
|
bool Converter<base::Value>::FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
base::Value* out) {
|
2022-07-05 15:25:18 +00:00
|
|
|
std::unique_ptr<base::Value> value =
|
|
|
|
content::V8ValueConverter::Create()->FromV8Value(
|
|
|
|
val, isolate->GetCurrentContext());
|
2018-08-03 21:23:07 +00:00
|
|
|
if (value) {
|
2019-10-30 05:30:59 +00:00
|
|
|
*out = std::move(*value);
|
2018-08-03 21:23:07 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> Converter<base::Value>::ToV8(v8::Isolate* isolate,
|
|
|
|
const base::Value& val) {
|
2022-07-05 15:25:18 +00:00
|
|
|
return content::V8ValueConverter::Create()->ToV8Value(
|
2022-07-20 11:03:34 +00:00
|
|
|
val, isolate->GetCurrentContext());
|
2018-08-03 21:23:07 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 15:25:18 +00:00
|
|
|
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());
|
2020-03-18 20:59:34 +00:00
|
|
|
if (value && value->is_list()) {
|
2022-07-05 15:25:18 +00:00
|
|
|
*out = std::move(value->GetList());
|
2014-04-17 05:45:14 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 15:25:18 +00:00
|
|
|
v8::Local<v8::Value> Converter<base::Value::List>::ToV8(
|
2015-01-15 01:51:54 +00:00
|
|
|
v8::Isolate* isolate,
|
2022-07-05 15:25:18 +00:00
|
|
|
const base::Value::List& val) {
|
|
|
|
base::Value value(val.Clone());
|
|
|
|
return content::V8ValueConverter::Create()->ToV8Value(
|
2022-07-20 11:03:34 +00:00
|
|
|
value, isolate->GetCurrentContext());
|
2015-01-15 01:51:54 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
} // namespace gin
|