From f1ed19d98fe8c659d6f9130c47f10bbc27d800ef Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Wed, 2 Nov 2016 14:53:42 -0600 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/12892 Ref: https://github.com/nodejs/node/pull/11883 Ref: https://github.com/nodejs/node/pull/8531 Reviewed-By: Andreas Madsen Reviewed-By: Anna Henningsen Reviewed-By: Sam Roberts Reviewed-By: Matteo Collina Reviewed-By: Refael Ackermann Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- src/async-wrap.cc | 4 +++- src/async-wrap.h | 11 +++++++---- src/node_crypto.cc | 4 ++-- src/node_crypto.h | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 71f09ba1603494..304e5d0c956490 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -109,7 +109,9 @@ intptr_t RetainedAsyncInfo::GetSizeInBytes() { RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local wrapper) { // No class_id should be the provider type of NONE. - CHECK_NE(NODE_ASYNC_ID_OFFSET, class_id); + CHECK_GT(class_id, NODE_ASYNC_ID_OFFSET); + // And make sure the class_id doesn't extend past the last provider. + CHECK_LE(class_id - NODE_ASYNC_ID_OFFSET, AsyncWrap::PROVIDERS_LENGTH); CHECK(wrapper->IsObject()); CHECK(!wrapper.IsEmpty()); diff --git a/src/async-wrap.h b/src/async-wrap.h index 8483685c2274b2..ecf8db9fc5eea9 100644 --- a/src/async-wrap.h +++ b/src/async-wrap.h @@ -36,27 +36,29 @@ namespace node { #define NODE_ASYNC_PROVIDER_TYPES(V) \ V(NONE) \ - V(CRYPTO) \ + V(CONNECTION) \ V(FSEVENTWRAP) \ V(FSREQWRAP) \ V(GETADDRINFOREQWRAP) \ V(GETNAMEINFOREQWRAP) \ V(HTTPPARSER) \ V(JSSTREAM) \ - V(PIPEWRAP) \ + V(PBKDF2REQUEST) \ V(PIPECONNECTWRAP) \ + V(PIPEWRAP) \ V(PROCESSWRAP) \ V(QUERYWRAP) \ + V(RANDOMBYTESREQUEST) \ V(SHUTDOWNWRAP) \ V(SIGNALWRAP) \ V(STATWATCHER) \ - V(TCPWRAP) \ V(TCPCONNECTWRAP) \ + V(TCPWRAP) \ V(TIMERWRAP) \ V(TLSWRAP) \ V(TTYWRAP) \ - V(UDPWRAP) \ V(UDPSENDWRAP) \ + V(UDPWRAP) \ V(WRITEWRAP) \ V(ZLIB) @@ -69,6 +71,7 @@ class AsyncWrap : public BaseObject { PROVIDER_ ## PROVIDER, NODE_ASYNC_PROVIDER_TYPES(V) #undef V + PROVIDERS_LENGTH, }; AsyncWrap(Environment* env, diff --git a/src/node_crypto.cc b/src/node_crypto.cc index da1c337fe6e1c8..87e008acd97e10 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5314,7 +5314,7 @@ class PBKDF2Request : public AsyncWrap { char* salt, int iter, int keylen) - : AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO), + : AsyncWrap(env, object, AsyncWrap::PROVIDER_PBKDF2REQUEST), digest_(digest), error_(0), passlen_(passlen), @@ -5586,7 +5586,7 @@ class RandomBytesRequest : public AsyncWrap { size_t size, char* data, FreeMode free_mode) - : AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO), + : AsyncWrap(env, object, AsyncWrap::PROVIDER_RANDOMBYTESREQUEST), error_(0), size_(size), data_(data), diff --git a/src/node_crypto.h b/src/node_crypto.h index ffb8444ce60145..90e268456a4f12 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -402,7 +402,7 @@ class Connection : public AsyncWrap, public SSLWrap { v8::Local wrap, SecureContext* sc, SSLWrap::Kind kind) - : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO), + : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CONNECTION), SSLWrap(env, sc, kind), bio_read_(nullptr), bio_write_(nullptr),