Skip to content

Commit

Permalink
src: replace SetAccessor w/ SetAccessorProperty
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jure authored and MylesBorins committed Jan 8, 2018
1 parent 29600cb commit 6a22186
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 135 deletions.
81 changes: 45 additions & 36 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL
namespace node {
namespace crypto {

using v8::AccessorSignature;
using v8::Array;
using v8::Boolean;
using v8::Context;
Expand All @@ -110,8 +109,8 @@ using v8::Object;
using v8::ObjectTemplate;
using v8::Persistent;
using v8::PropertyAttribute;
using v8::PropertyCallbackInfo;
using v8::ReadOnly;
using v8::Signature;
using v8::String;
using v8::Value;

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

t->PrototypeTemplate()->SetAccessor(
Local<FunctionTemplate> ctx_getter_templ =
FunctionTemplate::New(env->isolate(),
CtxGetter,
env->as_external(),
Signature::New(env->isolate(), t));


t->PrototypeTemplate()->SetAccessorProperty(
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
CtxGetter,
nullptr,
env->as_external(),
DEFAULT,
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
AccessorSignature::New(env->isolate(), t));
ctx_getter_templ,
Local<FunctionTemplate>(),
static_cast<PropertyAttribute>(ReadOnly | DontDelete));

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


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

t->PrototypeTemplate()->SetAccessor(
Local<FunctionTemplate> ssl_getter_templ =
FunctionTemplate::New(env->isolate(),
SSLGetter,
env->as_external(),
Signature::New(env->isolate(), t));

t->PrototypeTemplate()->SetAccessorProperty(
FIXED_ONE_BYTE_STRING(env->isolate(), "_external"),
SSLGetter,
nullptr,
env->as_external(),
DEFAULT,
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
AccessorSignature::New(env->isolate(), t));
ssl_getter_templ,
Local<FunctionTemplate>(),
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
}


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


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

t->InstanceTemplate()->SetAccessor(
Local<FunctionTemplate> verify_error_getter_templ =
FunctionTemplate::New(env->isolate(),
DiffieHellman::VerifyErrorGetter,
env->as_external(),
Signature::New(env->isolate(), t));

t->InstanceTemplate()->SetAccessorProperty(
env->verify_error_string(),
DiffieHellman::VerifyErrorGetter,
nullptr,
env->as_external(),
DEFAULT,
attributes,
AccessorSignature::New(env->isolate(), t));
verify_error_getter_templ,
Local<FunctionTemplate>(),
attributes);

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

t2->InstanceTemplate()->SetAccessor(
Local<FunctionTemplate> verify_error_getter_templ2 =
FunctionTemplate::New(env->isolate(),
DiffieHellman::VerifyErrorGetter,
env->as_external(),
Signature::New(env->isolate(), t2));

t2->InstanceTemplate()->SetAccessorProperty(
env->verify_error_string(),
DiffieHellman::VerifyErrorGetter,
nullptr,
env->as_external(),
DEFAULT,
attributes,
AccessorSignature::New(env->isolate(), t2));
verify_error_getter_templ2,
Local<FunctionTemplate>(),
attributes);

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


void DiffieHellman::VerifyErrorGetter(Local<String> property,
const PropertyCallbackInfo<Value>& args) {
void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(args.GetIsolate());

DiffieHellman* diffieHellman;
Expand Down
9 changes: 3 additions & 6 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ class SecureContext : public BaseObject {
const v8::FunctionCallbackInfo<v8::Value>& args);
static void EnableTicketKeyCallback(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void CtxGetter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
static void CtxGetter(const v8::FunctionCallbackInfo<v8::Value>& info);

template <bool primary>
static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down Expand Up @@ -329,8 +328,7 @@ class SSLWrap {
void* arg);
static int TLSExtStatusCallback(SSL* s, void* arg);
static int SSLCertCallback(SSL* s, void* arg);
static void SSLGetter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
static void SSLGetter(const v8::FunctionCallbackInfo<v8::Value>& info);

void DestroySSL();
void WaitForCertCb(CertCb cb, void* arg);
Expand Down Expand Up @@ -684,8 +682,7 @@ class DiffieHellman : public BaseObject {
static void SetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
static void VerifyErrorGetter(
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& args);
const v8::FunctionCallbackInfo<v8::Value>& args);

DiffieHellman(Environment* env, v8::Local<v8::Object> wrap)
: BaseObject(env, wrap),
Expand Down
64 changes: 48 additions & 16 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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,
env->as_external(),
signature);

Local<FunctionTemplate> get_performance_entry_type_templ =
FunctionTemplate::New(env->isolate(),
GetPerformanceEntryType,
env->as_external(),
signature);

Local<FunctionTemplate> get_performance_entry_start_time_templ =
FunctionTemplate::New(env->isolate(),
GetPerformanceEntryStartTime,
env->as_external(),
signature);

Local<FunctionTemplate> get_performance_entry_duration_templ =
FunctionTemplate::New(env->isolate(),
GetPerformanceEntryDuration,
env->as_external(),
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);
Expand Down
73 changes: 39 additions & 34 deletions src/stream_base-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace node {

using v8::AccessorSignature;
using v8::Signature;
using v8::External;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand All @@ -34,31 +34,41 @@ void StreamBase::AddMethods(Environment* env,
enum PropertyAttribute attributes =
static_cast<PropertyAttribute>(
v8::ReadOnly | v8::DontDelete | v8::DontEnum);
Local<AccessorSignature> signature =
AccessorSignature::New(env->isolate(), t);
t->PrototypeTemplate()->SetAccessor(env->fd_string(),
GetFD<Base>,
nullptr,
env->as_external(),
v8::DEFAULT,
attributes,
signature);

t->PrototypeTemplate()->SetAccessor(env->external_stream_string(),
GetExternal<Base>,
nullptr,
env->as_external(),
v8::DEFAULT,
attributes,
signature);

t->PrototypeTemplate()->SetAccessor(env->bytes_read_string(),
GetBytesRead<Base>,
nullptr,
env->as_external(),
v8::DEFAULT,
attributes,
signature);

Local<Signature> signature = Signature::New(env->isolate(), t);

Local<FunctionTemplate> get_fd_templ =
FunctionTemplate::New(env->isolate(),
GetFD<Base>,
env->as_external(),
signature);

Local<FunctionTemplate> get_external_templ =
FunctionTemplate::New(env->isolate(),
GetExternal<Base>,
env->as_external(),
signature);

Local<FunctionTemplate> get_bytes_read_templ =
FunctionTemplate::New(env->isolate(),
GetBytesRead<Base>,
env->as_external(),
signature);

t->PrototypeTemplate()->SetAccessorProperty(env->fd_string(),
get_fd_templ,
Local<FunctionTemplate>(),
attributes);

t->PrototypeTemplate()->SetAccessorProperty(env->external_stream_string(),
get_external_templ,
Local<FunctionTemplate>(),
attributes);

t->PrototypeTemplate()->SetAccessorProperty(env->bytes_read_string(),
get_bytes_read_templ,
Local<FunctionTemplate>(),
attributes);

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


template <class Base>
void StreamBase::GetFD(Local<String> key,
const PropertyCallbackInfo<Value>& args) {
void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) {
// Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD().
Base* handle;
ASSIGN_OR_RETURN_UNWRAP(&handle,
Expand All @@ -100,10 +109,8 @@ void StreamBase::GetFD(Local<String> key,
args.GetReturnValue().Set(wrap->GetFD());
}


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


template <class Base>
void StreamBase::GetExternal(Local<String> key,
const PropertyCallbackInfo<Value>& args) {
void StreamBase::GetExternal(const FunctionCallbackInfo<Value>& args) {
Base* handle;
ASSIGN_OR_RETURN_UNWRAP(&handle, args.This());

Expand Down
Loading

0 comments on commit 6a22186

Please sign in to comment.