Skip to content

Commit f3e082c

Browse files
jureMylesBorins
authored andcommitted
src: replace SetAccessor w/ SetAccessorProperty
Backport-PR-URL: #20456 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 45e28a8 commit f3e082c

9 files changed

+231
-135
lines changed

src/node_crypto.cc

+45-36
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL
7979
namespace node {
8080
namespace crypto {
8181

82-
using v8::AccessorSignature;
8382
using v8::Array;
8483
using v8::Boolean;
8584
using v8::Context;
@@ -102,8 +101,8 @@ using v8::Object;
102101
using v8::ObjectTemplate;
103102
using v8::Persistent;
104103
using v8::PropertyAttribute;
105-
using v8::PropertyCallbackInfo;
106104
using v8::ReadOnly;
105+
using v8::Signature;
107106
using v8::String;
108107
using v8::Value;
109108

@@ -481,14 +480,18 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
481480
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kTicketKeyIVIndex"),
482481
Integer::NewFromUnsigned(env->isolate(), kTicketKeyIVIndex));
483482

484-
t->PrototypeTemplate()->SetAccessor(
483+
Local<FunctionTemplate> ctx_getter_templ =
484+
FunctionTemplate::New(env->isolate(),
485+
CtxGetter,
486+
env->as_external(),
487+
Signature::New(env->isolate(), t));
488+
489+
490+
t->PrototypeTemplate()->SetAccessorProperty(
485491
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
486-
CtxGetter,
487-
nullptr,
488-
env->as_external(),
489-
DEFAULT,
490-
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
491-
AccessorSignature::New(env->isolate(), t));
492+
ctx_getter_templ,
493+
Local<FunctionTemplate>(),
494+
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
492495

493496
target->Set(secureContextString, t->GetFunction());
494497
env->set_secure_context_constructor_template(t);
@@ -1457,8 +1460,7 @@ int SecureContext::TicketCompatibilityCallback(SSL* ssl,
14571460
#endif
14581461

14591462

1460-
void SecureContext::CtxGetter(Local<String> property,
1461-
const PropertyCallbackInfo<Value>& info) {
1463+
void SecureContext::CtxGetter(const FunctionCallbackInfo<Value>& info) {
14621464
SecureContext* sc;
14631465
ASSIGN_OR_RETURN_UNWRAP(&sc, info.This());
14641466
Local<External> ext = External::New(info.GetIsolate(), sc->ctx_);
@@ -1528,14 +1530,17 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
15281530
env->SetProtoMethod(t, "getALPNNegotiatedProtocol", GetALPNNegotiatedProto);
15291531
env->SetProtoMethod(t, "setALPNProtocols", SetALPNProtocols);
15301532

1531-
t->PrototypeTemplate()->SetAccessor(
1533+
Local<FunctionTemplate> ssl_getter_templ =
1534+
FunctionTemplate::New(env->isolate(),
1535+
SSLGetter,
1536+
env->as_external(),
1537+
Signature::New(env->isolate(), t));
1538+
1539+
t->PrototypeTemplate()->SetAccessorProperty(
15321540
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
1533-
SSLGetter,
1534-
nullptr,
1535-
env->as_external(),
1536-
DEFAULT,
1537-
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
1538-
AccessorSignature::New(env->isolate(), t));
1541+
ssl_getter_templ,
1542+
Local<FunctionTemplate>(),
1543+
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
15391544
}
15401545

15411546

@@ -2696,8 +2701,7 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
26962701

26972702

26982703
template <class Base>
2699-
void SSLWrap<Base>::SSLGetter(Local<String> property,
2700-
const PropertyCallbackInfo<Value>& info) {
2704+
void SSLWrap<Base>::SSLGetter(const FunctionCallbackInfo<Value>& info) {
27012705
Base* base;
27022706
ASSIGN_OR_RETURN_UNWRAP(&base, info.This());
27032707
SSL* ssl = base->ssl_;
@@ -4694,14 +4698,17 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
46944698
env->SetProtoMethod(t, "setPublicKey", SetPublicKey);
46954699
env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey);
46964700

4697-
t->InstanceTemplate()->SetAccessor(
4701+
Local<FunctionTemplate> verify_error_getter_templ =
4702+
FunctionTemplate::New(env->isolate(),
4703+
DiffieHellman::VerifyErrorGetter,
4704+
env->as_external(),
4705+
Signature::New(env->isolate(), t));
4706+
4707+
t->InstanceTemplate()->SetAccessorProperty(
46984708
env->verify_error_string(),
4699-
DiffieHellman::VerifyErrorGetter,
4700-
nullptr,
4701-
env->as_external(),
4702-
DEFAULT,
4703-
attributes,
4704-
AccessorSignature::New(env->isolate(), t));
4709+
verify_error_getter_templ,
4710+
Local<FunctionTemplate>(),
4711+
attributes);
47054712

47064713
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"),
47074714
t->GetFunction());
@@ -4716,14 +4723,17 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
47164723
env->SetProtoMethod(t2, "getPublicKey", GetPublicKey);
47174724
env->SetProtoMethod(t2, "getPrivateKey", GetPrivateKey);
47184725

4719-
t2->InstanceTemplate()->SetAccessor(
4726+
Local<FunctionTemplate> verify_error_getter_templ2 =
4727+
FunctionTemplate::New(env->isolate(),
4728+
DiffieHellman::VerifyErrorGetter,
4729+
env->as_external(),
4730+
Signature::New(env->isolate(), t2));
4731+
4732+
t2->InstanceTemplate()->SetAccessorProperty(
47204733
env->verify_error_string(),
4721-
DiffieHellman::VerifyErrorGetter,
4722-
nullptr,
4723-
env->as_external(),
4724-
DEFAULT,
4725-
attributes,
4726-
AccessorSignature::New(env->isolate(), t2));
4734+
verify_error_getter_templ2,
4735+
Local<FunctionTemplate>(),
4736+
attributes);
47274737

47284738
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellmanGroup"),
47294739
t2->GetFunction());
@@ -5037,8 +5047,7 @@ void DiffieHellman::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
50375047
}
50385048

50395049

5040-
void DiffieHellman::VerifyErrorGetter(Local<String> property,
5041-
const PropertyCallbackInfo<Value>& args) {
5050+
void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
50425051
HandleScope scope(args.GetIsolate());
50435052

50445053
DiffieHellman* diffieHellman;

src/node_crypto.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ class SecureContext : public BaseObject {
141141
const v8::FunctionCallbackInfo<v8::Value>& args);
142142
static void EnableTicketKeyCallback(
143143
const v8::FunctionCallbackInfo<v8::Value>& args);
144-
static void CtxGetter(v8::Local<v8::String> property,
145-
const v8::PropertyCallbackInfo<v8::Value>& info);
144+
static void CtxGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
146145

147146
template <bool primary>
148147
static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -322,8 +321,7 @@ class SSLWrap {
322321
void* arg);
323322
static int TLSExtStatusCallback(SSL* s, void* arg);
324323
static int SSLCertCallback(SSL* s, void* arg);
325-
static void SSLGetter(v8::Local<v8::String> property,
326-
const v8::PropertyCallbackInfo<v8::Value>& info);
324+
static void SSLGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
327325

328326
void DestroySSL();
329327
void WaitForCertCb(CertCb cb, void* arg);
@@ -689,8 +687,7 @@ class DiffieHellman : public BaseObject {
689687
static void SetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
690688
static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
691689
static void VerifyErrorGetter(
692-
v8::Local<v8::String> property,
693-
const v8::PropertyCallbackInfo<v8::Value>& args);
690+
const v8::FunctionCallbackInfo<v8::Value>& args);
694691

695692
DiffieHellman(Environment* env, v8::Local<v8::Object> wrap)
696693
: 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

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

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

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

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

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