-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src,stream: use SetAccessorProperty instead of SetAccessor #17665
Changes from 7 commits
329e162
dcca3a5
ebbe147
a03028f
06d8157
0b96b12
26ffff1
9292fa0
354008a
a199e07
5eb6507
232d2be
d89578a
5a60daa
84905d6
73aaf0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ using v8::Persistent; | |
using v8::PropertyAttribute; | ||
using v8::PropertyCallbackInfo; | ||
using v8::ReadOnly; | ||
using v8::Signature; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
|
@@ -544,14 +545,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, | ||
Local<Value>(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes.The same also needs to be done for all other such instances, otherwise I'm fairly sure some tests will fail because of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests completed fine with just |
||
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); | ||
|
@@ -1565,8 +1570,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_); | ||
|
@@ -1636,14 +1640,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, | ||
Local<Value>(), | ||
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)); | ||
} | ||
|
||
|
||
|
@@ -2804,8 +2811,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_; | ||
|
@@ -4779,14 +4785,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, | ||
Local<Value>(), | ||
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()); | ||
|
@@ -4801,14 +4810,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, | ||
Local<Value>(), | ||
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()); | ||
|
@@ -5124,8 +5136,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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,18 +10,33 @@ const assert = require('assert'); | |
// Or anything that calls StreamBase::AddMethods when setting up its prototype | ||
const TTY = process.binding('tty_wrap').TTY; | ||
|
||
// Should throw instead of raise assertions | ||
{ | ||
const msg = /TypeError: Method \w+ called on incompatible receiver/; | ||
// Should throw instead of raise assertions | ||
assert.throws(() => { | ||
TTY.prototype.bytesRead; | ||
}, msg); | ||
}, TypeError); | ||
|
||
assert.throws(() => { | ||
TTY.prototype.fd; | ||
}, msg); | ||
}, TypeError); | ||
|
||
assert.throws(() => { | ||
TTY.prototype._externalStream; | ||
}, msg); | ||
}, TypeError); | ||
|
||
// Should not throw for Object.getOwnPropertyDescriptor | ||
assert.strictEqual( | ||
typeof Object.getOwnPropertyDescriptor(TTY.prototype, 'bytesRead'), | ||
'object' | ||
); | ||
|
||
assert.strictEqual( | ||
typeof Object.getOwnPropertyDescriptor(TTY.prototype, 'fd'), | ||
'object' | ||
); | ||
|
||
assert.strictEqual( | ||
typeof Object.getOwnPropertyDescriptor(TTY.prototype, '_externalStream'), | ||
'object' | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar tests should exist for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Added. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We indent by four spaces in line continuations :)
Here and also in other C++ files.