Skip to content

Commit efffcc2

Browse files
jureapapirovski
authored andcommitted
src: replace SetAccessor w/ SetAccessorProperty
PR-URL: #17665 Fixes: #17636 Refs: #16482 Refs: #16860 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent b2432a7 commit efffcc2

9 files changed

+231
-135
lines changed

src/node_crypto.cc

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

83-
using v8::AccessorSignature;
8483
using v8::Array;
8584
using v8::Boolean;
8685
using v8::Context;
@@ -103,8 +102,8 @@ using v8::Object;
103102
using v8::ObjectTemplate;
104103
using v8::Persistent;
105104
using v8::PropertyAttribute;
106-
using v8::PropertyCallbackInfo;
107105
using v8::ReadOnly;
106+
using v8::Signature;
108107
using v8::String;
109108
using v8::Value;
110109

@@ -544,14 +543,18 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
544543
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kTicketKeyIVIndex"),
545544
Integer::NewFromUnsigned(env->isolate(), kTicketKeyIVIndex));
546545

547-
t->PrototypeTemplate()->SetAccessor(
546+
Local<FunctionTemplate> ctx_getter_templ =
547+
FunctionTemplate::New(env->isolate(),
548+
CtxGetter,
549+
env->as_external(),
550+
Signature::New(env->isolate(), t));
551+
552+
553+
t->PrototypeTemplate()->SetAccessorProperty(
548554
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
549-
CtxGetter,
550-
nullptr,
551-
env->as_external(),
552-
DEFAULT,
553-
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
554-
AccessorSignature::New(env->isolate(), t));
555+
ctx_getter_templ,
556+
Local<FunctionTemplate>(),
557+
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
555558

556559
target->Set(secureContextString, t->GetFunction());
557560
env->set_secure_context_constructor_template(t);
@@ -1565,8 +1568,7 @@ int SecureContext::TicketCompatibilityCallback(SSL* ssl,
15651568
#endif
15661569

15671570

1568-
void SecureContext::CtxGetter(Local<String> property,
1569-
const PropertyCallbackInfo<Value>& info) {
1571+
void SecureContext::CtxGetter(const FunctionCallbackInfo<Value>& info) {
15701572
SecureContext* sc;
15711573
ASSIGN_OR_RETURN_UNWRAP(&sc, info.This());
15721574
Local<External> ext = External::New(info.GetIsolate(), sc->ctx_);
@@ -1636,14 +1638,17 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
16361638
env->SetProtoMethod(t, "getALPNNegotiatedProtocol", GetALPNNegotiatedProto);
16371639
env->SetProtoMethod(t, "setALPNProtocols", SetALPNProtocols);
16381640

1639-
t->PrototypeTemplate()->SetAccessor(
1641+
Local<FunctionTemplate> ssl_getter_templ =
1642+
FunctionTemplate::New(env->isolate(),
1643+
SSLGetter,
1644+
env->as_external(),
1645+
Signature::New(env->isolate(), t));
1646+
1647+
t->PrototypeTemplate()->SetAccessorProperty(
16401648
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
1641-
SSLGetter,
1642-
nullptr,
1643-
env->as_external(),
1644-
DEFAULT,
1645-
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
1646-
AccessorSignature::New(env->isolate(), t));
1649+
ssl_getter_templ,
1650+
Local<FunctionTemplate>(),
1651+
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
16471652
}
16481653

16491654

@@ -2804,8 +2809,7 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
28042809

28052810

28062811
template <class Base>
2807-
void SSLWrap<Base>::SSLGetter(Local<String> property,
2808-
const PropertyCallbackInfo<Value>& info) {
2812+
void SSLWrap<Base>::SSLGetter(const FunctionCallbackInfo<Value>& info) {
28092813
Base* base;
28102814
ASSIGN_OR_RETURN_UNWRAP(&base, info.This());
28112815
SSL* ssl = base->ssl_;
@@ -4797,14 +4801,17 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
47974801
env->SetProtoMethod(t, "setPublicKey", SetPublicKey);
47984802
env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey);
47994803

4800-
t->InstanceTemplate()->SetAccessor(
4804+
Local<FunctionTemplate> verify_error_getter_templ =
4805+
FunctionTemplate::New(env->isolate(),
4806+
DiffieHellman::VerifyErrorGetter,
4807+
env->as_external(),
4808+
Signature::New(env->isolate(), t));
4809+
4810+
t->InstanceTemplate()->SetAccessorProperty(
48014811
env->verify_error_string(),
4802-
DiffieHellman::VerifyErrorGetter,
4803-
nullptr,
4804-
env->as_external(),
4805-
DEFAULT,
4806-
attributes,
4807-
AccessorSignature::New(env->isolate(), t));
4812+
verify_error_getter_templ,
4813+
Local<FunctionTemplate>(),
4814+
attributes);
48084815

48094816
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"),
48104817
t->GetFunction());
@@ -4819,14 +4826,17 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
48194826
env->SetProtoMethod(t2, "getPublicKey", GetPublicKey);
48204827
env->SetProtoMethod(t2, "getPrivateKey", GetPrivateKey);
48214828

4822-
t2->InstanceTemplate()->SetAccessor(
4829+
Local<FunctionTemplate> verify_error_getter_templ2 =
4830+
FunctionTemplate::New(env->isolate(),
4831+
DiffieHellman::VerifyErrorGetter,
4832+
env->as_external(),
4833+
Signature::New(env->isolate(), t2));
4834+
4835+
t2->InstanceTemplate()->SetAccessorProperty(
48234836
env->verify_error_string(),
4824-
DiffieHellman::VerifyErrorGetter,
4825-
nullptr,
4826-
env->as_external(),
4827-
DEFAULT,
4828-
attributes,
4829-
AccessorSignature::New(env->isolate(), t2));
4837+
verify_error_getter_templ2,
4838+
Local<FunctionTemplate>(),
4839+
attributes);
48304840

48314841
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellmanGroup"),
48324842
t2->GetFunction());
@@ -5142,8 +5152,7 @@ void DiffieHellman::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
51425152
}
51435153

51445154

5145-
void DiffieHellman::VerifyErrorGetter(Local<String> property,
5146-
const PropertyCallbackInfo<Value>& args) {
5155+
void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
51475156
HandleScope scope(args.GetIsolate());
51485157

51495158
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)