From: Cheng Zhao Date: Mon, 18 Nov 2013 10:15:34 +0000 (+0800) Subject: Enable converting v8 object to dict type. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f8f09eb974f7030d443eed187dbcda9a2bce6d19;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Enable converting v8 object to dict type. --- diff --git a/common/v8_conversions.h b/common/v8_conversions.h index bd5f72a..378839a 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()) { @@ -144,6 +157,12 @@ bool V8ValueCanBeConvertedTo>( } template<> inline +bool V8ValueCanBeConvertedTo>( + v8::Handle value) { + return value->IsObject(); +} + +template<> inline bool V8ValueCanBeConvertedTo(v8::Handle value) { using atom::api::Window; if (value->IsObject()) {