forked from heycalmdown/v8-profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_edge.cc
91 lines (79 loc) · 2.75 KB
/
graph_edge.cc
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "graph_edge.h"
#include "graph_node.h"
using namespace v8;
namespace nodex {
Persistent<ObjectTemplate> GraphEdge::edge_template_;
void GraphEdge::Initialize() {
edge_template_ = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
edge_template_->SetInternalFieldCount(1);
edge_template_->SetAccessor(String::New("type"), GraphEdge::GetType);
edge_template_->SetAccessor(String::New("name"), GraphEdge::GetName);
edge_template_->SetAccessor(String::New("from"), GraphEdge::GetFrom);
edge_template_->SetAccessor(String::New("to"), GraphEdge::GetTo);
}
Handle<Value> GraphEdge::GetType(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
void* ptr = self->GetPointerFromInternalField(0);
int32_t type = static_cast<int32_t>(static_cast<HeapGraphEdge*>(ptr)->GetType());
Local<String> t;
switch(type) {
case HeapGraphEdge::kContextVariable :
t = String::New("ContextVariable");
break;
case HeapGraphEdge::kElement :
t = String::New("Element");
break;
case HeapGraphEdge::kProperty :
t = String::New("Property");
break;
case HeapGraphEdge::kInternal :
t = String::New("Internal");
break;
case HeapGraphEdge::kHidden :
t = String::New("Hidden");
break;
case HeapGraphEdge::kShortcut :
t = String::New("Shortcut");
break;
default:
t = String::New("Unknown");
}
return scope.Close(t);
}
Handle<Value> GraphEdge::GetName(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
void* ptr = self->GetPointerFromInternalField(0);
Handle<Value> title = static_cast<HeapGraphEdge*>(ptr)->GetName();
return scope.Close(title);
}
Handle<Value> GraphEdge::GetFrom(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
void* ptr = self->GetPointerFromInternalField(0);
const HeapGraphNode* node = static_cast<HeapGraphEdge*>(ptr)->GetFromNode();
return scope.Close(GraphNode::New(node));
}
Handle<Value> GraphEdge::GetTo(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
void* ptr = self->GetPointerFromInternalField(0);
const HeapGraphNode* node = static_cast<HeapGraphEdge*>(ptr)->GetToNode();
return scope.Close(GraphNode::New(node));
}
Handle<Value> GraphEdge::New(const HeapGraphEdge* edge) {
HandleScope scope;
if (edge_template_.IsEmpty()) {
GraphEdge::Initialize();
}
if(!edge) {
return Undefined();
}
else {
Local<Object> obj = edge_template_->NewInstance();
obj->SetPointerInInternalField(0, const_cast<HeapGraphEdge*>(edge));
return scope.Close(obj);
}
}
} //namespace nodex