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,
|
|
|
|
v8::Handle<v8::Value> val,
|
|
|
|
base::DictionaryValue* out) {
|
|
|
|
scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
|
|
|
|
scoped_ptr<base::Value> value(converter->FromV8Value(
|
2014-06-28 14:33:00 +00:00
|
|
|
val, isolate->GetCurrentContext()));
|
2014-06-23 13:50:28 +00:00
|
|
|
if (value && value->IsType(base::Value::TYPE_DICTIONARY)) {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Handle<v8::Value> val,
|
|
|
|
base::ListValue* out) {
|
|
|
|
scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
|
|
|
|
scoped_ptr<base::Value> value(converter->FromV8Value(
|
2014-06-28 14:33:00 +00:00
|
|
|
val, isolate->GetCurrentContext()));
|
2014-04-17 05:45:14 +00:00
|
|
|
if (value->IsType(base::Value::TYPE_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-01-15 01:51:54 +00:00
|
|
|
v8::Handle<v8::Value> Converter<base::ListValue>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const base::ListValue& val) {
|
2015-01-15 03:09:02 +00:00
|
|
|
scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
|
|
|
|
return converter->ToV8Value(&val, isolate->GetCurrentContext());
|
2015-01-15 01:51:54 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
} // namespace mate
|