Skip to content

Commit

Permalink
napi: add __wasm32__ guards
Browse files Browse the repository at this point in the history
PR-URL: #33597
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
devsnek authored and codebytere committed Jun 18, 2020
1 parent 2a29ced commit 022dceb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#ifndef NAPI_EXTERN
#ifdef _WIN32
#define NAPI_EXTERN __declspec(dllexport)
#elif defined(__wasm32__)
#define NAPI_EXTERN __attribute__((visibility("default"))) \
__attribute__((__import_module__("napi")))
#else
#define NAPI_EXTERN __attribute__((visibility("default")))
#endif
Expand Down
14 changes: 14 additions & 0 deletions src/node_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifdef _WIN32
// Building native module against node
#define NAPI_EXTERN __declspec(dllimport)
#elif defined(__wasm32__)
#define NAPI_EXTERN __attribute__((__import_module__("napi")))
#endif
#endif
#include "js_native_api.h"
Expand Down Expand Up @@ -71,8 +73,18 @@ typedef struct {
} \
EXTERN_C_END

#ifdef __wasm32__
#define NAPI_MODULE(modname, regfunc) \
EXTERN_C_START \
NAPI_MODULE_EXPORT napi_value _napi_register(napi_env env, \
napi_value exports) { \
return regfunc(env, exports); \
} \
EXTERN_C_END
#else
#define NAPI_MODULE(modname, regfunc) \
NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)
#endif

#define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v

Expand Down Expand Up @@ -196,6 +208,7 @@ NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env,

#if NAPI_VERSION >= 4

#ifndef __wasm32__
// Calling into JS from other threads
NAPI_EXTERN napi_status
napi_create_threadsafe_function(napi_env env,
Expand Down Expand Up @@ -231,6 +244,7 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);

NAPI_EXTERN napi_status
napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
#endif // __wasm32__

#endif // NAPI_VERSION >= 4

Expand Down

0 comments on commit 022dceb

Please sign in to comment.