From 5b5d95d3123c651afcdda55db846fda8e9e13efc Mon Sep 17 00:00:00 2001 From: legendecas Date: Thu, 25 Aug 2022 08:15:00 +0800 Subject: [PATCH] node-api: cleanup redundant static modifiers Functions declared in anonymous namespaces are not necessarily to be marked as static. PR-URL: https://github.com/nodejs/node/pull/44301 Refs: https://github.com/nodejs/node/pull/44141 Reviewed-By: Anna Henningsen Reviewed-By: Michael Dawson --- src/js_native_api_v8.cc | 34 ++++++++++++++++------------------ src/js_native_api_v8.h | 24 +++++++++++------------- src/node_api.cc | 5 +++-- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 5f8e21e0b58c8a..ecc3e00ce87a2d 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -61,7 +61,7 @@ namespace v8impl { namespace { -inline static napi_status V8NameFromPropertyDescriptor( +inline napi_status V8NameFromPropertyDescriptor( napi_env env, const napi_property_descriptor* p, v8::Local* result) { @@ -79,7 +79,7 @@ inline static napi_status V8NameFromPropertyDescriptor( } // convert from n-api property attributes to v8::PropertyAttribute -inline static v8::PropertyAttribute V8PropertyAttributesFromDescriptor( +inline v8::PropertyAttribute V8PropertyAttributesFromDescriptor( const napi_property_descriptor* descriptor) { unsigned int attribute_flags = v8::PropertyAttribute::None; @@ -100,12 +100,12 @@ inline static v8::PropertyAttribute V8PropertyAttributesFromDescriptor( return static_cast(attribute_flags); } -inline static napi_deferred JsDeferredFromNodePersistent( +inline napi_deferred JsDeferredFromNodePersistent( v8impl::Persistent* local) { return reinterpret_cast(local); } -inline static v8impl::Persistent* NodePersistentFromJsDeferred( +inline v8impl::Persistent* NodePersistentFromJsDeferred( napi_deferred local) { return reinterpret_cast*>(local); } @@ -139,32 +139,30 @@ class EscapableHandleScopeWrapper { bool escape_called_; }; -inline static napi_handle_scope JsHandleScopeFromV8HandleScope( - HandleScopeWrapper* s) { +inline napi_handle_scope JsHandleScopeFromV8HandleScope(HandleScopeWrapper* s) { return reinterpret_cast(s); } -inline static HandleScopeWrapper* V8HandleScopeFromJsHandleScope( - napi_handle_scope s) { +inline HandleScopeWrapper* V8HandleScopeFromJsHandleScope(napi_handle_scope s) { return reinterpret_cast(s); } -inline static napi_escapable_handle_scope +inline napi_escapable_handle_scope JsEscapableHandleScopeFromV8EscapableHandleScope( EscapableHandleScopeWrapper* s) { return reinterpret_cast(s); } -inline static EscapableHandleScopeWrapper* +inline EscapableHandleScopeWrapper* V8EscapableHandleScopeFromJsEscapableHandleScope( napi_escapable_handle_scope s) { return reinterpret_cast(s); } -inline static napi_status ConcludeDeferred(napi_env env, - napi_deferred deferred, - napi_value result, - bool is_resolved) { +inline napi_status ConcludeDeferred(napi_env env, + napi_deferred deferred, + napi_value result, + bool is_resolved) { NAPI_PREAMBLE(env); CHECK_ARG(env, result); @@ -191,10 +189,10 @@ inline static napi_status ConcludeDeferred(napi_env env, enum UnwrapAction { KeepWrap, RemoveWrap }; -inline static napi_status Unwrap(napi_env env, - napi_value js_object, - void** result, - UnwrapAction action) { +inline napi_status Unwrap(napi_env env, + napi_value js_object, + void** result, + UnwrapAction action) { NAPI_PREAMBLE(env); CHECK_ARG(env, js_object); if (action == KeepWrap) { diff --git a/src/js_native_api_v8.h b/src/js_native_api_v8.h index ac6e3f187b3078..8e9a06ed894362 100644 --- a/src/js_native_api_v8.h +++ b/src/js_native_api_v8.h @@ -1,8 +1,6 @@ #ifndef SRC_JS_NATIVE_API_V8_H_ #define SRC_JS_NATIVE_API_V8_H_ -// This file needs to be compatible with C compilers. -#include // NOLINT(modernize-deprecated-headers) #include "js_native_api_types.h" #include "js_native_api_v8_internals.h" @@ -152,7 +150,7 @@ class EnvRefHolder { napi_env _env; }; -static inline napi_status napi_clear_last_error(napi_env env) { +inline napi_status napi_clear_last_error(napi_env env) { env->last_error.error_code = napi_ok; // TODO(boingoing): Should this be a callback? @@ -162,10 +160,10 @@ static inline napi_status napi_clear_last_error(napi_env env) { return napi_ok; } -static inline napi_status napi_set_last_error(napi_env env, - napi_status error_code, - uint32_t engine_error_code = 0, - void* engine_reserved = nullptr) { +inline napi_status napi_set_last_error(napi_env env, + napi_status error_code, + uint32_t engine_error_code = 0, + void* engine_reserved = nullptr) { env->last_error.error_code = error_code; env->last_error.engine_error_code = engine_error_code; env->last_error.engine_reserved = engine_reserved; @@ -275,6 +273,12 @@ static inline napi_status napi_set_last_error(napi_env env, #define CHECK_MAYBE_EMPTY_WITH_PREAMBLE(env, maybe, status) \ RETURN_STATUS_IF_FALSE_WITH_PREAMBLE((env), !((maybe).IsEmpty()), (status)) +#define STATUS_CALL(call) \ + do { \ + napi_status status = (call); \ + if (status != napi_ok) return status; \ + } while (0) + namespace v8impl { //=== Conversion between V8 Handles and napi_value ======================== @@ -431,10 +435,4 @@ class Reference : public RefBase { } // end of namespace v8impl -#define STATUS_CALL(call) \ - do { \ - napi_status status = (call); \ - if (status != napi_ok) return status; \ - } while (0) - #endif // SRC_JS_NATIVE_API_V8_H_ diff --git a/src/node_api.cc b/src/node_api.cc index 08352b0a584b54..dfe27f43734238 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -16,6 +16,7 @@ #include "util-inl.h" #include +#include #include node_napi_env__::node_napi_env__(v8::Local context, @@ -124,8 +125,8 @@ class BufferFinalizer : private Finalizer { }; }; -static inline napi_env NewEnv(v8::Local context, - const std::string& module_filename) { +inline napi_env NewEnv(v8::Local context, + const std::string& module_filename) { node_napi_env result; result = new node_napi_env__(context, module_filename);