-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathObjectManager.h
More file actions
49 lines (39 loc) · 1.72 KB
/
Copy pathObjectManager.h
File metadata and controls
49 lines (39 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef ObjectManager_h
#define ObjectManager_h
#include "Common.h"
namespace tns {
class ObjectManager;
struct ObjectWeakCallbackState {
ObjectWeakCallbackState(std::shared_ptr<v8::Persistent<v8::Value>> target)
: target_(target) {}
std::shared_ptr<v8::Persistent<v8::Value>> target_;
// Links in the per-isolate registry (Caches::ObjectManagedValues) that
// teardown walks. Intrusive so that a wrapper unlinks itself in O(1) when it
// is disposed, rather than leaving an entry for a later sweep to find.
// head_ points at the owning cache's head slot so unlinking -- which happens
// in a GC finalizer -- needs no cache lookup.
ObjectWeakCallbackState** head_ = nullptr;
ObjectWeakCallbackState* prev_ = nullptr;
ObjectWeakCallbackState* next_ = nullptr;
};
class ObjectManager {
public:
static void Init(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> globalTemplate);
static std::shared_ptr<v8::Persistent<v8::Value>> Register(
v8::Local<v8::Context> context, const v8::Local<v8::Value> obj);
static void FinalizerCallback(
const v8::WeakCallbackInfo<ObjectWeakCallbackState>& data);
static bool DisposeValue(v8::Isolate* isolate, v8::Local<v8::Value> value,
bool isFinalDisposal = false);
// Disposes every handle from Register() that is still alive. Replaces the
// old Isolate::VisitHandlesWithClassIds walk, which V8 removed.
static void DisposeAllRegistered(v8::Isolate* isolate);
private:
static void ReleaseNativeCounterpartCallback(
const v8::FunctionCallbackInfo<v8::Value>& info);
static long GetRetainCount(id obj);
static bool IsInstanceOf(id obj, Class clazz);
};
} // namespace tns
#endif /* ObjectManager_h */