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
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
#include "base/values.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/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
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> val,
|
2014-04-22 15:07:21 +00:00
|
|
|
base::DictionaryValue* out) {
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::V8ValueConverter converter;
|
2018-04-18 01:55:30 +00:00
|
|
|
std::unique_ptr<base::Value> value(
|
2018-05-15 14:21:23 +00:00
|
|
|
converter.FromV8Value(val, isolate->GetCurrentContext()));
|
2018-04-10 14:05:36 +00:00
|
|
|
if (value && value->is_dict()) {
|
2014-06-28 14:33:00 +00:00
|
|
|
out->Swap(static_cast<base::DictionaryValue*>(value.get()));
|
2014-04-22 15:07:21 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 05:24:47 +00:00
|
|
|
v8::Local<v8::Value> Converter<base::DictionaryValue>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const base::DictionaryValue& val) {
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::V8ValueConverter converter;
|
2018-05-15 14:21:23 +00:00
|
|
|
return converter.ToV8Value(&val, 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) {
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::V8ValueConverter converter;
|
2018-08-03 21:23:07 +00:00
|
|
|
std::unique_ptr<base::Value> value(
|
|
|
|
converter.FromV8Value(val, isolate->GetCurrentContext()));
|
|
|
|
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) {
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::V8ValueConverter converter;
|
2018-08-03 21:23:07 +00:00
|
|
|
return converter.ToV8Value(&val, isolate->GetCurrentContext());
|
|
|
|
}
|
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> val,
|
2014-04-17 05:45:14 +00:00
|
|
|
base::ListValue* out) {
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::V8ValueConverter converter;
|
2018-04-18 01:55:30 +00:00
|
|
|
std::unique_ptr<base::Value> value(
|
2018-05-15 14:21:23 +00:00
|
|
|
converter.FromV8Value(val, isolate->GetCurrentContext()));
|
2020-03-18 20:59:34 +00:00
|
|
|
if (value && value->is_list()) {
|
2014-06-28 14:33:00 +00:00
|
|
|
out->Swap(static_cast<base::ListValue*>(value.get()));
|
2014-04-17 05:45:14 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> Converter<base::ListValue>::ToV8(
|
2015-01-15 01:51:54 +00:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
const base::ListValue& val) {
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::V8ValueConverter converter;
|
2018-05-15 14:21:23 +00:00
|
|
|
return converter.ToV8Value(&val, isolate->GetCurrentContext());
|
2015-01-15 01:51:54 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
} // namespace gin
|