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

src: replace SetAccessor w/ SetAccessorProperty #38

Merged
merged 2 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 45 additions & 36 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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 @@ -108,8 +107,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 @@ -402,14 +401,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 @@ -1335,8 +1338,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,



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 @@ -1406,14 +1408,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 @@ -2568,8 +2573,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 @@ -4652,14 +4656,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 @@ -4674,14 +4681,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 @@ -4964,8 +4974,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 @@ -131,8 +131,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 @@ -290,8 +289,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 @@ -676,8 +674,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 @@ -334,14 +330,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