Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit f2bcc6b

Browse files
authored
src: replace SetAccessor w/ SetAccessorProperty (#38)
* src: replace SetAccessor w/ SetAccessorProperty PR-URL: nodejs/node#17665 Fixes: nodejs/node#17636 Refs: nodejs/node#16482 Refs: nodejs/node#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> * test: make test-tls-external-accessor agnostic Remove reliance on V8-specific error messages in test/parallel/test-tls-external-accessor.js. Check that the error is a `TypeError`. The test should now be successful without modification using ChakraCore. Backport-PR-URL: nodejs/node#20456 PR-URL: nodejs/node#16272 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent bf06b64 commit f2bcc6b

10 files changed

+233
-137
lines changed

src/node_crypto.cc

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

88-
using v8::AccessorSignature;
8988
using v8::Array;
9089
using v8::Boolean;
9190
using v8::Context;
@@ -108,8 +107,8 @@ using v8::Object;
108107
using v8::ObjectTemplate;
109108
using v8::Persistent;
110109
using v8::PropertyAttribute;
111-
using v8::PropertyCallbackInfo;
112110
using v8::ReadOnly;
111+
using v8::Signature;
113112
using v8::String;
114113
using v8::Value;
115114

@@ -402,14 +401,18 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
402401
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kTicketKeyIVIndex"),
403402
Integer::NewFromUnsigned(env->isolate(), kTicketKeyIVIndex));
404403

