diff --git a/native_mate/dictionary.h b/native_mate/dictionary.h index 469746653f4..562d82a4204 100644 --- a/native_mate/dictionary.h +++ b/native_mate/dictionary.h @@ -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 - bool Get(const std::string& key, T* out) { + bool Get(const base::StringPiece& key, T* out) { v8::Handle val = object_->Get(StringToV8(isolate_, key)); return ConvertFromV8(isolate_, val, out); } template - 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 + bool SetMethod(const base::StringPiece& key, const T& callback) { + return object_->Set( + StringToV8(isolate_, key), + CallbackTraits::CreateTemplate(isolate_, callback)->GetFunction()); + } + v8::Isolate* isolate() const { return isolate_; } private: