Skip to content

Commit a93ed5c

Browse files
jureMylesBorins
authored andcommitted
src: replace SetAccessor w/ SetAccessorProperty
PR-URL: #17665 Fixes: #17636 Refs: #16482 Refs: #16860 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 712848b commit a93ed5c

9 files changed

+231
-135
lines changed

src/node_crypto.cc

+45-36
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL
8787
namespace node {
8888
namespace crypto {
8989

90-
using v8::AccessorSignature;
9190
using v8::Array;
9291
using v8::Boolean;
9392
using v8::Context;
@@ -110,8 +109,8 @@ using v8::Object;
110109
using v8::ObjectTemplate;
111110
using v8::Persistent;
112111
using v8::PropertyAttribute;
113-
using v8::PropertyCallbackInfo;
114112
using v8::ReadOnly;
113+
using v8::Signature;
115114
using v8::String;
116115
using v8::Value;
117116

@@ -551,14 +550,18 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
551550
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kTicketKeyIVIndex"),
552551
Integer::NewFromUnsigned(env->isolate(), kTicketKeyIVIndex));
553552

554-
t->PrototypeTemplate()->SetAccessor(
553+
Local<FunctionTemplate> ctx_getter_templ =
554+
FunctionTemplate::New(env->isolate(),
555+
CtxGetter,
556+
env->as_external(),
557+
Signature::New(env->isolate(), t));
558+
559+
560+
t->PrototypeTemplate()->SetAccessorProperty(
555561
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
556-
CtxGetter,
557-
nullptr,
558-
env->as_external(),
559-
DEFAULT,
560-
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
561-
AccessorSignature::New(env->isolate(), t));
562+
ctx_getter_templ,
563+
Local<FunctionTemplate>(),
564+
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
562565

563566
target->Set(secureContextString, t->GetFunction());
564567
env->set_secure_context_constructor_template(t);
@@ -1572,8 +1575,7 @@ int SecureContext::TicketCompatibilityCallback(SSL* ssl,
15721575
#endif
15731576

15741577

1575-
void SecureContext::CtxGetter(Local<String> property,
1576-
const PropertyCallbackInfo<Value>& info) {
1578+
void SecureContext::CtxGetter(const FunctionCallbackInfo<Value>& info) {
15771579
SecureContext* sc;
15781580
ASSIGN_OR_RETURN_UNWRAP(&sc, info.This());
15791581
Local<External> ext = External::New(info.GetIsolate(), sc->ctx_);
@@ -1643,14 +1645,17 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
16431645
env->SetProtoMethod(t, "getALPNNegotiatedProtocol", GetALPNNegotiatedProto);
16441646
env->SetProtoMethod(t, "setALPNProtocols", SetALPNProtocols);
16451647

1646-
t->PrototypeTemplate()->SetAccessor(
1648+
Local<FunctionTemplate> ssl_getter_templ =
1649+
FunctionTemplate::New(env->isolate(),
1650+
SSLGetter,
1651+
env->as_external(),
1652+
Signature::New(env->isolate(), t));
1653+
1654+
t->PrototypeTemplate()->SetAccessorProperty(
16471655
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
1648-
SSLGetter,
1649-
nullptr,
1650-
env->as_external(),
1651-
DEFAULT,
1652-
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
1653-
AccessorSignature::New(env->isolate(), t));
1656+
ssl_getter_templ,
1657+
Local<FunctionTemplate>(),
1658+
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
16541659
}
16551660

16561661

@@ -2811,8 +2816,7 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
28112816

28122817

28132818
template <class Base>
2814-
void SSLWrap<Base>::SSLGetter(Local<String> property,
2815-
const PropertyCallbackInfo<Value>& info) {
2819+
void SSLWrap<Base>::SSLGetter(const FunctionCallbackInfo<Value>& info) {
28162820
Base* base;
28172821
ASSIGN_OR_RETURN_UNWRAP(&base, info.This());
28182822
SSL* ssl = base->ssl_;
@@ -4828,14 +4832,17 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
48284832
env->SetProtoMethod(t, "setPublicKey", SetPublicKey);
48294833
env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey);
48304834

4831-
t->InstanceTemplate()->SetAccessor(
4835+
Local<FunctionTemplate> verify_error_getter_templ =
4836+
FunctionTemplate::New(env->isolate(),
4837+
DiffieHellman::VerifyErrorGetter,
4838+
env->as_external(),
4839+
Signature::New(env->isolate(), t));
4840+
4841+
t->InstanceTemplate()->SetAccessorProperty(
48324842
env->verify_error_string(),
4833-
DiffieHellman::VerifyErrorGetter,
4834-
nullptr,
4835-
env->as_external(),
4836-
DEFAULT,
4837-
attributes,
4838-
AccessorSignature::New(env->isolate(), t));
4843+
verify_error_getter_templ,
4844+
Local<FunctionTemplate>(),
4845+
attributes);
48394846

48404847
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"),
48414848
t->GetFunction());
@@ -4850,14 +4857,17 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
48504857
env->SetProtoMethod(t2, "getPublicKey", GetPublicKey);
48514858
env->SetProtoMethod(t2, "getPrivateKey", GetPrivateKey);
48524859

4853-
t2->InstanceTemplate()->SetAccessor(
4860+
Local<FunctionTemplate> verify_error_getter_templ2 =
4861+
FunctionTemplate::New(env->isolate(),
4862+
DiffieHellman::VerifyErrorGetter,
4863+
env->as_external(),
4864+
Signature::New(env->isolate(), t2));
4865+
4866+
t2->InstanceTemplate()->SetAccessorProperty(
48544867
env->verify_error_string(),
4855-
DiffieHellman::VerifyErrorGetter,
4856-
nullptr,
4857-
env->as_external(),
4858-
DEFAULT,
4859-
attributes,
4860-
AccessorSignature::New(env->isolate(), t2));
4868+
verify_error_getter_templ2,
4869+
Local<FunctionTemplate>(),
4870+
attributes);
48614871

48624872
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellmanGroup"),
48634873
t2->GetFunction());
@@ -5173,8 +5183,7 @@ void DiffieHellman::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
51735183
}
51745184

51755185

5176-
void DiffieHellman::VerifyErrorGetter(Local<String> property,
5177-
const PropertyCallbackInfo<Value>& args) {
5186+
void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
51785187
HandleScope scope(args.GetIsolate());
51795188

51805189
DiffieHellman* diffieHellman;

src/node_crypto.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ class SecureContext : public BaseObject {
148148
const v8::FunctionCallbackInfo<v8::Value>& args);
149149
static void EnableTicketKeyCallback(
150150
const v8::FunctionCallbackInfo<v8::Value>& args);
151-
static void CtxGetter(v8::Local<v8::String> property,
152-
const v8::PropertyCallbackInfo<v8::Value>& info);
151+
static void CtxGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
153152

154153
template <bool primary>
155154
static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -329,8 +328,7 @@ class SSLWrap {
329328
void* arg);
330329
static int TLSExtStatusCallback(SSL* s, void* arg);
331330
static int SSLCertCallback(SSL* s, void* arg);
332-
static void SSLGetter(v8::Local<v8::String> property,
333-
const v8::PropertyCallbackInfo<v8::Value>& info);
331+
static void SSLGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
334332

335333
void DestroySSL();
336334
void WaitForCertCb(CertCb cb, void* arg);
@@ -684,8 +682,7 @@ class DiffieHellman : public BaseObject {
684682
static void SetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
685683
static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
686684
static void VerifyErrorGetter(
687-
v8::Local<v8::String> property,
688-
const v8::PropertyCallbackInfo<v8::Value>& args);
685+
const v8::FunctionCallbackInfo<v8::Value>& args);
689686

690687
DiffieHellman(Environment* env, v8::Local<v8::Object> wrap)
691688
: BaseObject(env, wrap),

src/node_perf.cc

+48-16
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using v8::Local;
1919
using v8::Name;
2020
using v8::Object;
2121
using v8::ObjectTemplate;
22-
using v8::PropertyCallbackInfo;
22+
using v8::Signature;
2323
using v8::String;
2424
using v8::Value;
2525

@@ -120,33 +120,29 @@ void Measure(const FunctionCallbackInfo<Value>& args) {
120120
args.GetReturnValue().Set(obj);
121121
}
122122

123-
void GetPerformanceEntryName(const Local<String> prop,
124-
const PropertyCallbackInfo<Value>& info) {
123+
void GetPerformanceEntryName(const FunctionCallbackInfo<Value>& info) {
125124
Isolate* isolate = info.GetIsolate();
126125
PerformanceEntry* entry;
127126
ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder());
128127
info.GetReturnValue().Set(
129128
String::NewFromUtf8(isolate, entry->name().c_str(), String::kNormalString));
130129
}
131130

132-
void GetPerformanceEntryType(const Local<String> prop,
133-
const PropertyCallbackInfo<Value>& info) {
131+
void GetPerformanceEntryType(const FunctionCallbackInfo<Value>& info) {
134132
Isolate* isolate = info.GetIsolate();
135133
PerformanceEntry* entry;
136134
ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder());
137135
info.GetReturnValue().Set(
138136
String::NewFromUtf8(isolate, entry->type().c_str(), String::kNormalString));
139137
}
140138

141-
void GetPerformanceEntryStartTime(const Local<String> prop,
142-
const PropertyCallbackInfo<Value>& info) {
139+
void GetPerformanceEntryStartTime(const FunctionCallbackInfo<Value>& info) {
143140
PerformanceEntry* entry;
144141
ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder());
145142
info.GetReturnValue().Set(entry->startTime());
146143
}
147144

148-
void GetPerformanceEntryDuration(const Local<String> prop,
149-
const PropertyCallbackInfo<Value>& info) {
145+
void GetPerformanceEntryDuration(const FunctionCallbackInfo<Value>& info) {
150146
PerformanceEntry* entry;
151147
ASSIGN_OR_RETURN_UNWRAP(&entry, info.Holder());
152148
info.GetReturnValue().Set(entry->duration());
@@ -336,14 +332,50 @@ void Init(Local<Object> target,
336332
Local<FunctionTemplate> pe = env->NewFunctionTemplate(PerformanceEntry::New);
337333
pe->InstanceTemplate()->SetInternalFieldCount(1);
338334
pe->SetClassName(performanceEntryString);
335+
336+
Local<Signature> signature = Signature::New(env->isolate(), pe);
337+
338+
Local<FunctionTemplate> get_performance_entry_name_templ =
339+
FunctionTemplate::New(env->isolate(),
340+
GetPerformanceEntryName,
341+
env->as_external(),
342+
signature);
343+
344+
Local<FunctionTemplate> get_performance_entry_type_templ =
345+
FunctionTemplate::New(env->isolate(),
346+
GetPerformanceEntryType,
347+
env->as_external(),
348+
signature);
349+
350+
Local<FunctionTemplate> get_performance_entry_start_time_templ =
351+
FunctionTemplate::New(env->isolate(),
352+
GetPerformanceEntryStartTime,
353+
env->as_external(),
354+
signature);
355+
356+
Local<FunctionTemplate> get_performance_entry_duration_templ =
357+
FunctionTemplate::New(env->isolate(),
358+
GetPerformanceEntryDuration,
359+
env->as_external(),
360+
signature);
361+
339362
Local<ObjectTemplate> ot = pe->InstanceTemplate();
340-
ot->SetAccessor(env->name_string(), GetPerformanceEntryName);
341-
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "entryType"),
342-
GetPerformanceEntryType);
343-
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "startTime"),
344-
GetPerformanceEntryStartTime);
345-
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "duration"),
346-
GetPerformanceEntryDuration);
363+
ot->SetAccessorProperty(env->name_string(),
364+
get_performance_entry_name_templ,
365+
Local<FunctionTemplate>());
366+
367+
ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "entryType"),
368+
get_performance_entry_type_templ,
369+
Local<FunctionTemplate>());
370+
371+
ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "startTime"),
372+
get_performance_entry_start_time_templ,
373+
Local<FunctionTemplate>());
374+
375+
ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "duration"),
376+
get_performance_entry_duration_templ,
377+
Local<FunctionTemplate>());
378+
347379
Local<Function> fn = pe->GetFunction();
348380
target->Set(performanceEntryString, fn);
349381
env->set_performance_entry_template(fn);

src/stream_base-inl.h

+39-34
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace node {
1313

14-
using v8::AccessorSignature;
14+
using v8::Signature;
1515
using v8::External;
1616
using v8::FunctionCallbackInfo;
1717
using v8::FunctionTemplate;
@@ -34,31 +34,41 @@ void StreamBase::AddMethods(Environment* env,
3434
enum PropertyAttribute attributes =
3535
static_cast<PropertyAttribute>(
3636
v8::ReadOnly | v8::DontDelete | v8::DontEnum);
37-
Local<AccessorSignature> signature =
38-
AccessorSignature::New(env->isolate(), t);
39-
t->PrototypeTemplate()->SetAccessor(env->fd_string(),
40-
GetFD<Base>,
41-
nullptr,
42-
env->as_external(),
43-
v8::DEFAULT,
44-
attributes,
45-
signature);
46-
47-
t->PrototypeTemplate()->SetAccessor(env->external_stream_string(),
48-
GetExternal<Base>,
49-
nullptr,
50-
env->as_external(),
51-
v8::DEFAULT,
52-
attributes,
53-
signature);
54-
55-
t->PrototypeTemplate()->SetAccessor(env->bytes_read_string(),
56-
GetBytesRead<Base>,
57-
nullptr,
58-
env->as_external(),
59-
v8::DEFAULT,
60-
attributes,
61-
signature);
37+
38+
Local<Signature> signature = Signature::New(env->isolate(), t);
39+
40+
Local<FunctionTemplate> get_fd_templ =
41+
FunctionTemplate::New(env->isolate(),
42+
GetFD<Base>,
43+
env->as_external(),
44+
signature);
45+
46+
Local<FunctionTemplate> get_external_templ =
47+
FunctionTemplate::New(env->isolate(),
48+
GetExternal<Base>,
49+
env->as_external(),
50+
signature);
51+
52+
Local<FunctionTemplate> get_bytes_read_templ =
53+
FunctionTemplate::New(env->isolate(),
54+
GetBytesRead<Base>,
55+
env->as_external(),
56+
signature);
57+
58+
t->PrototypeTemplate()->SetAccessorProperty(env->fd_string(),
59+
get_fd_templ,
60+
Local<FunctionTemplate>(),
61+
attributes);
62+
63+
t->PrototypeTemplate()->SetAccessorProperty(env->external_stream_string(),
64+
get_external_templ,
65+
Local<FunctionTemplate>(),
66+
attributes);
67+
68+
t->PrototypeTemplate()->SetAccessorProperty(env->bytes_read_string(),
69+
get_bytes_read_templ,
70+
Local<FunctionTemplate>(),
71+
attributes);
6272

6373
env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>);
6474
env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>);
@@ -85,8 +95,7 @@ void StreamBase::AddMethods(Environment* env,
8595

8696

8797
template <class Base>
88-
void StreamBase::GetFD(Local<String> key,
89-
const PropertyCallbackInfo<Value>& args) {
98+
void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) {
9099
// Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD().
91100
Base* handle;
92101
ASSIGN_OR_RETURN_UNWRAP(&handle,
@@ -100,10 +109,8 @@ void StreamBase::GetFD(Local<String> key,
100109
args.GetReturnValue().Set(wrap->GetFD());
101110
}
102111

103-
104112
template <class Base>
105-
void StreamBase::GetBytesRead(Local<String> key,
106-
const PropertyCallbackInfo<Value>& args) {
113+
void StreamBase::GetBytesRead(const FunctionCallbackInfo<Value>& args) {
107114
// The handle instance hasn't been set. So no bytes could have been read.
108115
Base* handle;
109116
ASSIGN_OR_RETURN_UNWRAP(&handle,
@@ -115,10 +122,8 @@ void StreamBase::GetBytesRead(Local<String> key,
115122
args.GetReturnValue().Set(static_cast<double>(wrap->bytes_read_));
116123
}
117124

118-
119125
template <class Base>
120-
void StreamBase::GetExternal(Local<String> key,
121-
const PropertyCallbackInfo<Value>& args) {
126+
void StreamBase::GetExternal(const FunctionCallbackInfo<Value>& args) {
122127
Base* handle;
123128
ASSIGN_OR_RETURN_UNWRAP(&handle, args.This());
124129

0 commit comments

Comments
 (0)