Enable converting v8 object to dict type.
This commit is contained in:
parent
28b692aeaa
commit
f8f09eb974
1 changed files with 19 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
||||||
#ifndef COMMON_V8_CONVERSIONS_H_
|
#ifndef COMMON_V8_CONVERSIONS_H_
|
||||||
#define COMMON_V8_CONVERSIONS_H_
|
#define COMMON_V8_CONVERSIONS_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -47,6 +48,18 @@ struct FromV8Value {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator std::map<std::string, std::string>() {
|
||||||
|
std::map<std::string, std::string> dict;
|
||||||
|
v8::Handle<v8::Object> v8_dict = value_->ToObject();
|
||||||
|
v8::Handle<v8::Array> v8_keys = v8_dict->GetOwnPropertyNames();
|
||||||
|
for (uint32_t i = 0; i < v8_keys->Length(); ++i) {
|
||||||
|
std::string key = FromV8Value(v8_keys->Get(i));
|
||||||
|
dict[key] = std::string(FromV8Value(v8_dict->Get(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
operator atom::NativeWindow*() {
|
operator atom::NativeWindow*() {
|
||||||
using atom::api::Window;
|
using atom::api::Window;
|
||||||
if (value_->IsObject()) {
|
if (value_->IsObject()) {
|
||||||
|
@ -143,6 +156,12 @@ bool V8ValueCanBeConvertedTo<std::vector<std::string>>(
|
||||||
return value->IsArray();
|
return value->IsArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<> inline
|
||||||
|
bool V8ValueCanBeConvertedTo<std::map<std::string, std::string>>(
|
||||||
|
v8::Handle<v8::Value> value) {
|
||||||
|
return value->IsObject();
|
||||||
|
}
|
||||||
|
|
||||||
template<> inline
|
template<> inline
|
||||||
bool V8ValueCanBeConvertedTo<atom::NativeWindow*>(v8::Handle<v8::Value> value) {
|
bool V8ValueCanBeConvertedTo<atom::NativeWindow*>(v8::Handle<v8::Value> value) {
|
||||||
using atom::api::Window;
|
using atom::api::Window;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue