Skip to content

Commit b55adfb

Browse files
authored
node-api: update headers for better wasm support
PR-URL: #49037 Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 0e507d3 commit b55adfb

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/js_native_api.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#ifndef NAPI_EXTERN
2929
#ifdef _WIN32
3030
#define NAPI_EXTERN __declspec(dllexport)
31-
#elif defined(__wasm32__)
31+
#elif defined(__wasm__)
3232
#define NAPI_EXTERN \
3333
__attribute__((visibility("default"))) \
3434
__attribute__((__import_module__("napi")))

src/node_api.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#ifndef SRC_NODE_API_H_
22
#define SRC_NODE_API_H_
33

4-
#ifdef BUILDING_NODE_EXTENSION
4+
#if defined(BUILDING_NODE_EXTENSION) && !defined(NAPI_EXTERN)
55
#ifdef _WIN32
66
// Building native addon against node
77
#define NAPI_EXTERN __declspec(dllimport)
8-
#elif defined(__wasm32__)
8+
#elif defined(__wasm__)
99
#define NAPI_EXTERN __attribute__((__import_module__("napi")))
1010
#endif
1111
#endif
@@ -17,8 +17,13 @@ struct uv_loop_s; // Forward declaration.
1717
#ifdef _WIN32
1818
#define NAPI_MODULE_EXPORT __declspec(dllexport)
1919
#else
20+
#ifdef __EMSCRIPTEN__
21+
#define NAPI_MODULE_EXPORT \
22+
__attribute__((visibility("default"))) __attribute__((used))
23+
#else
2024
#define NAPI_MODULE_EXPORT __attribute__((visibility("default")))
2125
#endif
26+
#endif
2227

2328
#if defined(__GNUC__)
2429
#define NAPI_NO_RETURN __attribute__((noreturn))
@@ -49,7 +54,7 @@ typedef struct napi_module {
4954
NAPI_MODULE_INITIALIZER_X_HELPER(base, version)
5055
#define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version
5156

52-
#ifdef __wasm32__
57+
#ifdef __wasm__
5358
#define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
5459
#else
5560
#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,
143148
void** data,
144149
size_t* length);
145150

146-
#ifndef __wasm32__
147151
// Methods to manage simple async operations
148152
NAPI_EXTERN napi_status NAPI_CDECL
149153
napi_create_async_work(napi_env env,
@@ -159,7 +163,6 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(napi_env env,
159163
napi_async_work work);
160164
NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(napi_env env,
161165
napi_async_work work);
162-
#endif // __wasm32__
163166

164167
// version management
165168
NAPI_EXTERN napi_status NAPI_CDECL
@@ -197,7 +200,6 @@ napi_close_callback_scope(napi_env env, napi_callback_scope scope);
197200

198201
#if NAPI_VERSION >= 4
199202

200-
#ifndef __wasm32__
201203
// Calling into JS from other threads
202204
NAPI_EXTERN napi_status NAPI_CDECL
203205
napi_create_threadsafe_function(napi_env env,
@@ -231,7 +233,6 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
231233

232234
NAPI_EXTERN napi_status NAPI_CDECL
233235
napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
234-
#endif // __wasm32__
235236

236237
#endif // NAPI_VERSION >= 4
237238

0 commit comments

Comments
 (0)