From b015bdb446e593ca609a252dc9641708ad0f3dd8 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 8 Jan 2019 23:08:42 +0800 Subject: [PATCH] src: move node::errno_string into node_errors.h/cc Move `node::errno_string` into node_errors.h/cc and move it into the `node:errors` namespace to reduce the size of the header. It's not on any performance-critical code path so does not need to be inlined. --- src/env.cc | 2 +- src/exceptions.cc | 10 +- src/node_errors.cc | 330 +++++++++++++++++++++++++++++++++++++++++++ src/node_errors.h | 3 +- src/node_internals.h | 326 ------------------------------------------ 5 files changed, 339 insertions(+), 332 deletions(-) diff --git a/src/env.cc b/src/env.cc index 58d7cea841bc30..c1c0c812f4e497 100644 --- a/src/env.cc +++ b/src/env.cc @@ -830,7 +830,7 @@ void Environment::CollectExceptionInfo(Local object, return; Local obj = object.As(); - const char* err_string = node::errno_string(errorno); + const char* err_string = errors::errno_string(errorno); if (message == nullptr || message[0] == '\0') { message = strerror(errorno); diff --git a/src/exceptions.cc b/src/exceptions.cc index c0804798e1aad6..d5c05fdf420926 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -1,9 +1,11 @@ -#include "node.h" -#include "node_internals.h" +// This file contains implementation of error APIs exposed in node.h + #include "env-inl.h" +#include "node.h" +#include "node_errors.h" #include "util-inl.h" -#include "v8.h" #include "uv.h" +#include "v8.h" #include @@ -27,7 +29,7 @@ Local ErrnoException(Isolate* isolate, Environment* env = Environment::GetCurrent(isolate); Local e; - Local estring = OneByteString(isolate, errno_string(errorno)); + Local estring = OneByteString(isolate, errors::errno_string(errorno)); if (msg == nullptr || msg[0] == '\0') { msg = strerror(errorno); } diff --git a/src/node_errors.cc b/src/node_errors.cc index 9ffd8d88f1e473..2a86c7402b5a64 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -1,4 +1,6 @@ +#include #include + #include "node_errors.h" #include "node_internals.h" @@ -326,6 +328,334 @@ TryCatchScope::~TryCatchScope() { } } +const char* errno_string(int errorno) { +#define ERRNO_CASE(e) \ + case e: \ + return #e; + switch (errorno) { +#ifdef EACCES + ERRNO_CASE(EACCES); +#endif + +#ifdef EADDRINUSE + ERRNO_CASE(EADDRINUSE); +#endif + +#ifdef EADDRNOTAVAIL + ERRNO_CASE(EADDRNOTAVAIL); +#endif + +#ifdef EAFNOSUPPORT + ERRNO_CASE(EAFNOSUPPORT); +#endif + +#ifdef EAGAIN + ERRNO_CASE(EAGAIN); +#endif + +#ifdef EWOULDBLOCK +#if EAGAIN != EWOULDBLOCK + ERRNO_CASE(EWOULDBLOCK); +#endif +#endif + +#ifdef EALREADY + ERRNO_CASE(EALREADY); +#endif + +#ifdef EBADF + ERRNO_CASE(EBADF); +#endif + +#ifdef EBADMSG + ERRNO_CASE(EBADMSG); +#endif + +#ifdef EBUSY + ERRNO_CASE(EBUSY); +#endif + +#ifdef ECANCELED + ERRNO_CASE(ECANCELED); +#endif + +#ifdef ECHILD + ERRNO_CASE(ECHILD); +#endif + +#ifdef ECONNABORTED + ERRNO_CASE(ECONNABORTED); +#endif + +#ifdef ECONNREFUSED + ERRNO_CASE(ECONNREFUSED); +#endif + +#ifdef ECONNRESET + ERRNO_CASE(ECONNRESET); +#endif + +#ifdef EDEADLK + ERRNO_CASE(EDEADLK); +#endif + +#ifdef EDESTADDRREQ + ERRNO_CASE(EDESTADDRREQ); +#endif + +#ifdef EDOM + ERRNO_CASE(EDOM); +#endif + +#ifdef EDQUOT + ERRNO_CASE(EDQUOT); +#endif + +#ifdef EEXIST + ERRNO_CASE(EEXIST); +#endif + +#ifdef EFAULT + ERRNO_CASE(EFAULT); +#endif + +#ifdef EFBIG + ERRNO_CASE(EFBIG); +#endif + +#ifdef EHOSTUNREACH + ERRNO_CASE(EHOSTUNREACH); +#endif + +#ifdef EIDRM + ERRNO_CASE(EIDRM); +#endif + +#ifdef EILSEQ + ERRNO_CASE(EILSEQ); +#endif + +#ifdef EINPROGRESS + ERRNO_CASE(EINPROGRESS); +#endif + +#ifdef EINTR + ERRNO_CASE(EINTR); +#endif + +#ifdef EINVAL + ERRNO_CASE(EINVAL); +#endif + +#ifdef EIO + ERRNO_CASE(EIO); +#endif + +#ifdef EISCONN + ERRNO_CASE(EISCONN); +#endif + +#ifdef EISDIR + ERRNO_CASE(EISDIR); +#endif + +#ifdef ELOOP + ERRNO_CASE(ELOOP); +#endif + +#ifdef EMFILE + ERRNO_CASE(EMFILE); +#endif + +#ifdef EMLINK + ERRNO_CASE(EMLINK); +#endif + +#ifdef EMSGSIZE + ERRNO_CASE(EMSGSIZE); +#endif + +#ifdef EMULTIHOP + ERRNO_CASE(EMULTIHOP); +#endif + +#ifdef ENAMETOOLONG + ERRNO_CASE(ENAMETOOLONG); +#endif + +#ifdef ENETDOWN + ERRNO_CASE(ENETDOWN); +#endif + +#ifdef ENETRESET + ERRNO_CASE(ENETRESET); +#endif + +#ifdef ENETUNREACH + ERRNO_CASE(ENETUNREACH); +#endif + +#ifdef ENFILE + ERRNO_CASE(ENFILE); +#endif + +#ifdef ENOBUFS + ERRNO_CASE(ENOBUFS); +#endif + +#ifdef ENODATA + ERRNO_CASE(ENODATA); +#endif + +#ifdef ENODEV + ERRNO_CASE(ENODEV); +#endif + +#ifdef ENOENT + ERRNO_CASE(ENOENT); +#endif + +#ifdef ENOEXEC + ERRNO_CASE(ENOEXEC); +#endif + +#ifdef ENOLINK + ERRNO_CASE(ENOLINK); +#endif + +#ifdef ENOLCK +#if ENOLINK != ENOLCK + ERRNO_CASE(ENOLCK); +#endif +#endif + +#ifdef ENOMEM + ERRNO_CASE(ENOMEM); +#endif + +#ifdef ENOMSG + ERRNO_CASE(ENOMSG); +#endif + +#ifdef ENOPROTOOPT + ERRNO_CASE(ENOPROTOOPT); +#endif + +#ifdef ENOSPC + ERRNO_CASE(ENOSPC); +#endif + +#ifdef ENOSR + ERRNO_CASE(ENOSR); +#endif + +#ifdef ENOSTR + ERRNO_CASE(ENOSTR); +#endif + +#ifdef ENOSYS + ERRNO_CASE(ENOSYS); +#endif + +#ifdef ENOTCONN + ERRNO_CASE(ENOTCONN); +#endif + +#ifdef ENOTDIR + ERRNO_CASE(ENOTDIR); +#endif + +#ifdef ENOTEMPTY +#if ENOTEMPTY != EEXIST + ERRNO_CASE(ENOTEMPTY); +#endif +#endif + +#ifdef ENOTSOCK + ERRNO_CASE(ENOTSOCK); +#endif + +#ifdef ENOTSUP + ERRNO_CASE(ENOTSUP); +#else +#ifdef EOPNOTSUPP + ERRNO_CASE(EOPNOTSUPP); +#endif +#endif + +#ifdef ENOTTY + ERRNO_CASE(ENOTTY); +#endif + +#ifdef ENXIO + ERRNO_CASE(ENXIO); +#endif + +#ifdef EOVERFLOW + ERRNO_CASE(EOVERFLOW); +#endif + +#ifdef EPERM + ERRNO_CASE(EPERM); +#endif + +#ifdef EPIPE + ERRNO_CASE(EPIPE); +#endif + +#ifdef EPROTO + ERRNO_CASE(EPROTO); +#endif + +#ifdef EPROTONOSUPPORT + ERRNO_CASE(EPROTONOSUPPORT); +#endif + +#ifdef EPROTOTYPE + ERRNO_CASE(EPROTOTYPE); +#endif + +#ifdef ERANGE + ERRNO_CASE(ERANGE); +#endif + +#ifdef EROFS + ERRNO_CASE(EROFS); +#endif + +#ifdef ESPIPE + ERRNO_CASE(ESPIPE); +#endif + +#ifdef ESRCH + ERRNO_CASE(ESRCH); +#endif + +#ifdef ESTALE + ERRNO_CASE(ESTALE); +#endif + +#ifdef ETIME + ERRNO_CASE(ETIME); +#endif + +#ifdef ETIMEDOUT + ERRNO_CASE(ETIMEDOUT); +#endif + +#ifdef ETXTBSY + ERRNO_CASE(ETXTBSY); +#endif + +#ifdef EXDEV + ERRNO_CASE(EXDEV); +#endif + + default: + return ""; + } +} + } // namespace errors void DecorateErrorStack(Environment* env, diff --git a/src/node_errors.h b/src/node_errors.h index 7638ff4251f95e..cea7c108c168f3 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -189,11 +189,12 @@ class TryCatchScope : public v8::TryCatch { CatchMode mode_; }; +const char* errno_string(int errorno); + } // namespace errors void DecorateErrorStack(Environment* env, const errors::TryCatchScope& try_catch); - } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/node_internals.h b/src/node_internals.h index f9ef31eea5aa85..3d15425b4edb23 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -358,332 +358,6 @@ int ThreadPoolWork::CancelWork() { tracing::AgentWriterHandle* GetTracingAgentWriter(); -static inline const char* errno_string(int errorno) { -#define ERRNO_CASE(e) case e: return #e; - switch (errorno) { -#ifdef EACCES - ERRNO_CASE(EACCES); -#endif - -#ifdef EADDRINUSE - ERRNO_CASE(EADDRINUSE); -#endif - -#ifdef EADDRNOTAVAIL - ERRNO_CASE(EADDRNOTAVAIL); -#endif - -#ifdef EAFNOSUPPORT - ERRNO_CASE(EAFNOSUPPORT); -#endif - -#ifdef EAGAIN - ERRNO_CASE(EAGAIN); -#endif - -#ifdef EWOULDBLOCK -# if EAGAIN != EWOULDBLOCK - ERRNO_CASE(EWOULDBLOCK); -# endif -#endif - -#ifdef EALREADY - ERRNO_CASE(EALREADY); -#endif - -#ifdef EBADF - ERRNO_CASE(EBADF); -#endif - -#ifdef EBADMSG - ERRNO_CASE(EBADMSG); -#endif - -#ifdef EBUSY - ERRNO_CASE(EBUSY); -#endif - -#ifdef ECANCELED - ERRNO_CASE(ECANCELED); -#endif - -#ifdef ECHILD - ERRNO_CASE(ECHILD); -#endif - -#ifdef ECONNABORTED - ERRNO_CASE(ECONNABORTED); -#endif - -#ifdef ECONNREFUSED - ERRNO_CASE(ECONNREFUSED); -#endif - -#ifdef ECONNRESET - ERRNO_CASE(ECONNRESET); -#endif - -#ifdef EDEADLK - ERRNO_CASE(EDEADLK); -#endif - -#ifdef EDESTADDRREQ - ERRNO_CASE(EDESTADDRREQ); -#endif - -#ifdef EDOM - ERRNO_CASE(EDOM); -#endif - -#ifdef EDQUOT - ERRNO_CASE(EDQUOT); -#endif - -#ifdef EEXIST - ERRNO_CASE(EEXIST); -#endif - -#ifdef EFAULT - ERRNO_CASE(EFAULT); -#endif - -#ifdef EFBIG - ERRNO_CASE(EFBIG); -#endif - -#ifdef EHOSTUNREACH - ERRNO_CASE(EHOSTUNREACH); -#endif - -#ifdef EIDRM - ERRNO_CASE(EIDRM); -#endif - -#ifdef EILSEQ - ERRNO_CASE(EILSEQ); -#endif - -#ifdef EINPROGRESS - ERRNO_CASE(EINPROGRESS); -#endif - -#ifdef EINTR - ERRNO_CASE(EINTR); -#endif - -#ifdef EINVAL - ERRNO_CASE(EINVAL); -#endif - -#ifdef EIO - ERRNO_CASE(EIO); -#endif - -#ifdef EISCONN - ERRNO_CASE(EISCONN); -#endif - -#ifdef EISDIR - ERRNO_CASE(EISDIR); -#endif - -#ifdef ELOOP - ERRNO_CASE(ELOOP); -#endif - -#ifdef EMFILE - ERRNO_CASE(EMFILE); -#endif - -#ifdef EMLINK - ERRNO_CASE(EMLINK); -#endif - -#ifdef EMSGSIZE - ERRNO_CASE(EMSGSIZE); -#endif - -#ifdef EMULTIHOP - ERRNO_CASE(EMULTIHOP); -#endif - -#ifdef ENAMETOOLONG - ERRNO_CASE(ENAMETOOLONG); -#endif - -#ifdef ENETDOWN - ERRNO_CASE(ENETDOWN); -#endif - -#ifdef ENETRESET - ERRNO_CASE(ENETRESET); -#endif - -#ifdef ENETUNREACH - ERRNO_CASE(ENETUNREACH); -#endif - -#ifdef ENFILE - ERRNO_CASE(ENFILE); -#endif - -#ifdef ENOBUFS - ERRNO_CASE(ENOBUFS); -#endif - -#ifdef ENODATA - ERRNO_CASE(ENODATA); -#endif - -#ifdef ENODEV - ERRNO_CASE(ENODEV); -#endif - -#ifdef ENOENT - ERRNO_CASE(ENOENT); -#endif - -#ifdef ENOEXEC - ERRNO_CASE(ENOEXEC); -#endif - -#ifdef ENOLINK - ERRNO_CASE(ENOLINK); -#endif - -#ifdef ENOLCK -# if ENOLINK != ENOLCK - ERRNO_CASE(ENOLCK); -# endif -#endif - -#ifdef ENOMEM - ERRNO_CASE(ENOMEM); -#endif - -#ifdef ENOMSG - ERRNO_CASE(ENOMSG); -#endif - -#ifdef ENOPROTOOPT - ERRNO_CASE(ENOPROTOOPT); -#endif - -#ifdef ENOSPC - ERRNO_CASE(ENOSPC); -#endif - -#ifdef ENOSR - ERRNO_CASE(ENOSR); -#endif - -#ifdef ENOSTR - ERRNO_CASE(ENOSTR); -#endif - -#ifdef ENOSYS - ERRNO_CASE(ENOSYS); -#endif - -#ifdef ENOTCONN - ERRNO_CASE(ENOTCONN); -#endif - -#ifdef ENOTDIR - ERRNO_CASE(ENOTDIR); -#endif - -#ifdef ENOTEMPTY -# if ENOTEMPTY != EEXIST - ERRNO_CASE(ENOTEMPTY); -# endif -#endif - -#ifdef ENOTSOCK - ERRNO_CASE(ENOTSOCK); -#endif - -#ifdef ENOTSUP - ERRNO_CASE(ENOTSUP); -#else -# ifdef EOPNOTSUPP - ERRNO_CASE(EOPNOTSUPP); -# endif -#endif - -#ifdef ENOTTY - ERRNO_CASE(ENOTTY); -#endif - -#ifdef ENXIO - ERRNO_CASE(ENXIO); -#endif - - -#ifdef EOVERFLOW - ERRNO_CASE(EOVERFLOW); -#endif - -#ifdef EPERM - ERRNO_CASE(EPERM); -#endif - -#ifdef EPIPE - ERRNO_CASE(EPIPE); -#endif - -#ifdef EPROTO - ERRNO_CASE(EPROTO); -#endif - -#ifdef EPROTONOSUPPORT - ERRNO_CASE(EPROTONOSUPPORT); -#endif - -#ifdef EPROTOTYPE - ERRNO_CASE(EPROTOTYPE); -#endif - -#ifdef ERANGE - ERRNO_CASE(ERANGE); -#endif - -#ifdef EROFS - ERRNO_CASE(EROFS); -#endif - -#ifdef ESPIPE - ERRNO_CASE(ESPIPE); -#endif - -#ifdef ESRCH - ERRNO_CASE(ESRCH); -#endif - -#ifdef ESTALE - ERRNO_CASE(ESTALE); -#endif - -#ifdef ETIME - ERRNO_CASE(ETIME); -#endif - -#ifdef ETIMEDOUT - ERRNO_CASE(ETIMEDOUT); -#endif - -#ifdef ETXTBSY - ERRNO_CASE(ETXTBSY); -#endif - -#ifdef EXDEV - ERRNO_CASE(EXDEV); -#endif - - default: return ""; - } -} - #define TRACING_CATEGORY_NODE "node" #define TRACING_CATEGORY_NODE1(one) \ TRACING_CATEGORY_NODE "," \