From c9fa29ef640e8d3d2edf6b48c2311b16ce314464 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 16 Apr 2014 15:13:44 +0800 Subject: [PATCH] Enable setting method in Dictionary. --- native_mate/dictionary.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/native_mate/dictionary.h b/native_mate/dictionary.h index 469746653f..562d82a420 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: