Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

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/node#16234
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
Gabriel Schulhof authored and addaleax committed Oct 26, 2017
1 parent 41d4842 commit 6da35d7
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 Down Expand Up @@ -897,6 +907,7 @@ napi_status napi_remove_env_cleanup_hook(napi_env env,
}

// Warning: Keep in-sync with napi_status enum
static
const char* error_messages[] = {nullptr,
"Invalid argument",
"An object was expected",
Expand Down Expand Up @@ -1233,10 +1244,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 @@ -3261,6 +3272,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 @@ -3362,6 +3374,7 @@ class Work : public node::AsyncResource {
};

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

#define CALL_UV(env, condition) \
do { \
Expand Down Expand Up @@ -3443,9 +3456,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 @@ -3462,21 +3475,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 @@ -3486,9 +3499,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 6da35d7

Please sign in to comment.