-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src,stream: use SetAccessorProperty instead of SetAccessor #17665
Changes from 12 commits
329e162
dcca3a5
ebbe147
a03028f
06d8157
0b96b12
26ffff1
9292fa0
354008a
a199e07
5eb6507
232d2be
d89578a
5a60daa
84905d6
73aaf0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,33 +120,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()); | ||
|
@@ -336,14 +332,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>(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know they didn't use to get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, that makes sense. Done 👍 |
||
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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would
env->as_external()
be appropriate here as well? Or better yet, is there a place where it isn't appropriate (there are 10 places still using it)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess anywhere where as_external was previously used. I'll get on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick look: it would be appropriate at all of those places. In fact if you look at the current
SetAccessor()
-based code, all of them haveenv->as_external()
for thedata
parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Done.