405-
t->PrototypeTemplate()->SetAccessor(
404+
Local<FunctionTemplate> ctx_getter_templ =
405+
FunctionTemplate::New(env->isolate(),
406+
CtxGetter,
407+
env->as_external(),
408+
Signature::New(env->isolate(), t));
409+
410+
411+
t->PrototypeTemplate()->SetAccessorProperty(
406412
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
407-
CtxGetter,
408-
nullptr,
409-
env->as_external(),
410-
DEFAULT,
411-
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
412-
AccessorSignature::New(env->isolate(), t));
413+
ctx_getter_templ,
414+
Local<FunctionTemplate>(),
415+
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
413416

414417
target->Set(secureContextString, t->GetFunction());
415418
env->set_secure_context_constructor_template(t);
@@ -1335,8 +1338,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
13351338

13361339

13371340

1338-
void SecureContext::CtxGetter(Local<String> property,
1339-
const PropertyCallbackInfo<Value>& info) {
1341+
void SecureContext::CtxGetter(const FunctionCallbackInfo<Value>& info) {
13401342
SecureContext* sc;
13411343
ASSIGN_OR_RETURN_UNWRAP(&sc, info.This());
13421344
Local<External> ext = External::New(info.GetIsolate(), sc->ctx_);
@@ -1406,14 +1408,17 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
14061408
env->SetProtoMethod(t, "getALPNNegotiatedProtocol", GetALPNNegotiatedProto);
14071409
env->SetProtoMethod(t, "setALPNProtocols", SetALPNProtocols);
14081410

1409-
t->PrototypeTemplate()->SetAccessor(
1411+
Local<FunctionTemplate> ssl_getter_templ =
1412+
FunctionTemplate::New(env->isolate(),
1413+
SSLGetter,
1414+
env->as_external(),
1415+
Signature::New(env->isolate(), t));
1416+
1417+
t->PrototypeTemplate()->SetAccessorProperty(
14101418
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
1411-
SSLGetter,
1412-
nullptr,
1413-
env->as_external(),
1414-
DEFAULT,
1415-
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
1416-
AccessorSignature::New(env->isolate(), t));
1419+
ssl_getter_templ,
1420+
Local<FunctionTemplate>(),
1421+
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
14171422
}
14181423

14191424

@@ -2568,8 +2573,7 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
25682573

25692574

25702575
template <class Base>
2571-
void SSLWrap<Base>::SSLGetter(Local<String> property,
2572-
const PropertyCallbackInfo<Value>& info) {
2576+
void SSLWrap<Base>::SSLGetter(const FunctionCallbackInfo<Value>& info) {
25732577
Base* base;
25742578
ASSIGN_OR_RETURN_UNWRAP(&base, info.This());
25752579
SSL* ssl = base->ssl_;
@@ -4652,14 +4656,17 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
46524656
env->SetProtoMethod(t, "setPublicKey", SetPublicKey);
46534657
env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey);
46544658

4655-
t->InstanceTemplate()->SetAccessor(
4659+
Local<FunctionTemplate> verify_error_getter_templ =
4660+
FunctionTemplate::New(env->isolate(),
4661+
DiffieHellman::VerifyErrorGetter,
4662+
env->as_external(),
4663+
Signature::New(env->isolate(), t));
4664+
4665+
t->InstanceTemplate()->SetAccessorProperty(
46564666
env->verify_error_string(),
4657-
DiffieHellman::VerifyErrorGetter,
4658-
nullptr,
4659-
env->as_external(),
4660-
DEFAULT,
4661-
attributes,
4662-
AccessorSignature::New(env->isolate(), t));
4667+
verify_error_getter_templ,
4668+
Local<FunctionTemplate>(),
4669+
attributes);
46634670

46644671
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"),
46654672
t->GetFunction());
@@ -4674,14 +4681,17 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
46744681
env->SetProtoMethod(t2, "getPublicKey", GetPublicKey);
46754682
env->SetProtoMethod(t2, "getPrivateKey", GetPrivateKey);
46764683

4677-
t2->InstanceTemplate()->SetAccessor(
4684+
Local<FunctionTemplate> verify_error_getter_templ2 =
4685+
FunctionTemplate::New(env->isolate(),
4686+
DiffieHellman::VerifyErrorGetter,
4687+
env->as_external(),
4688+
Signature::New(env->isolate(), t2));
4689+
4690+
t2->InstanceTemplate()->SetAccessorProperty(
46784691
env->verify_error_string(),
4679-
DiffieHellman::VerifyErrorGetter,
4680-
nullptr,
4681-
env->as_external(),
4682-
DEFAULT,
4683-
attributes,
4684-
AccessorSignature::New(env->isolate(), t2));
4692+
verify_error_getter_templ2,
4693+
Local<FunctionTemplate>(),
4694+
attributes);
46854695

46864696
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellmanGroup"),
46874697
t2->GetFunction());
@@ -4964,8 +4974,7 @@ void DiffieHellman::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
49644974
}
49654975

49664976

4967-
void DiffieHellman::VerifyErrorGetter(Local<String> property,
4968-
const PropertyCallbackInfo<Value>& args) {
4977+
void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
49694978
HandleScope scope(args.GetIsolate());
49704979

49714980
DiffieHellman* diffieHellman;

src/node_crypto.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ class SecureContext : public BaseObject {
131131
const v8::FunctionCallbackInfo<v8::Value>& args);
132132
static void EnableTicketKeyCallback(
133133
const v8::FunctionCallbackInfo<v8::Value>& args);
134-
static void CtxGetter(v8::Local<v8::String> property,
135-
const v8::PropertyCallbackInfo<v8::Value>& info);
134+
static void CtxGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
136135

137136
template <bool primary>
138137
static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -290,8 +289,7 @@ class SSLWrap {
290289
void* arg);
291290
static int TLSExtStatusCallback(SSL* s, void* arg);
292291
static int SSLCertCallback(SSL* s, void* arg);
293-
static void SSLGetter(v8::Local<v8::String> property,
294-
const v8::PropertyCallbackInfo<v8::Value>& info);
292+
static void SSLGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
295293

296294
void DestroySSL();
297295
void WaitForCertCb(CertCb cb, void* arg);
@@ -676,8 +674,7 @@ class DiffieHellman : public BaseObject {
676674
static void SetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
677675
static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
678676
static void VerifyErrorGetter(
679-
v8::Local<v8::String> property,
680-
const v8::PropertyCallbackInfo<v8::Value>& args);
677+
const v8::FunctionCallbackInfo<v8::Value>& args);
681678

682679
DiffieHellman(Environment* env, v8::Local<v8::Object> wrap)
683680
: 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());
@@ -334,14 +330,50 @@ void Init(Local<Object> target,
334330
Local<FunctionTemplate> pe = env->NewFunctionTemplate(PerformanceEntry::New);
335331
pe->InstanceTemplate()->SetInternalFieldCount(1);
336332
pe->SetClassName(performanceEntryString);
333+
334+
Local<Signature> signature = Signature::New(env->isolate(), pe);
335+
336+
Local<FunctionTemplate> get_performance_entry_name_templ =
337+
FunctionTemplate::New(env->isolate(),
338+
GetPerformanceEntryName,
339+
env->as_external(),
340+
signature);
341+
342+
Local<FunctionTemplate> get_performance_entry_type_templ =
343+
FunctionTemplate::New(env->isolate(),
344+
GetPerformanceEntryType,
345+
env->as_external(),
346+
signature);
347+
348+
Local<FunctionTemplate> get_performance_entry_start_time_templ =
349+
FunctionTemplate::New(env->isolate(),
350+
GetPerformanceEntryStartTime,
351+
env->as_external(),
352+
signature);
353+
354+
Local<FunctionTemplate> get_performance_entry_duration_templ =
355+
FunctionTemplate::New(env->isolate(),
356+
GetPerformanceEntryDuration,
357+
env->as_external(),
358+
signature);
359+
337360
Local<ObjectTemplate> ot = pe->InstanceTemplate();
338-
ot->SetAccessor(env->name_string(), GetPerformanceEntryName);
339-
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "entryType"),
340-
GetPerformanceEntryType);
341-
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "startTime"),
342-
GetPerformanceEntryStartTime);
343-
ot->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "duration"),
344-
GetPerformanceEntryDuration);
361+
ot->SetAccessorProperty(env->name_string(),
362+
get_performance_entry_name_templ,
363+
Local<FunctionTemplate>());
364+
365+
ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "entryType"),
366+
get_performance_entry_type_templ,
367+
Local<FunctionTemplate>());
368+
369+
ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "startTime"),
370+
get_performance_entry_start_time_templ,
371+
Local<FunctionTemplate>());
372+
373+
ot->SetAccessorProperty(FIXED_ONE_BYTE_STRING(isolate, "duration"),
374+
get_performance_entry_duration_templ,
375+
Local<FunctionTemplate>());
376+
345377
Local<Function> fn = pe->GetFunction();
346378
target->Set(performanceEntryString, fn);
347379
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)