forked from c4milo/v8-profiler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
profile.cc
78 lines (64 loc) · 2.5 KB
/
profile.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
#include "profile.h"
#include "profile_node.h"
using namespace v8;
namespace nodex {
Persistent<ObjectTemplate> Profile::profile_template_;
void Profile::Initialize() {
profile_template_ = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
profile_template_->SetInternalFieldCount(1);
profile_template_->SetAccessor(String::New("title"), Profile::GetTitle);
profile_template_->SetAccessor(String::New("uid"), Profile::GetUid);
profile_template_->SetAccessor(String::New("topRoot"), Profile::GetTopRoot);
profile_template_->SetAccessor(String::New("bottomRoot"), Profile::GetBottomRoot);
profile_template_->Set(String::New("delete"), FunctionTemplate::New(Profile::Delete));
}
Handle<Value> Profile::GetUid(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
void* ptr = self->GetPointerFromInternalField(0);
uint32_t uid = static_cast<CpuProfile*>(ptr)->GetUid();
return scope.Close(Integer::NewFromUnsigned(uid));
}
Handle<Value> Profile::GetTitle(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
void* ptr = self->GetPointerFromInternalField(0);
Handle<String> title = static_cast<CpuProfile*>(ptr)->GetTitle();
return scope.Close(title);
}
Handle<Value> Profile::GetTopRoot(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
void* ptr = self->GetPointerFromInternalField(0);
const CpuProfileNode* node = static_cast<CpuProfile*>(ptr)->GetTopDownRoot();
return scope.Close(ProfileNode::New(node));
}
Handle<Value> Profile::GetBottomRoot(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
void* ptr = self->GetPointerFromInternalField(0);
const CpuProfileNode* node = static_cast<CpuProfile*>(ptr)->GetBottomUpRoot();
return scope.Close(ProfileNode::New(node));
}
Handle<Value> Profile::Delete(const Arguments& args) {
HandleScope scope;
Handle<Object> self = args.This();
void* ptr = self->GetPointerFromInternalField(0);
static_cast<CpuProfile*>(ptr)->Delete();
return Undefined();
}
Handle<Value> Profile::New(const CpuProfile* profile) {
HandleScope scope;
if (profile_template_.IsEmpty()) {
Profile::Initialize();
}
if(!profile) {
return Undefined();
}
else {
Local<Object> obj = profile_template_->NewInstance();
obj->SetPointerInInternalField(0, const_cast<CpuProfile*>(profile));
return scope.Close(obj);
}
}
}