Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change InstanceTemplate SetAccessor to SetAccessorProperty
  • Loading branch information
jure committed Dec 14, 2017
commit 9292fa03fb9b3edf14142bbc2d8e8af2b74b665d
63 changes: 48 additions & 15 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using v8::Name;
using v8::Object;
using v8::ObjectTemplate;
using v8::PropertyCallbackInfo;
using v8::Signature;
using v8::String;
using v8::Value;

Expand Down Expand Up @@ -120,33 +121,29 @@ void Measure(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(obj);
}

void GetPerformanceEntryName(const Local<String> prop,
const PropertyCallbackInfo<Value>& info) {
void GetPerformanceEntryName(const FunctionCallbackInfo<Value>& info) {
Isolate* isolate = info.GetIsolate();
PerformanceEntry* entry;
ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder());
info.GetReturnValue().Set(
String::NewFromUtf8(isolate, entry->name().c_str(), String::kNormalString));
}

void GetPerformanceEntryType(const Local<String> prop,
const PropertyCallbackInfo<Value>& info) {
void GetPerformanceEntryType(const FunctionCallbackInfo<Value>& info) {
Isolate* isolate = info.GetIsolate();
PerformanceEntry* entry;
ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder());
info.GetReturnValue().Set(
String::NewFromUtf8(isolate, entry->type().c_str(), String::kNormalString));
}

void GetPerformanceEntryStartTime(const Local<String> prop,
const PropertyCallbackInfo<Value>& info) {
void GetPerformanceEntryStartTime(const FunctionCallbackInfo<Value>& info) {
PerformanceEntry* entry;
ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder());
info.GetReturnValue().Set(entry->startTime());
}

void GetPerformanceEntryDuration(const Local<String> prop,
const PropertyCallbackInfo<Value>& info) {
void GetPerformanceEntryDuration(const FunctionCallbackInfo<Value>& info) {
PerformanceEntry* entry;
ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder());
info.GetReturnValue().Set(entry->duration());
Expand Down Expand Up @@ -336,14 +333,50 @@ void Init(Local<Object> target,
Local<FunctionTemplate> pe = env->NewFunctionTemplate(PerformanceEntry::New);
pe->InstanceTemplate()->SetInternalFieldCount(1);
pe->SetClassName(performanceEntryString);

Local<Signature> signature = Signature::New(env->isolate(), pe);

Local<FunctionTemplate> get_performance_entry_name_templ =
FunctionTemplate::New(env->isolate(),
GetPerformanceEntryName,
Local<Value>(),
signature);

Local<FunctionTemplate> get_performance_entry_type_templ =
FunctionTemplate::New(env->isolate(),
GetPerformanceEntryType,
Local<Value>(),
signature);

Local<FunctionTemplate> get_performance_entry_start_time_templ =
FunctionTemplate::New(env->isolate(),
GetPerformanceEntryStartTime,
Local<Value>(),
signature);

Local<FunctionTemplate> get_performance_entry_duration_templ =
FunctionTemplate::New(env->isolate(),
GetPerformanceEntryDuration,
Local<Value>(),
signature);

Local<ObjectTemplate> ot = pe->InstanceTemplate();
ot->SetAccessor(env->name_string(), GetPerformanceEntryName);
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "entryType"),
GetPerformanceEntryType);
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "startTime"),
GetPerformanceEntryStartTime);
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "duration"),
GetPerformanceEntryDuration);
ot->SetAccessorProperty(env->name_string(),
get_performance_entry_name_templ,
Local<FunctionTemplate>());

ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "entryType"),
get_performance_entry_type_templ,
Local<FunctionTemplate>());

ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "startTime"),
get_performance_entry_start_time_templ,
Local<FunctionTemplate>());

ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "duration"),
get_performance_entry_duration_templ,
Local<FunctionTemplate>());

Local<Function> fn = pe->GetFunction();
target->Set(performanceEntryString, fn);
env->set_performance_entry_template(fn);
Expand Down