From f8f09eb974f7030d443eed187dbcda9a2bce6d19 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 18 Nov 2013 18:15:34 +0800 Subject: [PATCH] Enable converting v8 object to dict type. --- common/v8_conversions.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/common/v8_conversions.h b/common/v8_conversions.h index bd5f72a6aa..378839a0c7 100644 --- a/common/v8_conversions.h +++ b/common/v8_conversions.h @@ -5,6 +5,7 @@ #ifndef COMMON_V8_CONVERSIONS_H_ #define COMMON_V8_CONVERSIONS_H_ +#include #include #include @@ -47,6 +48,18 @@ struct FromV8Value { return array; } + operator std::map() { + std::map dict; + v8::Handle v8_dict = value_->ToObject(); + v8::Handle 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*() { using atom::api::Window; if (value_->IsObject()) { @@ -143,6 +156,12 @@ bool V8ValueCanBeConvertedTo>( return value->IsArray(); } +template<> inline +bool V8ValueCanBeConvertedTo>( + v8::Handle value) { + return value->IsObject(); +} + template<> inline bool V8ValueCanBeConvertedTo(v8::Handle value) { using atom::api::Window;