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.
|
|
|
|
|
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
|
|
|
|
|
|
|
#include "atom/common/native_mate_converters/v8_value_converter.h"
|
|
|
|
#include "base/values.h"
|
|
|
|
|
|
|
|
namespace mate {
|
|
|
|
|
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) {
|
2018-05-15 14:21:23 +00:00
|
|
|
atom::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) {
|
2018-05-15 14:21:23 +00:00
|
|
|
atom::V8ValueConverter converter;
|
|
|
|
return converter.ToV8Value(&val, isolate->GetCurrentContext());
|
2015-06-05 05:24:47 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2018-05-15 14:21:23 +00:00
|
|
|
atom::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->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) {
|
2018-05-15 14:21:23 +00:00
|
|
|
atom::V8ValueConverter converter;
|
|
|
|
return converter.ToV8Value(&val, isolate->GetCurrentContext());
|
2015-01-15 01:51:54 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
} // namespace mate
|