From 9d522225e7907b6cf631975b34f586984f698e33 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 12 Apr 2017 19:17:24 +0200 Subject: [PATCH] src: reduce number of exported symbols Use `static` definitions and anonymous namespaces to reduce the number of symbols that are exported from the `node` binary. PR-URL: https://github.com/nodejs/node/pull/12366 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- node.gyp | 2 -- src/cares_wrap.cc | 56 +++++++++++++++++++++-------------------- src/fs_event_wrap.cc | 3 +++ src/node.cc | 32 ++++++++++++----------- src/node_api.cc | 9 ++++--- src/node_buffer.cc | 6 ++++- src/node_config.cc | 6 ++--- src/node_constants.cc | 4 +++ src/node_contextify.cc | 2 ++ src/node_file.cc | 13 +++++----- src/node_file.h | 38 ---------------------------- src/node_http_parser.cc | 4 ++- src/node_http_parser.h | 39 ---------------------------- src/node_i18n.cc | 13 ++++++---- src/node_revert.cc | 2 +- src/node_serdes.cc | 3 +++ src/node_zlib.cc | 3 +++ src/process_wrap.cc | 3 +++ src/signal_wrap.cc | 3 +++ src/string_bytes.cc | 17 +++++++------ src/timer_wrap.cc | 2 ++ src/uv.cc | 12 ++++----- 22 files changed, 118 insertions(+), 154 deletions(-) delete mode 100644 src/node_file.h delete mode 100644 src/node_http_parser.h diff --git a/node.gyp b/node.gyp index 5f480001daa24d..db0531c0694d5a 100644 --- a/node.gyp +++ b/node.gyp @@ -222,8 +222,6 @@ 'src/node_buffer.h', 'src/node_constants.h', 'src/node_debug_options.h', - 'src/node_file.h', - 'src/node_http_parser.h', 'src/node_internals.h', 'src/node_javascript.h', 'src/node_mutex.h', diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 9fe20f15903e1e..2ff1470d603505 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -67,6 +67,7 @@ using v8::Object; using v8::String; using v8::Value; +namespace { inline const char* ToErrorCodeString(int status) { switch (status) { @@ -114,7 +115,7 @@ GetAddrInfoReqWrap::GetAddrInfoReqWrap(Environment* env, } -static void NewGetAddrInfoReqWrap(const FunctionCallbackInfo& args) { +void NewGetAddrInfoReqWrap(const FunctionCallbackInfo& args) { CHECK(args.IsConstructCall()); } @@ -133,17 +134,17 @@ GetNameInfoReqWrap::GetNameInfoReqWrap(Environment* env, } -static void NewGetNameInfoReqWrap(const FunctionCallbackInfo& args) { +void NewGetNameInfoReqWrap(const FunctionCallbackInfo& args) { CHECK(args.IsConstructCall()); } -static void NewQueryReqWrap(const FunctionCallbackInfo& args) { +void NewQueryReqWrap(const FunctionCallbackInfo& args) { CHECK(args.IsConstructCall()); } -static int cmp_ares_tasks(const node_ares_task* a, const node_ares_task* b) { +int cmp_ares_tasks(const node_ares_task* a, const node_ares_task* b) { if (a->sock < b->sock) return -1; if (a->sock > b->sock) @@ -158,14 +159,14 @@ RB_GENERATE_STATIC(node_ares_task_list, node_ares_task, node, cmp_ares_tasks) /* This is called once per second by loop->timer. It is used to constantly */ /* call back into c-ares for possibly processing timeouts. */ -static void ares_timeout(uv_timer_t* handle) { +void ares_timeout(uv_timer_t* handle) { Environment* env = Environment::from_cares_timer_handle(handle); CHECK_EQ(false, RB_EMPTY(env->cares_task_list())); ares_process_fd(env->cares_channel(), ARES_SOCKET_BAD, ARES_SOCKET_BAD); } -static void ares_poll_cb(uv_poll_t* watcher, int status, int events) { +void ares_poll_cb(uv_poll_t* watcher, int status, int events) { node_ares_task* task = ContainerOf(&node_ares_task::poll_watcher, watcher); Environment* env = task->env; @@ -186,7 +187,7 @@ static void ares_poll_cb(uv_poll_t* watcher, int status, int events) { } -static void ares_poll_close_cb(uv_handle_t* watcher) { +void ares_poll_close_cb(uv_handle_t* watcher) { node_ares_task* task = ContainerOf(&node_ares_task::poll_watcher, reinterpret_cast(watcher)); free(task); @@ -194,7 +195,7 @@ static void ares_poll_close_cb(uv_handle_t* watcher) { /* Allocates and returns a new node_ares_task */ -static node_ares_task* ares_task_create(Environment* env, ares_socket_t sock) { +node_ares_task* ares_task_create(Environment* env, ares_socket_t sock) { auto task = node::UncheckedMalloc(1); if (task == nullptr) { @@ -216,10 +217,10 @@ static node_ares_task* ares_task_create(Environment* env, ares_socket_t sock) { /* Callback from ares when socket operation is started */ -static void ares_sockstate_cb(void* data, - ares_socket_t sock, - int read, - int write) { +void ares_sockstate_cb(void* data, + ares_socket_t sock, + int read, + int write) { Environment* env = static_cast(data); node_ares_task* task; @@ -273,7 +274,7 @@ static void ares_sockstate_cb(void* data, } -static Local HostentToAddresses(Environment* env, struct hostent* host) { +Local HostentToAddresses(Environment* env, struct hostent* host) { EscapableHandleScope scope(env->isolate()); Local addresses = Array::New(env->isolate()); @@ -288,7 +289,7 @@ static Local HostentToAddresses(Environment* env, struct hostent* host) { } -static Local HostentToNames(Environment* env, struct hostent* host) { +Local HostentToNames(Environment* env, struct hostent* host) { EscapableHandleScope scope(env->isolate()); Local names = Array::New(env->isolate()); @@ -1105,7 +1106,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req, } -static void IsIP(const FunctionCallbackInfo& args) { +void IsIP(const FunctionCallbackInfo& args) { node::Utf8Value ip(args.GetIsolate(), args[0]); char address_buffer[sizeof(struct in6_addr)]; @@ -1118,7 +1119,7 @@ static void IsIP(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(rc); } -static void IsIPv4(const FunctionCallbackInfo& args) { +void IsIPv4(const FunctionCallbackInfo& args) { node::Utf8Value ip(args.GetIsolate(), args[0]); char address_buffer[sizeof(struct in_addr)]; @@ -1129,7 +1130,7 @@ static void IsIPv4(const FunctionCallbackInfo& args) { } } -static void IsIPv6(const FunctionCallbackInfo& args) { +void IsIPv6(const FunctionCallbackInfo& args) { node::Utf8Value ip(args.GetIsolate(), args[0]); char address_buffer[sizeof(struct in6_addr)]; @@ -1140,7 +1141,7 @@ static void IsIPv6(const FunctionCallbackInfo& args) { } } -static void GetAddrInfo(const FunctionCallbackInfo& args) { +void GetAddrInfo(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsObject()); @@ -1188,7 +1189,7 @@ static void GetAddrInfo(const FunctionCallbackInfo& args) { } -static void GetNameInfo(const FunctionCallbackInfo& args) { +void GetNameInfo(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsObject()); @@ -1217,7 +1218,7 @@ static void GetNameInfo(const FunctionCallbackInfo& args) { } -static void GetServers(const FunctionCallbackInfo& args) { +void GetServers(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Local server_array = Array::New(env->isolate()); @@ -1246,7 +1247,7 @@ static void GetServers(const FunctionCallbackInfo& args) { } -static void SetServers(const FunctionCallbackInfo& args) { +void SetServers(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsArray()); @@ -1313,30 +1314,30 @@ static void SetServers(const FunctionCallbackInfo& args) { } -static void StrError(const FunctionCallbackInfo& args) { +void StrError(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); const char* errmsg = ares_strerror(args[0]->Int32Value()); args.GetReturnValue().Set(OneByteString(env->isolate(), errmsg)); } -static void CaresTimerCloseCb(uv_handle_t* handle) { +void CaresTimerCloseCb(uv_handle_t* handle) { Environment* env = Environment::from_cares_timer_handle( reinterpret_cast(handle)); env->FinishHandleCleanup(handle); } -static void CaresTimerClose(Environment* env, +void CaresTimerClose(Environment* env, uv_handle_t* handle, void* arg) { uv_close(handle, CaresTimerCloseCb); } -static void Initialize(Local target, - Local unused, - Local context) { +void Initialize(Local target, + Local unused, + Local context) { Environment* env = Environment::GetCurrent(context); int r = ares_library_init(ARES_LIB_INIT_ALL); @@ -1424,6 +1425,7 @@ static void Initialize(Local target, qrw->GetFunction()); } +} // anonymous namespace } // namespace cares_wrap } // namespace node diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index ce272362c420ee..a747f71c40c1ae 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -43,6 +43,8 @@ using v8::Object; using v8::String; using v8::Value; +namespace { + class FSEventWrap: public HandleWrap { public: static void Initialize(Local target, @@ -214,6 +216,7 @@ void FSEventWrap::Close(const FunctionCallbackInfo& args) { HandleWrap::Close(args); } +} // anonymous namespace } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(fs_event_wrap, node::FSEventWrap::Initialize) diff --git a/src/node.cc b/src/node.cc index 84a883845d916b..a24dcdb734e79b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -22,8 +22,6 @@ #include "node.h" #include "node_buffer.h" #include "node_constants.h" -#include "node_file.h" -#include "node_http_parser.h" #include "node_javascript.h" #include "node_version.h" #include "node_internals.h" @@ -1049,8 +1047,10 @@ void* ArrayBufferAllocator::Allocate(size_t size) { return node::UncheckedMalloc(size); } -static bool DomainHasErrorHandler(const Environment* env, - const Local& domain) { +namespace { + +bool DomainHasErrorHandler(const Environment* env, + const Local& domain) { HandleScope scope(env->isolate()); Local domain_event_listeners_v = domain->Get(env->events_string()); @@ -1071,7 +1071,7 @@ static bool DomainHasErrorHandler(const Environment* env, return false; } -static bool DomainsStackHasErrorHandler(const Environment* env) { +bool DomainsStackHasErrorHandler(const Environment* env) { HandleScope scope(env->isolate()); if (!env->using_domains()) @@ -1096,7 +1096,7 @@ static bool DomainsStackHasErrorHandler(const Environment* env) { } -static bool ShouldAbortOnUncaughtException(Isolate* isolate) { +bool ShouldAbortOnUncaughtException(Isolate* isolate) { HandleScope scope(isolate); Environment* env = Environment::GetCurrent(isolate); @@ -1226,6 +1226,8 @@ void SetupPromises(const FunctionCallbackInfo& args) { FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupPromises")).FromJust(); } +} // anonymous namespace + Local MakeCallback(Environment* env, Local recv, @@ -2274,7 +2276,7 @@ static void WaitForInspectorDisconnect(Environment* env) { } -void Exit(const FunctionCallbackInfo& args) { +static void Exit(const FunctionCallbackInfo& args) { WaitForInspectorDisconnect(Environment::GetCurrent(args)); exit(args[0]->Int32Value()); } @@ -2291,7 +2293,7 @@ static void Uptime(const FunctionCallbackInfo& args) { } -void MemoryUsage(const FunctionCallbackInfo& args) { +static void MemoryUsage(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); size_t rss; @@ -2319,7 +2321,7 @@ void MemoryUsage(const FunctionCallbackInfo& args) { } -void Kill(const FunctionCallbackInfo& args) { +static void Kill(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); if (args.Length() != 2) { @@ -2343,7 +2345,7 @@ void Kill(const FunctionCallbackInfo& args) { // broken into the upper/lower 32 bits to be converted back in JS, // because there is no Uint64Array in JS. // The third entry contains the remaining nanosecond part of the value. -void Hrtime(const FunctionCallbackInfo& args) { +static void Hrtime(const FunctionCallbackInfo& args) { uint64_t t = uv_hrtime(); Local ab = args[0].As()->Buffer(); @@ -2362,7 +2364,7 @@ void Hrtime(const FunctionCallbackInfo& args) { // which are uv_timeval_t structs (long tv_sec, long tv_usec). // Returns those values as Float64 microseconds in the elements of the array // passed to the function. -void CPUUsage(const FunctionCallbackInfo& args) { +static void CPUUsage(const FunctionCallbackInfo& args) { uv_rusage_t rusage; // Call libuv to get the values we'll return. @@ -2433,7 +2435,7 @@ struct node_module* get_linked_module(const char* name) { // FIXME(bnoordhuis) Not multi-context ready. TBD how to resolve the conflict // when two contexts try to load the same shared object. Maybe have a shadow // cache that's a plain C list or hash table that's shared across contexts? -void DLOpen(const FunctionCallbackInfo& args) { +static void DLOpen(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); uv_lib_t lib; @@ -2602,7 +2604,7 @@ void FatalException(Isolate* isolate, const TryCatch& try_catch) { } -void OnMessage(Local message, Local error) { +static void OnMessage(Local message, Local error) { // The current version of V8 sends messages for errors only // (thus `error` is always set). FatalException(Isolate::GetCurrent(), error, message); @@ -3010,6 +3012,7 @@ static void DebugProcess(const FunctionCallbackInfo& args); static void DebugPause(const FunctionCallbackInfo& args); static void DebugEnd(const FunctionCallbackInfo& args); +namespace { void NeedImmediateCallbackGetter(Local property, const PropertyCallbackInfo& info) { @@ -3021,7 +3024,7 @@ void NeedImmediateCallbackGetter(Local property, } -static void NeedImmediateCallbackSetter( +void NeedImmediateCallbackSetter( Local property, Local value, const PropertyCallbackInfo& info) { @@ -3077,6 +3080,7 @@ void StopProfilerIdleNotifier(const FunctionCallbackInfo& args) { .FromJust(); \ } while (0) +} // anonymous namespace void SetupProcessObject(Environment* env, int argc, diff --git a/src/node_api.cc b/src/node_api.cc index 949f4f0404ce25..f59dcae4e11e2d 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -17,9 +17,11 @@ #include "node_api.h" #include "env-inl.h" +static napi_status napi_set_last_error(napi_env env, napi_status error_code, uint32_t engine_error_code = 0, void* engine_reserved = nullptr); +static void napi_clear_last_error(napi_env env); struct napi_env__ { @@ -100,6 +102,7 @@ struct napi_env__ { (!try_catch.HasCaught() ? napi_ok \ : napi_set_last_error((env), napi_pending_exception)) +namespace { namespace v8impl { // convert from n-api property attributes to v8::PropertyAttribute @@ -126,10 +129,6 @@ static inline v8::PropertyAttribute V8PropertyAttributesFromDescriptor( return static_cast(attribute_flags); } -v8::Isolate* V8IsolateFromJsEnv(napi_env e) { - return reinterpret_cast(e); -} - class HandleScopeWrapper { public: explicit HandleScopeWrapper(v8::Isolate* isolate) : scope(isolate) {} @@ -660,6 +659,8 @@ void napi_module_register_cb(v8::Local exports, mod->nm_priv); } +} // end of anonymous namespace + #ifndef EXTERNAL_NAPI namespace node { // Indicates whether NAPI was enabled/disabled via the node command-line. diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 50760df8a3887e..e8d70d329a992a 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -87,6 +87,8 @@ using v8::Uint8Array; using v8::Value; using v8::WeakCallbackInfo; +namespace { + class CallbackInfo { public: static inline void Free(char* data, void* hint); @@ -192,6 +194,7 @@ inline MUST_USE_RESULT bool ParseArrayIndex(Local arg, return true; } +} // anonymous namespace // Buffer methods @@ -434,6 +437,7 @@ MaybeLocal New(Environment* env, char* data, size_t length) { return Local(); } +namespace { void CreateFromString(const FunctionCallbackInfo& args) { CHECK(args[0]->IsString()); @@ -1285,7 +1289,7 @@ void Initialize(Local target, Integer::New(env->isolate(), String::kMaxLength)).FromJust(); } - +} // anonymous namespace } // namespace Buffer } // namespace node diff --git a/src/node_config.cc b/src/node_config.cc index 3c082d61943a7c..05a163c3f1e4df 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -27,9 +27,9 @@ using v8::Value; True(env->isolate()), ReadOnly).FromJust(); \ } while (0) -void InitConfig(Local target, - Local unused, - Local context) { +static void InitConfig(Local target, + Local unused, + Local context) { Environment* env = Environment::GetCurrent(context); #ifdef NODE_HAVE_I18N_SUPPORT diff --git a/src/node_constants.cc b/src/node_constants.cc index 8bc95392f26bcf..0e178602b73742 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -53,6 +53,8 @@ using v8::Object; const char* default_cipher_list = DEFAULT_CIPHER_LIST_CORE; #endif +namespace { + void DefineErrnoConstants(Local target) { #ifdef E2BIG NODE_DEFINE_CONSTANT(target, E2BIG); @@ -1256,6 +1258,8 @@ void DefineZlibConstants(Local target) { NODE_DEFINE_CONSTANT(target, Z_DEFAULT_LEVEL); } +} // anonymous namespace + void DefineConstants(v8::Isolate* isolate, Local target) { Environment* env = Environment::GetCurrent(isolate); diff --git a/src/node_contextify.cc b/src/node_contextify.cc index bc6c468aaf4218..a169d1b8325934 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -65,6 +65,7 @@ using v8::UnboundScript; using v8::Value; using v8::WeakCallbackInfo; +namespace { class ContextifyContext { protected: @@ -963,6 +964,7 @@ void InitContextify(Local target, ContextifyScript::Init(env, target); } +} // anonymous namespace } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(contextify, node::InitContextify); diff --git a/src/node_file.cc b/src/node_file.cc index 9c180833fb926f..9d00bb475d21da 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -20,7 +20,6 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. #include "node.h" -#include "node_file.h" #include "node_buffer.h" #include "node_internals.h" #include "node_stat_watcher.h" @@ -46,6 +45,7 @@ #include namespace node { +namespace { using v8::Array; using v8::ArrayBuffer; @@ -148,16 +148,16 @@ void FSReqWrap::Dispose() { } -static void NewFSReqWrap(const FunctionCallbackInfo& args) { +void NewFSReqWrap(const FunctionCallbackInfo& args) { CHECK(args.IsConstructCall()); } -static inline bool IsInt64(double x) { +inline bool IsInt64(double x) { return x == static_cast(static_cast(x)); } -static void After(uv_fs_t *req) { +void After(uv_fs_t *req) { FSReqWrap* req_wrap = static_cast(req->data); CHECK_EQ(req_wrap->req(), req); req_wrap->ReleaseEarly(); // Free memory that's no longer used now. @@ -401,7 +401,7 @@ class fs_req_wrap { #define SYNC_RESULT err -static void Access(const FunctionCallbackInfo& args) { +void Access(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope scope(env->isolate()); @@ -423,7 +423,7 @@ static void Access(const FunctionCallbackInfo& args) { } -static void Close(const FunctionCallbackInfo& args) { +void Close(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); if (args.Length() < 1) @@ -440,6 +440,7 @@ static void Close(const FunctionCallbackInfo& args) { } } +} // anonymous namespace void FillStatsArray(double* fields, const uv_stat_t* s) { fields[0] = s->st_dev; diff --git a/src/node_file.h b/src/node_file.h deleted file mode 100644 index c7ba9417fa0d2b..00000000000000 --- a/src/node_file.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -#ifndef SRC_NODE_FILE_H_ -#define SRC_NODE_FILE_H_ - -#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#include "node.h" -#include "v8.h" - -namespace node { - -void InitFs(v8::Local target); - -} // namespace node - -#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#endif // SRC_NODE_FILE_H_ diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 38450148b706a8..d504f42f35107b 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -21,12 +21,12 @@ #include "node.h" #include "node_buffer.h" -#include "node_http_parser.h" #include "async-wrap.h" #include "async-wrap-inl.h" #include "env.h" #include "env-inl.h" +#include "http_parser.h" #include "stream_base.h" #include "stream_base-inl.h" #include "util.h" @@ -49,6 +49,7 @@ namespace node { +namespace { using v8::Array; using v8::Boolean; @@ -798,6 +799,7 @@ void InitHttpParser(Local target, t->GetFunction()); } +} // anonymous namespace } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(http_parser, node::InitHttpParser) diff --git a/src/node_http_parser.h b/src/node_http_parser.h deleted file mode 100644 index a785d46cc10bfc..00000000000000 --- a/src/node_http_parser.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -#ifndef SRC_NODE_HTTP_PARSER_H_ -#define SRC_NODE_HTTP_PARSER_H_ - -#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#include "v8.h" - -#include "http_parser.h" - -namespace node { - -void InitHttpParser(v8::Local target); - -} // namespace node - -#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#endif // SRC_NODE_HTTP_PARSER_H_ diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 284f9b0b6c8042..13fb77b15d3654 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -93,6 +93,7 @@ using v8::String; using v8::Value; namespace i18n { +namespace { template MaybeLocal ToBufferEndian(Environment* env, MaybeStackBuffer* buf) { @@ -344,7 +345,7 @@ void Transcode(const FunctionCallbackInfo&args) { return args.GetReturnValue().Set(result.ToLocalChecked()); } -static void ICUErrorName(const FunctionCallbackInfo& args) { +void ICUErrorName(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); UErrorCode status = static_cast(args[0]->Int32Value()); args.GetReturnValue().Set( @@ -366,9 +367,9 @@ static void ICUErrorName(const FunctionCallbackInfo& args) { * @param status ICU error status. If failure, assume result is undefined. * @return version number, or NULL. May or may not be buf. */ -static const char* GetVersion(const char* type, - char buf[U_MAX_VERSION_STRING_LENGTH], - UErrorCode* status) { +const char* GetVersion(const char* type, + char buf[U_MAX_VERSION_STRING_LENGTH], + UErrorCode* status) { if (!strcmp(type, TYPE_ICU)) { return U_ICU_VERSION; } else if (!strcmp(type, TYPE_UNICODE)) { @@ -387,7 +388,7 @@ static const char* GetVersion(const char* type, return nullptr; } -static void GetVersion(const FunctionCallbackInfo& args) { +void GetVersion(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); if ( args.Length() == 0 ) { // With no args - return a comma-separated list of allowed values @@ -414,6 +415,8 @@ static void GetVersion(const FunctionCallbackInfo& args) { } } +} // anonymous namespace + bool InitializeICUDirectory(const std::string& path) { if (path.empty()) { UErrorCode status = U_ZERO_ERROR; diff --git a/src/node_revert.cc b/src/node_revert.cc index 48f03a89a3131e..9d029a3592fd0c 100644 --- a/src/node_revert.cc +++ b/src/node_revert.cc @@ -6,7 +6,7 @@ namespace node { unsigned int reverted = 0; -const char* RevertMessage(const unsigned int cve) { +static const char* RevertMessage(const unsigned int cve) { #define V(code, label, msg) case REVERT_ ## code: return label ": " msg; switch (cve) { REVERSIONS(V) diff --git a/src/node_serdes.cc b/src/node_serdes.cc index 13bc27685d15dd..a077598dfe4cbf 100644 --- a/src/node_serdes.cc +++ b/src/node_serdes.cc @@ -28,6 +28,8 @@ using v8::Value; using v8::ValueDeserializer; using v8::ValueSerializer; +namespace { + class SerializerContext : public BaseObject, public ValueSerializer::Delegate { public: @@ -478,6 +480,7 @@ void InitializeSerdesBindings(Local target, des->GetFunction(env->context()).ToLocalChecked()).FromJust(); } +} // anonymous namespace } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(serdes, node::InitializeSerdesBindings) diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 2214f1cd1ecf54..bad7e7e82bc526 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -50,6 +50,8 @@ using v8::Number; using v8::Object; using v8::Value; +namespace { + enum node_zlib_mode { NONE, DEFLATE, @@ -693,6 +695,7 @@ void InitZlib(Local target, FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION)); } +} // anonymous namespace } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(zlib, node::InitZlib) diff --git a/src/process_wrap.cc b/src/process_wrap.cc index c067d5c9d8a765..2780adad74afca 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -43,6 +43,8 @@ using v8::Object; using v8::String; using v8::Value; +namespace { + class ProcessWrap : public HandleWrap { public: static void Initialize(Local target, @@ -273,6 +275,7 @@ class ProcessWrap : public HandleWrap { }; +} // anonymous namespace } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(process_wrap, node::ProcessWrap::Initialize) diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index 55f1563438362f..36b862ce82523f 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -39,6 +39,8 @@ using v8::Local; using v8::Object; using v8::Value; +namespace { + class SignalWrap : public HandleWrap { public: static void Initialize(Local target, @@ -119,6 +121,7 @@ class SignalWrap : public HandleWrap { }; +} // anonymous namespace } // namespace node diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 39239592595e7a..0954b0f244ec10 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -46,6 +46,8 @@ using v8::Object; using v8::String; using v8::Value; +namespace { + template class ExternString: public ResourceType { public: @@ -141,6 +143,7 @@ MaybeLocal ExternTwoByteString::NewExternal( return String::NewExternalTwoByte(isolate, h_str); } +} // anonymous namespace // supports regular and URL-safe base64 const int8_t unbase64_table[256] = @@ -182,15 +185,15 @@ static const int8_t unhex_table[256] = -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; -#define unhex(x) \ - static_cast(unhex_table[static_cast(x)]) - +static inline unsigned unhex(uint8_t x) { + return unhex_table[x]; +} template -size_t hex_decode(char* buf, - size_t len, - const TypeName* src, - const size_t srcLen) { +static size_t hex_decode(char* buf, + size_t len, + const TypeName* src, + const size_t srcLen) { size_t i; for (i = 0; i < len && i * 2 + 1 < srcLen; ++i) { unsigned a = unhex(src[i * 2 + 0]); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 8ffe934a21e0fb..382bcaacb6c02d 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -30,6 +30,7 @@ #include namespace node { +namespace { using v8::Context; using v8::FunctionCallbackInfo; @@ -132,6 +133,7 @@ class TimerWrap : public HandleWrap { }; +} // anonymous namespace } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(timer_wrap, node::TimerWrap::Initialize) diff --git a/src/uv.cc b/src/uv.cc index aec63696d1ec94..3e345374a2ef74 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -25,7 +25,7 @@ #include "env-inl.h" namespace node { -namespace uv { +namespace { using v8::Context; using v8::FunctionCallbackInfo; @@ -45,9 +45,9 @@ void ErrName(const FunctionCallbackInfo& args) { } -void Initialize(Local target, - Local unused, - Local context) { +void InitializeUV(Local target, + Local unused, + Local context) { Environment* env = Environment::GetCurrent(context); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "errname"), env->NewFunctionTemplate(ErrName)->GetFunction()); @@ -59,7 +59,7 @@ void Initialize(Local target, } -} // namespace uv +} // anonymous namespace } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(uv, node::uv::Initialize) +NODE_MODULE_CONTEXT_AWARE_BUILTIN(uv, node::InitializeUV)