Skip to content

Commit f1ed19d

Browse files
trevnorrisaddaleax
authored andcommitted
async_wrap: use more specific providers
Instead of wrapping several providers into PROVIDER_CRYPTO, have them all be named after their class. Rename other providers to also match their class names. With the exception of Parser. Which is actually HTTPParser. Add PROVIDER_LENGTH to make better checks in WrapperInfo(). PR-URL: #12892 Ref: #11883 Ref: #8531 Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent d9f3ec8 commit f1ed19d

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/async-wrap.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ intptr_t RetainedAsyncInfo::GetSizeInBytes() {
109109

110110
RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local<Value> wrapper) {
111111
// No class_id should be the provider type of NONE.
112-
CHECK_NE(NODE_ASYNC_ID_OFFSET, class_id);
112+
CHECK_GT(class_id, NODE_ASYNC_ID_OFFSET);
113+
// And make sure the class_id doesn't extend past the last provider.
114+
CHECK_LE(class_id - NODE_ASYNC_ID_OFFSET, AsyncWrap::PROVIDERS_LENGTH);
113115
CHECK(wrapper->IsObject());
114116
CHECK(!wrapper.IsEmpty());
115117

src/async-wrap.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,29 @@ namespace node {
3636

3737
#define NODE_ASYNC_PROVIDER_TYPES(V) \
3838
V(NONE) \
39-
V(CRYPTO) \
39+
V(CONNECTION) \
4040
V(FSEVENTWRAP) \
4141
V(FSREQWRAP) \
4242
V(GETADDRINFOREQWRAP) \
4343
V(GETNAMEINFOREQWRAP) \
4444
V(HTTPPARSER) \
4545
V(JSSTREAM) \
46-
V(PIPEWRAP) \
46+
V(PBKDF2REQUEST) \
4747
V(PIPECONNECTWRAP) \
48+
V(PIPEWRAP) \
4849
V(PROCESSWRAP) \
4950
V(QUERYWRAP) \
51+
V(RANDOMBYTESREQUEST) \
5052
V(SHUTDOWNWRAP) \
5153
V(SIGNALWRAP) \
5254
V(STATWATCHER) \
53-
V(TCPWRAP) \
5455
V(TCPCONNECTWRAP) \
56+
V(TCPWRAP) \
5557
V(TIMERWRAP) \
5658
V(TLSWRAP) \
5759
V(TTYWRAP) \
58-
V(UDPWRAP) \
5960
V(UDPSENDWRAP) \
61+
V(UDPWRAP) \
6062
V(WRITEWRAP) \
6163
V(ZLIB)
6264

@@ -69,6 +71,7 @@ class AsyncWrap : public BaseObject {
6971
PROVIDER_ ## PROVIDER,
7072
NODE_ASYNC_PROVIDER_TYPES(V)
7173
#undef V
74+
PROVIDERS_LENGTH,
7275
};
7376

7477
AsyncWrap(Environment* env,

src/node_crypto.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -5314,7 +5314,7 @@ class PBKDF2Request : public AsyncWrap {
53145314
char* salt,
53155315
int iter,
53165316
int keylen)
5317-
: AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
5317+
: AsyncWrap(env, object, AsyncWrap::PROVIDER_PBKDF2REQUEST),
53185318
digest_(digest),
53195319
error_(0),
53205320
passlen_(passlen),
@@ -5586,7 +5586,7 @@ class RandomBytesRequest : public AsyncWrap {
55865586
size_t size,
55875587
char* data,
55885588
FreeMode free_mode)
5589-
: AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
5589+
: AsyncWrap(env, object, AsyncWrap::PROVIDER_RANDOMBYTESREQUEST),
55905590
error_(0),
55915591
size_(size),
55925592
data_(data),

src/node_crypto.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class Connection : public AsyncWrap, public SSLWrap<Connection> {
402402
v8::Local<v8::Object> wrap,
403403
SecureContext* sc,
404404
SSLWrap<Connection>::Kind kind)
405-
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO),
405+
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CONNECTION),
406406
SSLWrap<Connection>(env, sc, kind),
407407
bio_read_(nullptr),
408408
bio_write_(nullptr),

0 commit comments

Comments
 (0)