Skip to content

Commit 7be4a84

Browse files
author
Gabriel Schulhof
committed
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: #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]>
1 parent 4f1d548 commit 7be4a84

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

src/node_api.cc

+37-24
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,23 @@ class EscapableHandleScopeWrapper {
199199
bool escape_called_;
200200
};
201201

202+
static
202203
napi_handle_scope JsHandleScopeFromV8HandleScope(HandleScopeWrapper* s) {
203204
return reinterpret_cast<napi_handle_scope>(s);
204205
}
205206

207+
static
206208
HandleScopeWrapper* V8HandleScopeFromJsHandleScope(napi_handle_scope s) {
207209
return reinterpret_cast<HandleScopeWrapper*>(s);
208210
}
209211

212+
static
210213
napi_escapable_handle_scope JsEscapableHandleScopeFromV8EscapableHandleScope(
211214
EscapableHandleScopeWrapper* s) {
212215
return reinterpret_cast<napi_escapable_handle_scope>(s);
213216
}
214217

218+
static
215219
EscapableHandleScopeWrapper*
216220
V8EscapableHandleScopeFromJsEscapableHandleScope(
217221
napi_escapable_handle_scope s) {
@@ -225,18 +229,22 @@ V8EscapableHandleScopeFromJsEscapableHandleScope(
225229
static_assert(sizeof(v8::Local<v8::Value>) == sizeof(napi_value),
226230
"Cannot convert between v8::Local<v8::Value> and napi_value");
227231

232+
static
228233
napi_deferred JsDeferredFromV8Persistent(v8::Persistent<v8::Value>* local) {
229234
return reinterpret_cast<napi_deferred>(local);
230235
}
231236

237+
static
232238
v8::Persistent<v8::Value>* V8PersistentFromJsDeferred(napi_deferred local) {
233239
return reinterpret_cast<v8::Persistent<v8::Value>*>(local);
234240
}
235241

242+
static
236243
napi_value JsValueFromV8LocalValue(v8::Local<v8::Value> local) {
237244
return reinterpret_cast<napi_value>(*local);
238245
}
239246

247+
static
240248
v8::Local<v8::Value> V8LocalValueFromJsValue(napi_value v) {
241249
v8::Local<v8::Value> local;
242250
memcpy(&local, &v, sizeof(v));
@@ -639,6 +647,7 @@ class SetterCallbackWrapper
639647

640648
// Creates an object to be made available to the static function callback
641649
// wrapper, used to retrieve the native callback function and data pointer.
650+
static
642651
v8::Local<v8::Object> CreateFunctionCallbackData(napi_env env,
643652
napi_callback cb,
644653
void* data) {
@@ -664,6 +673,7 @@ v8::Local<v8::Object> CreateFunctionCallbackData(napi_env env,
664673
// Creates an object to be made available to the static getter/setter
665674
// callback wrapper, used to retrieve the native getter/setter callback
666675
// function and data pointer.
676+
static
667677
v8::Local<v8::Object> CreateAccessorCallbackData(napi_env env,
668678
napi_callback getter,
669679
napi_callback setter,
@@ -706,6 +716,7 @@ const char napi_wrap_name[] = "N-API Wrapper";
706716
// Search the object's prototype chain for the wrapper object. Usually the
707717
// wrapper would be the first in the chain, but it is OK for other objects to
708718
// be inserted in the prototype chain.
719+
static
709720
bool FindWrapper(v8::Local<v8::Object> obj,
710721
v8::Local<v8::Object>* result = nullptr,
711722
v8::Local<v8::Object>* parent = nullptr) {
@@ -739,6 +750,7 @@ static void DeleteEnv(napi_env env, void* data, void* hint) {
739750
delete env;
740751
}
741752

753+
static
742754
napi_env GetEnv(v8::Local<v8::Context> context) {
743755
napi_env result;
744756

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

789+
static
777790
napi_status Unwrap(napi_env env,
778791
napi_value js_object,
779792
void** result,
@@ -797,6 +810,7 @@ napi_status Unwrap(napi_env env,
797810
return napi_ok;
798811
}
799812

813+
static
800814
napi_status ConcludeDeferred(napi_env env,
801815
napi_deferred deferred,
802816
napi_value result,
@@ -856,12 +870,8 @@ void napi_module_register_cb(v8::Local<v8::Object> exports,
856870

857871
// Registers a NAPI module.
858872
void napi_module_register(napi_module* mod) {
859-
int module_version = -1;
860-
#ifdef EXTERNAL_NAPI
861-
module_version = NODE_MODULE_VERSION;
862-
#endif // EXTERNAL_NAPI
863873
node::node_module* nm = new node::node_module {
864-
module_version,
874+
-1,
865875
mod->nm_flags,
866876
nullptr,
867877
mod->nm_filename,
@@ -875,6 +885,7 @@ void napi_module_register(napi_module* mod) {
875885
}
876886

877887
// Warning: Keep in-sync with napi_status enum
888+
static
878889
const char* error_messages[] = {nullptr,
879890
"Invalid argument",
880891
"An object was expected",
@@ -1211,10 +1222,10 @@ napi_status napi_delete_property(napi_env env,
12111222
return GET_RETURN_STATUS(env);
12121223
}
12131224

1214-
NAPI_EXTERN napi_status napi_has_own_property(napi_env env,
1215-
napi_value object,
1216-
napi_value key,
1217-
bool* result) {
1225+
napi_status napi_has_own_property(napi_env env,
1226+
napi_value object,
1227+
napi_value key,
1228+
bool* result) {
12181229
NAPI_PREAMBLE(env);
12191230
CHECK_ARG(env, key);
12201231

@@ -3239,6 +3250,7 @@ napi_status napi_adjust_external_memory(napi_env env,
32393250
return napi_clear_last_error(env);
32403251
}
32413252

3253+
namespace {
32423254
namespace uvimpl {
32433255

32443256
static napi_status ConvertUVErrorCode(int code) {
@@ -3337,6 +3349,7 @@ class Work : public node::AsyncResource {
33373349
};
33383350

33393351
} // end of namespace uvimpl
3352+
} // end of anonymous namespace
33403353

33413354
#define CALL_UV(env, condition) \
33423355
do { \
@@ -3419,9 +3432,9 @@ napi_status napi_cancel_async_work(napi_env env, napi_async_work work) {
34193432
return napi_clear_last_error(env);
34203433
}
34213434

3422-
NAPI_EXTERN napi_status napi_create_promise(napi_env env,
3423-
napi_deferred* deferred,
3424-
napi_value* promise) {
3435+
napi_status napi_create_promise(napi_env env,
3436+
napi_deferred* deferred,
3437+
napi_value* promise) {
34253438
NAPI_PREAMBLE(env);
34263439
CHECK_ARG(env, deferred);
34273440
CHECK_ARG(env, promise);
@@ -3438,21 +3451,21 @@ NAPI_EXTERN napi_status napi_create_promise(napi_env env,
34383451
return GET_RETURN_STATUS(env);
34393452
}
34403453

3441-
NAPI_EXTERN napi_status napi_resolve_deferred(napi_env env,
3442-
napi_deferred deferred,
3443-
napi_value resolution) {
3454+
napi_status napi_resolve_deferred(napi_env env,
3455+
napi_deferred deferred,
3456+
napi_value resolution) {
34443457
return v8impl::ConcludeDeferred(env, deferred, resolution, true);
34453458
}
34463459

3447-
NAPI_EXTERN napi_status napi_reject_deferred(napi_env env,
3448-
napi_deferred deferred,
3449-
napi_value resolution) {
3460+
napi_status napi_reject_deferred(napi_env env,
3461+
napi_deferred deferred,
3462+
napi_value resolution) {
34503463
return v8impl::ConcludeDeferred(env, deferred, resolution, false);
34513464
}
34523465

3453-
NAPI_EXTERN napi_status napi_is_promise(napi_env env,
3454-
napi_value promise,
3455-
bool* is_promise) {
3466+
napi_status napi_is_promise(napi_env env,
3467+
napi_value promise,
3468+
bool* is_promise) {
34563469
CHECK_ENV(env);
34573470
CHECK_ARG(env, promise);
34583471
CHECK_ARG(env, is_promise);
@@ -3462,9 +3475,9 @@ NAPI_EXTERN napi_status napi_is_promise(napi_env env,
34623475
return napi_clear_last_error(env);
34633476
}
34643477

3465-
NAPI_EXTERN napi_status napi_run_script(napi_env env,
3466-
napi_value script,
3467-
napi_value* result) {
3478+
napi_status napi_run_script(napi_env env,
3479+
napi_value script,
3480+
napi_value* result) {
34683481
NAPI_PREAMBLE(env);
34693482
CHECK_ARG(env, script);
34703483
CHECK_ARG(env, result);

0 commit comments

Comments
 (0)