use idweakmap for holding callbacks in browser

This commit is contained in:
Robo 2015-10-28 21:29:46 +05:30
parent 62d15953ff
commit eae7c840b7
6 changed files with 63 additions and 13 deletions

View file

@ -9,12 +9,14 @@
#include <vector>
#include "base/memory/linked_ptr.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/wrappable.h"
#include "v8/include/v8.h"
namespace atom {
// Like ES6's WeakMap, but the key is Integer and the value is Weak Pointer.
class IDWeakMap {
class IDWeakMap : public mate::Wrappable {
public:
IDWeakMap();
~IDWeakMap();
@ -22,6 +24,9 @@ class IDWeakMap {
// Adds |object| to WeakMap and returns its allocated |id|.
int32_t Add(v8::Isolate* isolate, v8::Local<v8::Object> object);
// Sets the object to WeakMap with the given |id|.
void Set(v8::Isolate* isolate, int32_t id, v8::Local<v8::Object> object);
// Gets the object from WeakMap by its |id|.
v8::MaybeLocal<v8::Object> Get(v8::Isolate* isolate, int32_t id);
@ -40,6 +45,10 @@ class IDWeakMap {
// Clears the weak map.
void Clear();
protected:
mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) override;
private:
// Returns next available ID.
int32_t GetNextID();