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