Use native_mate to simplify id_weak_map api.
This commit is contained in:
parent
338d11ef01
commit
8162689014
3 changed files with 70 additions and 114 deletions
|
@ -7,41 +7,39 @@
|
|||
#define ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/v8/scoped_persistent.h"
|
||||
#include "base/basictypes.h"
|
||||
#include "vendor/node/src/node_object_wrap.h"
|
||||
#include "native_mate/wrappable.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
// Like ES6's WeakMap, but the key is Integer and the value is Weak Pointer.
|
||||
class IDWeakMap : public node::ObjectWrap {
|
||||
class IDWeakMap : public mate::Wrappable<IDWeakMap> {
|
||||
public:
|
||||
static void Initialize(v8::Handle<v8::Object> target);
|
||||
IDWeakMap();
|
||||
|
||||
static void Initialize(v8::Handle<v8::Object> exports);
|
||||
|
||||
private:
|
||||
IDWeakMap();
|
||||
virtual ~IDWeakMap();
|
||||
|
||||
bool Has(int key) const;
|
||||
void Erase(int key);
|
||||
int GetNextID();
|
||||
|
||||
static void WeakCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Object>* value,
|
||||
IDWeakMap* self);
|
||||
|
||||
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
static void Add(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
static void Get(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
static void Has(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
static void Keys(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
static void Remove(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
int32_t Add(v8::Isolate* isolate, v8::Handle<v8::Object> object);
|
||||
v8::Handle<v8::Value> Get(int32_t key);
|
||||
bool Has(int32_t key) const;
|
||||
std::vector<int32_t> Keys() const;
|
||||
void Remove(int32_t key);
|
||||
int GetNextID();
|
||||
|
||||
int next_id_;
|
||||
std::map<int, RefCountedV8Object> map_;
|
||||
int32_t next_id_;
|
||||
std::map<int32_t, RefCountedV8Object> map_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IDWeakMap);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue