diff --git a/src/js_native_api.h b/src/js_native_api.h index 3aa0ee5c1c5c5c..5e95452bd700bb 100644 --- a/src/js_native_api.h +++ b/src/js_native_api.h @@ -28,7 +28,7 @@ #ifndef NAPI_EXTERN #ifdef _WIN32 #define NAPI_EXTERN __declspec(dllexport) -#elif defined(__wasm32__) +#elif defined(__wasm__) #define NAPI_EXTERN \ __attribute__((visibility("default"))) \ __attribute__((__import_module__("napi"))) diff --git a/src/node_api.h b/src/node_api.h index 27acc6a0df43be..49a23aed9c6e90 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -1,11 +1,11 @@ #ifndef SRC_NODE_API_H_ #define SRC_NODE_API_H_ -#ifdef BUILDING_NODE_EXTENSION +#if defined(BUILDING_NODE_EXTENSION) && !defined(NAPI_EXTERN) #ifdef _WIN32 // Building native addon against node #define NAPI_EXTERN __declspec(dllimport) -#elif defined(__wasm32__) +#elif defined(__wasm__) #define NAPI_EXTERN __attribute__((__import_module__("napi"))) #endif #endif @@ -17,8 +17,13 @@ struct uv_loop_s; // Forward declaration. #ifdef _WIN32 #define NAPI_MODULE_EXPORT __declspec(dllexport) #else +#ifdef __EMSCRIPTEN__ +#define NAPI_MODULE_EXPORT \ + __attribute__((visibility("default"))) __attribute__((used)) +#else #define NAPI_MODULE_EXPORT __attribute__((visibility("default"))) #endif +#endif #if defined(__GNUC__) #define NAPI_NO_RETURN __attribute__((noreturn)) @@ -49,7 +54,7 @@ typedef struct napi_module { NAPI_MODULE_INITIALIZER_X_HELPER(base, version) #define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version -#ifdef __wasm32__ +#ifdef __wasm__ #define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v #else #define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v @@ -143,7 +148,6 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_buffer_info(napi_env env, void** data, size_t* length); -#ifndef __wasm32__ // Methods to manage simple async operations NAPI_EXTERN napi_status NAPI_CDECL napi_create_async_work(napi_env env, @@ -159,7 +163,6 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(napi_env env, napi_async_work work); NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(napi_env env, napi_async_work work); -#endif // __wasm32__ // version management NAPI_EXTERN napi_status NAPI_CDECL @@ -197,7 +200,6 @@ napi_close_callback_scope(napi_env env, napi_callback_scope scope); #if NAPI_VERSION >= 4 -#ifndef __wasm32__ // Calling into JS from other threads NAPI_EXTERN napi_status NAPI_CDECL napi_create_threadsafe_function(napi_env env, @@ -231,7 +233,6 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func); NAPI_EXTERN napi_status NAPI_CDECL napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func); -#endif // __wasm32__ #endif // NAPI_VERSION >= 4