-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 2 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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
namespace node { | ||
|
||
using v8::AccessorSignature; | ||
using v8::Signature; | ||
using v8::External; | ||
using v8::FunctionCallbackInfo; | ||
using v8::FunctionTemplate; | ||
|
@@ -34,31 +34,42 @@ 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>, | ||
Local<Value>(), | ||
signature); | ||
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. For the person landing this commit: for consistency the indentation should look something like: Local<FunctionTemplate> get_fd_templ =
FunctionTemplate::New(env->isolate(),
GetFD<Base>,
Local<Value>(),
signature); 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. 👍 Fixed, was struggling a bit with how to indent it before. |
||
|
||
Local<FunctionTemplate> get_external_templ = FunctionTemplate::New( | ||
env->isolate(), | ||
GetExternal<Base>, | ||
Local<Value>(), | ||
signature); | ||
|
||
Local<FunctionTemplate> get_bytes_read = FunctionTemplate::New( | ||
env->isolate(), | ||
GetBytesRead<Base>, | ||
Local<Value>(), | ||
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, | ||
Local<FunctionTemplate>(), | ||
attributes); | ||
|
||
env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>); | ||
env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>); | ||
|
@@ -85,8 +96,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, | ||
|
@@ -100,10 +110,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, | ||
|
@@ -115,10 +123,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()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,9 @@ 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 | ||
const msg = /TypeError: Illegal invocation/; | ||
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. Even better, change all uses 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. 👍 Fixed. |
||
assert.throws(() => { | ||
TTY.prototype.bytesRead; | ||
}, msg); | ||
|
@@ -24,4 +24,20 @@ const TTY = process.binding('tty_wrap').TTY; | |
assert.throws(() => { | ||
TTY.prototype._externalStream; | ||
}, msg); | ||
|
||
// 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.
For the person landing this commit: these two lines could be merged into a single line, which might help with readability.
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.
👍 This used to be AccessorSignature, and was over the limit. Fixed.