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