Skip to content

Commit

Permalink
n-api: unexpose symbols and remove EXTERNAL_NAPI
Browse files Browse the repository at this point in the history
* 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: nodejs#16234
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
Gabriel Schulhof committed Oct 19, 2017
1 parent 4f1d548 commit 7be4a84
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,23 @@ class EscapableHandleScopeWrapper {
bool escape_called_;
};

static
napi_handle_scope JsHandleScopeFromV8HandleScope(HandleScopeWrapper* s) {
return reinterpret_cast<napi_handle_scope>(s);
}

static
HandleScopeWrapper* V8HandleScopeFromJsHandleScope(napi_handle_scope s) {
return reinterpret_cast<HandleScopeWrapper*>(s);
}

static
napi_escapable_handle_scope JsEscapableHandleScopeFromV8EscapableHandleScope(
EscapableHandleScopeWrapper* s) {
return reinterpret_cast<napi_escapable_handle_scope>(s);
}

static
EscapableHandleScopeWrapper*
V8EscapableHandleScopeFromJsEscapableHandleScope(
napi_escapable_handle_scope s) {
Expand All @@ -225,18 +229,22 @@ V8EscapableHandleScopeFromJsEscapableHandleScope(
static_assert(sizeof(v8::Local<v8::Value>) == sizeof(napi_value),
"Cannot convert between v8::Local<v8::Value> and napi_value");

static
napi_deferred JsDeferredFromV8Persistent(v8::Persistent<v8::Value>* local) {
return reinterpret_cast<napi_deferred>(local);
}

static
v8::Persistent<v8::Value>* V8PersistentFromJsDeferred(napi_deferred local) {
return reinterpret_cast<v8::Persistent<v8::Value>*>(local);
}

static
napi_value JsValueFromV8LocalValue(v8::Local<v8::Value> local) {
return reinterpret_cast<napi_value>(*local);
}

static
v8::Local<v8::Value> V8LocalValueFromJsValue(napi_value v) {
v8::Local<v8::Value> local;
memcpy(&local, &v, sizeof(v));
Expand Down Expand Up @@ -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<v8::Object> CreateFunctionCallbackData(napi_env env,
napi_callback cb,
void* data) {
Expand All @@ -664,6 +673,7 @@ v8::Local<v8::Object> 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<v8::Object> CreateAccessorCallbackData(napi_env env,
napi_callback getter,
napi_callback setter,
Expand Down Expand Up @@ -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<v8::Object> obj,
v8::Local<v8::Object>* result = nullptr,
v8::Local<v8::Object>* parent = nullptr) {
Expand Down Expand Up @@ -739,6 +750,7 @@ static void DeleteEnv(napi_env env, void* data, void* hint) {
delete env;
}

static
napi_env GetEnv(v8::Local<v8::Context> context) {
napi_env result;

Expand Down Expand Up @@ -774,6 +786,7 @@ napi_env GetEnv(v8::Local<v8::Context> context) {
return result;
}

static
napi_status Unwrap(napi_env env,
napi_value js_object,
void** result,
Expand All @@ -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,
Expand Down Expand Up @@ -856,12 +870,8 @@ void napi_module_register_cb(v8::Local<v8::Object> 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,
Expand All @@ -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",
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -3337,6 +3349,7 @@ class Work : public node::AsyncResource {
};

} // end of namespace uvimpl
} // end of anonymous namespace

#define CALL_UV(env, condition) \
do { \
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 7be4a84

Please sign in to comment.