From 7be4a84c667f41da130163d083747dbd4187f1bd Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Mon, 16 Oct 2017 15:03:53 +0300 Subject: [PATCH] n-api: unexpose symbols and remove EXTERNAL_NAPI * namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope become part of Node's public symbols unless they are declared static. * the class uvimpl::Work needs to be enclosed in an anonymous namespace else it, too becomes part of Node's public symbols. * remove references to EXTERNAL_NAPI. PR-URL: https://github.com/nodejs/node/pull/16234 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson --- src/node_api.cc | 61 ++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/node_api.cc b/src/node_api.cc index 1c3d0915adcc5f..ad922d9ad195db 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -199,19 +199,23 @@ class EscapableHandleScopeWrapper { bool escape_called_; }; +static napi_handle_scope JsHandleScopeFromV8HandleScope(HandleScopeWrapper* s) { return reinterpret_cast(s); } +static HandleScopeWrapper* V8HandleScopeFromJsHandleScope(napi_handle_scope s) { return reinterpret_cast(s); } +static napi_escapable_handle_scope JsEscapableHandleScopeFromV8EscapableHandleScope( EscapableHandleScopeWrapper* s) { return reinterpret_cast(s); } +static EscapableHandleScopeWrapper* V8EscapableHandleScopeFromJsEscapableHandleScope( napi_escapable_handle_scope s) { @@ -225,18 +229,22 @@ V8EscapableHandleScopeFromJsEscapableHandleScope( static_assert(sizeof(v8::Local) == sizeof(napi_value), "Cannot convert between v8::Local and napi_value"); +static napi_deferred JsDeferredFromV8Persistent(v8::Persistent* local) { return reinterpret_cast(local); } +static v8::Persistent* V8PersistentFromJsDeferred(napi_deferred local) { return reinterpret_cast*>(local); } +static napi_value JsValueFromV8LocalValue(v8::Local local) { return reinterpret_cast(*local); } +static v8::Local V8LocalValueFromJsValue(napi_value v) { v8::Local local; memcpy(&local, &v, sizeof(v)); @@ -639,6 +647,7 @@ class SetterCallbackWrapper // Creates an object to be made available to the static function callback // wrapper, used to retrieve the native callback function and data pointer. +static v8::Local CreateFunctionCallbackData(napi_env env, napi_callback cb, void* data) { @@ -664,6 +673,7 @@ v8::Local CreateFunctionCallbackData(napi_env env, // Creates an object to be made available to the static getter/setter // callback wrapper, used to retrieve the native getter/setter callback // function and data pointer. +static v8::Local CreateAccessorCallbackData(napi_env env, napi_callback getter, napi_callback setter, @@ -706,6 +716,7 @@ const char napi_wrap_name[] = "N-API Wrapper"; // Search the object's prototype chain for the wrapper object. Usually the // wrapper would be the first in the chain, but it is OK for other objects to // be inserted in the prototype chain. +static bool FindWrapper(v8::Local obj, v8::Local* result = nullptr, v8::Local* parent = nullptr) { @@ -739,6 +750,7 @@ static void DeleteEnv(napi_env env, void* data, void* hint) { delete env; } +static napi_env GetEnv(v8::Local context) { napi_env result; @@ -774,6 +786,7 @@ napi_env GetEnv(v8::Local context) { return result; } +static napi_status Unwrap(napi_env env, napi_value js_object, void** result, @@ -797,6 +810,7 @@ napi_status Unwrap(napi_env env, return napi_ok; } +static napi_status ConcludeDeferred(napi_env env, napi_deferred deferred, napi_value result, @@ -856,12 +870,8 @@ void napi_module_register_cb(v8::Local exports, // Registers a NAPI module. void napi_module_register(napi_module* mod) { - int module_version = -1; -#ifdef EXTERNAL_NAPI - module_version = NODE_MODULE_VERSION; -#endif // EXTERNAL_NAPI node::node_module* nm = new node::node_module { - module_version, + -1, mod->nm_flags, nullptr, mod->nm_filename, @@ -875,6 +885,7 @@ void napi_module_register(napi_module* mod) { } // Warning: Keep in-sync with napi_status enum +static const char* error_messages[] = {nullptr, "Invalid argument", "An object was expected", @@ -1211,10 +1222,10 @@ napi_status napi_delete_property(napi_env env, return GET_RETURN_STATUS(env); } -NAPI_EXTERN napi_status napi_has_own_property(napi_env env, - napi_value object, - napi_value key, - bool* result) { +napi_status napi_has_own_property(napi_env env, + napi_value object, + napi_value key, + bool* result) { NAPI_PREAMBLE(env); CHECK_ARG(env, key); @@ -3239,6 +3250,7 @@ napi_status napi_adjust_external_memory(napi_env env, return napi_clear_last_error(env); } +namespace { namespace uvimpl { static napi_status ConvertUVErrorCode(int code) { @@ -3337,6 +3349,7 @@ class Work : public node::AsyncResource { }; } // end of namespace uvimpl +} // end of anonymous namespace #define CALL_UV(env, condition) \ do { \ @@ -3419,9 +3432,9 @@ napi_status napi_cancel_async_work(napi_env env, napi_async_work work) { return napi_clear_last_error(env); } -NAPI_EXTERN napi_status napi_create_promise(napi_env env, - napi_deferred* deferred, - napi_value* promise) { +napi_status napi_create_promise(napi_env env, + napi_deferred* deferred, + napi_value* promise) { NAPI_PREAMBLE(env); CHECK_ARG(env, deferred); CHECK_ARG(env, promise); @@ -3438,21 +3451,21 @@ NAPI_EXTERN napi_status napi_create_promise(napi_env env, return GET_RETURN_STATUS(env); } -NAPI_EXTERN napi_status napi_resolve_deferred(napi_env env, - napi_deferred deferred, - napi_value resolution) { +napi_status napi_resolve_deferred(napi_env env, + napi_deferred deferred, + napi_value resolution) { return v8impl::ConcludeDeferred(env, deferred, resolution, true); } -NAPI_EXTERN napi_status napi_reject_deferred(napi_env env, - napi_deferred deferred, - napi_value resolution) { +napi_status napi_reject_deferred(napi_env env, + napi_deferred deferred, + napi_value resolution) { return v8impl::ConcludeDeferred(env, deferred, resolution, false); } -NAPI_EXTERN napi_status napi_is_promise(napi_env env, - napi_value promise, - bool* is_promise) { +napi_status napi_is_promise(napi_env env, + napi_value promise, + bool* is_promise) { CHECK_ENV(env); CHECK_ARG(env, promise); CHECK_ARG(env, is_promise); @@ -3462,9 +3475,9 @@ NAPI_EXTERN napi_status napi_is_promise(napi_env env, return napi_clear_last_error(env); } -NAPI_EXTERN napi_status napi_run_script(napi_env env, - napi_value script, - napi_value* result) { +napi_status napi_run_script(napi_env env, + napi_value script, + napi_value* result) { NAPI_PREAMBLE(env); CHECK_ARG(env, script); CHECK_ARG(env, result);