-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Conversation
|
||
// Should not throw for Object.getOwnPropertyDescriptor | ||
assert.strictEqual( | ||
typeof (Object.getOwnPropertyDescriptor(TTY.prototype, 'bytesRead')), |
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.
You don’t need the parentheses after typeof
here
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.
👍 Removed.
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 PR should also update the following files. In all of them, look for PrototypeTemplate()->SetAccessor
to find which ones to replace.
node_crypto.cc
udp_wrap.cc
Ideally, we shouldn't use SetAccessor
on InstanceTemplate()
either, other than under exceptional circumstances. Here're two files that are easier to fix (look for SetAccessor
):
node_crypto.cc
node_perf.cc
src/stream_base-inl.h
Outdated
signature); | ||
|
||
Local<Signature> signature = | ||
Signature::New(env->isolate(), t); |
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.
src/stream_base-inl.h
Outdated
env->isolate(), | ||
GetFD<Base>, | ||
Local<Value>(), | ||
signature); |
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: 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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Fixed, was struggling a bit with how to indent it before.
{ | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Even better, change all uses of msg
below to TypeError
, because the exact error message may differ depending on the JavaScript engine.
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.
👍 Fixed.
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.
Almost there!
src/node_crypto.cc
Outdated
@@ -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(), |
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.
assert.strictEqual( | ||
typeof Object.getOwnPropertyDescriptor(TTY.prototype, '_externalStream'), | ||
'object' | ||
); |
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.
Similar tests should exist for Object.getOwnPropertyDescriptor(crypto.SecureContext.prototype, '_external')
and Object.getOwnPropertyDescriptor(crypto.Connection.prototype, '_external')
where crypto = process.binding('crypto')
, and Object.getOwnPropertyDescriptor(process.binding('udp_wrap').UDP.prototype, 'fd')
.
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.
👍 Added.
src/node_crypto.cc
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
We usually use env->as_external()
for the parameter right here, so that we can get access to the Environment
object in the callback itself. Again, here and below.
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.
You mean instead of Local<Value>()
?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Tests completed fine with just Local<Value>()
, so that's a bit worrying, but it's perhaps out of the scope of this PR to add tests for that. I've now switched to env->as_external
wherever it was previously used.
That should be that I think! Fun stuff :) |
src/node_crypto.cc
Outdated
Local<FunctionTemplate> verify_error_getter_templ = | ||
FunctionTemplate::New(env->isolate(), | ||
DiffieHellman::VerifyErrorGetter, | ||
Local<Value>(), |
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.
Would env->as_external()
be appropriate here as well? Or better yet, is there a place where it isn't appropriate (there are 10 places still using it)?
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.
I guess anywhere where as_external was previously used. I'll get on it.
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.
From a quick look: it would be appropriate at all of those places. In fact if you look at the current SetAccessor()
-based code, all of them have env->as_external()
for the data
parameter.
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.
👍 Done.
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.
LGTM. The comment is optional.
src/node_perf.cc
Outdated
Local<FunctionTemplate> get_performance_entry_name_templ = | ||
FunctionTemplate::New(env->isolate(), | ||
GetPerformanceEntryName, | ||
Local<Value>(), |
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.
I know they didn't use to get env->as_external()
, so this should be fine. But for sake of consistency I'd rather still have env->as_external()
here.
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.
Sure, that makes sense. Done 👍
What's with the failures on CI (Windows, Linux and SmartOS)? How does one look into a failed build? |
The CI failures all seem to be infrastructural. I'll start a rebuild to see if the situation improves. If not we can land this as-is. |
Thank you @jure! This is an awesome 1st PR! 👍 |
Thanks @apapirovski :) Let me know if there's anything else. I've already put a bottle of bubbly into the fridge, just waiting for that merge notification! |
@jure We usually tend to wait a few days before applying to make sure everyone who wants to take a look at this PR got a chance to. This should get applied in a few hours. |
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>
Do we want to land this on LTS? It lands cleanly on v8.x and v6.x, just unsure if we should wait a bit before landing |
@MylesBorins I’m +1 on backporting this. |
This does not land cleanly on v6.x due to the performance API not existing on that release stream. Does it still make sense to backport? edit: landing on v8.x also broke a test, need a backport to both branches
|
PR-URL: nodejs#17665 Fixes: nodejs#17636 Refs: nodejs#16482 Refs: nodejs#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>
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>
* 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>
Fixes: #17636
Refs: #16482
Refs: #16860
As per #17636's solution 1 (found in #17636 (comment)), this PR allows
Object.getOwnPropertyDescriptor(process.stdin._handle.__proto__, 'bytesRead')
to not throw anymore and return an object/property descriptor. However, accessing this property usingprocess.stdin._handle.__proto__.bytesRead
will still throw (as is the current case on 8.9.2+).Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
src, stream