Enable setting method in Dictionary.

This commit is contained in:
Cheng Zhao 2014-04-16 15:13:44 +08:00
parent 213ac43721
commit c9fa29ef64

View file

@ -6,6 +6,7 @@
#define NATIVE_MATE_DICTIONARY_H_
#include "native_mate/converter.h"
#include "native_mate/object_template_builder.h"
namespace mate {
@ -30,16 +31,23 @@ class Dictionary {
static Dictionary CreateEmpty(v8::Isolate* isolate);
template<typename T>
bool Get(const std::string& key, T* out) {
bool Get(const base::StringPiece& key, T* out) {
v8::Handle<v8::Value> val = object_->Get(StringToV8(isolate_, key));
return ConvertFromV8(isolate_, val, out);
}
template<typename T>
bool Set(const std::string& key, T val) {
bool Set(const base::StringPiece& key, T val) {
return object_->Set(StringToV8(isolate_, key), ConvertToV8(isolate_, val));
}
template<typename T>
bool SetMethod(const base::StringPiece& key, const T& callback) {
return object_->Set(
StringToV8(isolate_, key),
CallbackTraits<T>::CreateTemplate(isolate_, callback)->GetFunction());
}
v8::Isolate* isolate() const { return isolate_; }
private: