Use V8's new SetWeak method
This commit is contained in:
parent
f7c75d36ba
commit
bd64f5ced2
5 changed files with 70 additions and 37 deletions
|
@ -6,7 +6,8 @@
|
|||
#define ATOM_COMMON_API_OBJECT_LIFE_MONITOR_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "native_mate/scoped_persistent.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -14,15 +15,23 @@ class ObjectLifeMonitor {
|
|||
public:
|
||||
static void BindTo(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> target,
|
||||
v8::Local<v8::Value> destructor);
|
||||
v8::Local<v8::Function> destructor);
|
||||
|
||||
private:
|
||||
ObjectLifeMonitor();
|
||||
ObjectLifeMonitor(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> target,
|
||||
v8::Local<v8::Function> destructor);
|
||||
|
||||
static void WeakCallback(
|
||||
const v8::WeakCallbackData<v8::Object, ObjectLifeMonitor>& data);
|
||||
static void OnObjectGC(const v8::WeakCallbackInfo<ObjectLifeMonitor>& data);
|
||||
|
||||
mate::ScopedPersistent<v8::Object> handle_;
|
||||
void RunCallback();
|
||||
|
||||
v8::Isolate* isolate_;
|
||||
v8::Global<v8::Context> context_;
|
||||
v8::Global<v8::Object> target_;
|
||||
v8::Global<v8::Function> destructor_;
|
||||
|
||||
base::WeakPtrFactory<ObjectLifeMonitor> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ObjectLifeMonitor);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue