Enable setting method in Dictionary.
This commit is contained in:
parent
213ac43721
commit
c9fa29ef64
1 changed files with 10 additions and 2 deletions
|
@ -6,6 +6,7 @@
|
||||||
#define NATIVE_MATE_DICTIONARY_H_
|
#define NATIVE_MATE_DICTIONARY_H_
|
||||||
|
|
||||||
#include "native_mate/converter.h"
|
#include "native_mate/converter.h"
|
||||||
|
#include "native_mate/object_template_builder.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
|
@ -30,16 +31,23 @@ class Dictionary {
|
||||||
static Dictionary CreateEmpty(v8::Isolate* isolate);
|
static Dictionary CreateEmpty(v8::Isolate* isolate);
|
||||||
|
|
||||||
template<typename T>
|
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));
|
v8::Handle<v8::Value> val = object_->Get(StringToV8(isolate_, key));
|
||||||
return ConvertFromV8(isolate_, val, out);
|
return ConvertFromV8(isolate_, val, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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));
|
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_; }
|
v8::Isolate* isolate() const { return isolate_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue