From efffcc262c77a58ad3c75787497df46863d1b7a6 Mon Sep 17 00:00:00 2001 From: Jure Triglav Date: Wed, 13 Dec 2017 22:35:32 +0000 Subject: src: replace SetAccessor w/ SetAccessorProperty PR-URL: https://github.com/nodejs/node/pull/17665 Fixes: https://github.com/nodejs/node/issues/17636 Refs: https://github.com/nodejs/node/pull/16482 Refs: https://github.com/nodejs/node/pull/16860 Reviewed-By: Anna Henningsen Reviewed-By: Timothy Gu Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- src/node_perf.cc | 64 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 16 deletions(-) (limited to 'src/node_perf.cc') diff --git a/src/node_perf.cc b/src/node_perf.cc index 94c3a0f8e0..37256a943c 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -19,7 +19,7 @@ using v8::Local; using v8::Name; using v8::Object; using v8::ObjectTemplate; -using v8::PropertyCallbackInfo; +using v8::Signature; using v8::String; using v8::Value; @@ -120,8 +120,7 @@ void Measure(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(obj); } -void GetPerformanceEntryName(const Local prop, - const PropertyCallbackInfo& info) { +void GetPerformanceEntryName(const FunctionCallbackInfo& info) { Isolate* isolate = info.GetIsolate(); PerformanceEntry* entry; ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder()); @@ -129,8 +128,7 @@ void GetPerformanceEntryName(const Local prop, String::NewFromUtf8(isolate, entry->name().c_str(), String::kNormalString)); } -void GetPerformanceEntryType(const Local prop, - const PropertyCallbackInfo& info) { +void GetPerformanceEntryType(const FunctionCallbackInfo& info) { Isolate* isolate = info.GetIsolate(); PerformanceEntry* entry; ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder()); @@ -138,15 +136,13 @@ void GetPerformanceEntryType(const Local prop, String::NewFromUtf8(isolate, entry->type().c_str(), String::kNormalString)); } -void GetPerformanceEntryStartTime(const Local prop, - const PropertyCallbackInfo& info) { +void GetPerformanceEntryStartTime(const FunctionCallbackInfo& info) { PerformanceEntry* entry; ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder()); info.GetReturnValue().Set(entry->startTime()); } -void GetPerformanceEntryDuration(const Local prop, - const PropertyCallbackInfo& info) { +void GetPerformanceEntryDuration(const FunctionCallbackInfo& info) { PerformanceEntry* entry; ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder()); info.GetReturnValue().Set(entry->duration()); @@ -336,14 +332,50 @@ void Init(Local target, Local pe = env->NewFunctionTemplate(PerformanceEntry::New); pe->InstanceTemplate()->SetInternalFieldCount(1); pe->SetClassName(performanceEntryString); + + Local signature = Signature::New(env->isolate(), pe); + + Local get_performance_entry_name_templ = + FunctionTemplate::New(env->isolate(), + GetPerformanceEntryName, + env->as_external(), + signature); + + Local get_performance_entry_type_templ = + FunctionTemplate::New(env->isolate(), + GetPerformanceEntryType, + env->as_external(), + signature); + + Local get_performance_entry_start_time_templ = + FunctionTemplate::New(env->isolate(), + GetPerformanceEntryStartTime, + env->as_external(), + signature); + + Local get_performance_entry_duration_templ = + FunctionTemplate::New(env->isolate(), + GetPerformanceEntryDuration, + env->as_external(), + signature); + Local 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()); + + ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "entryType"), + get_performance_entry_type_templ, + Local()); + + ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "startTime"), + get_performance_entry_start_time_templ, + Local()); + + ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "duration"), + get_performance_entry_duration_templ, + Local()); + Local fn = pe->GetFunction(); target->Set(performanceEntryString, fn); env->set_performance_entry_template(fn); -- cgit v1.2.3