@@ -363,31 +363,32 @@ class Work : AutoCloseable {
363363 std::atomic_bool canceled_{false };
364364};
365365
366- napi_status napi_create_async_work (napi_env env, napi_value async_resource,
367- napi_value async_resource_name,
368- napi_async_execute_callback execute,
369- napi_async_complete_callback complete,
370- void * data, napi_async_work* result) {
366+ napi_status napi_create_async_work_internal (
367+ napi_env env, napi_value async_resource, napi_value async_resource_name,
368+ napi_async_execute_callback execute, napi_async_complete_callback complete,
369+ void * data, napi_async_work* result) {
371370 *result = reinterpret_cast <napi_async_work>(
372371 Work::New (env->rt , execute, complete, data));
373372 return napi_clear_last_error (env);
374373}
375374
376- napi_status napi_delete_async_work (napi_env env, napi_async_work work) {
375+ napi_status napi_delete_async_work_internal (napi_env env,
376+ napi_async_work work) {
377377 Work::Delete (reinterpret_cast <Work*>(work));
378378
379379 return napi_clear_last_error (env);
380380}
381381
382- napi_status napi_queue_async_work (napi_env env, napi_async_work work) {
382+ napi_status napi_queue_async_work_internal (napi_env env, napi_async_work work) {
383383 Work* w = reinterpret_cast <Work*>(work);
384384
385385 w->ScheduleWork ();
386386
387387 return napi_clear_last_error (env);
388388}
389389
390- napi_status napi_cancel_async_work (napi_env env, napi_async_work work) {
390+ napi_status napi_cancel_async_work_internal (napi_env env,
391+ napi_async_work work) {
391392 Work* w = reinterpret_cast <Work*>(work);
392393
393394 if (!w->CancelWork ()) {
@@ -599,7 +600,7 @@ class ThreadSafeFunction {
599600 std::shared_ptr<Mutex<SharedState>> state_;
600601};
601602
602- napi_status napi_create_threadsafe_function (
603+ napi_status napi_create_threadsafe_function_internal (
603604 napi_env env, void * thread_finalize_data, napi_finalize thread_finalize_cb,
604605 void * context, napi_threadsafe_function_call_js call_js_cb,
605606 napi_threadsafe_function* result) {
@@ -611,23 +612,6 @@ napi_status napi_create_threadsafe_function(
611612 return napi_clear_last_error (env);
612613}
613614
614- napi_status napi_get_threadsafe_function_context (napi_threadsafe_function func,
615- void ** result) {
616- *result = reinterpret_cast <ThreadSafeFunction*>(func)->Context ();
617- return napi_ok;
618- }
619-
620- napi_status napi_call_threadsafe_function (
621- napi_threadsafe_function func, void * data,
622- napi_threadsafe_function_call_mode is_blocking) {
623- return reinterpret_cast <ThreadSafeFunction*>(func)->Call (data, is_blocking);
624- }
625-
626- napi_status napi_delete_threadsafe_function (napi_threadsafe_function func) {
627- ThreadSafeFunction::Delete (reinterpret_cast <ThreadSafeFunction*>(func));
628- return napi_ok;
629- }
630-
631615class ErrorScope {
632616 public:
633617 explicit ErrorScope (napi_env env) : env_(env) {}
@@ -646,12 +630,14 @@ class ErrorScope {
646630 napi_env env_;
647631};
648632
649- napi_status napi_open_error_scope (napi_env env, napi_error_scope* result) {
633+ napi_status napi_open_error_scope_internal (napi_env env,
634+ napi_error_scope* result) {
650635 *result = reinterpret_cast <napi_error_scope>(new ErrorScope (env));
651636 return napi_ok;
652637}
653638
654- napi_status napi_close_error_scope (napi_env env, napi_error_scope scope) {
639+ napi_status napi_close_error_scope_internal (napi_env env,
640+ napi_error_scope scope) {
655641 delete reinterpret_cast <ErrorScope*>(scope);
656642 return napi_ok;
657643}
@@ -714,6 +700,24 @@ napi_status napi_dump_code_cache_status(napi_env env, void* dump_vec) {
714700
715701} // namespace
716702
703+ napi_status napi_get_threadsafe_function_context_internal (
704+ napi_threadsafe_function func, void ** result) {
705+ *result = reinterpret_cast <ThreadSafeFunction*>(func)->Context ();
706+ return napi_ok;
707+ }
708+
709+ napi_status napi_call_threadsafe_function_internal (
710+ napi_threadsafe_function func, void * data,
711+ napi_threadsafe_function_call_mode is_blocking) {
712+ return reinterpret_cast <ThreadSafeFunction*>(func)->Call (data, is_blocking);
713+ }
714+
715+ napi_status napi_delete_threadsafe_function_internal (
716+ napi_threadsafe_function func) {
717+ ThreadSafeFunction::Delete (reinterpret_cast <ThreadSafeFunction*>(func));
718+ return napi_ok;
719+ }
720+
717721napi_runtime_configuration napi_create_runtime_configuration () {
718722 return new napi_runtime_configuration__{};
719723}
@@ -756,9 +760,15 @@ void napi_attach_runtime_with_configuration(
756760 napi_env env, napi_runtime_configuration configuration) {
757761 env->rt = new napi_runtime__ (env, configuration);
758762
763+ #define SET_INTERNAL_METHOD (API ) env->napi_##API = napi_##API##_internal;
764+
765+ FOR_EACH_NAPI_RUNTIME_CALL (SET_INTERNAL_METHOD)
766+
767+ #undef SET_INTERNAL_METHOD
768+
759769#define SET_METHOD (API ) env->napi_##API = napi_##API;
760770
761- FOR_EACH_NAPI_RUNTIME_CALL (SET_METHOD)
771+ NAPI_RUNTIME_CODECACHE_CALL (SET_METHOD)
762772
763773#undef SET_METHOD
764774}
0 commit comments