Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Aug 5, 2023
1 parent 8386786 commit b06f26c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
14 changes: 7 additions & 7 deletions packages/emnapi/include/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@

#include "js_native_api_types.h"

#ifdef EMNAPI_UNMODIFIED_UPSTREAM
// If you need __declspec(dllimport), either include <node_api.h> instead, or
// define NAPI_EXTERN as __declspec(dllimport) on the compiler's command line.
#ifndef NAPI_EXTERN
#ifdef _WIN32
#define NAPI_EXTERN __declspec(dllexport)
#elif defined(__wasm32__)
#elif defined(__wasm__)
#ifdef __EMSCRIPTEN__
#define NAPI_EXTERN \
__attribute__((visibility("default"))) \
__attribute__((__import_module__("env")))
#else
#define NAPI_EXTERN \
__attribute__((visibility("default"))) \
__attribute__((__import_module__("napi")))
#endif
#else
#define NAPI_EXTERN __attribute__((visibility("default")))
#endif
#endif
#else
#include "emnapi_common.h"
#endif

#define NAPI_AUTO_LENGTH SIZE_MAX

#ifdef EMNAPI_UNMODIFIED_UPSTREAM
#ifdef __cplusplus
#define EXTERN_C_START extern "C" {
#define EXTERN_C_END }
#else
#define EXTERN_C_START
#define EXTERN_C_END
#endif
#endif

EXTERN_C_START

Expand Down
37 changes: 19 additions & 18 deletions packages/emnapi/include/node_api.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
#ifndef SRC_NODE_API_H_
#define SRC_NODE_API_H_

#ifdef EMNAPI_UNMODIFIED_UPSTREAM
#ifdef BUILDING_NODE_EXTENSION
#ifdef _WIN32
// Building native addon against node
#define NAPI_EXTERN __declspec(dllimport)
#elif defined(__wasm32__)
#elif defined(__wasm__)
#ifdef __EMSCRIPTEN__
#define NAPI_EXTERN __attribute__((__import_module__("env")))
#else
#define NAPI_EXTERN __attribute__((__import_module__("napi")))
#endif
#endif
#endif
#include "js_native_api.h"
#include "node_api_types.h"

// See https://github.com/nodejs/node-addon-api/pull/1283
#ifndef NAPI_HAS_THREADS
#if !defined(__wasm__) || (defined(__EMSCRIPTEN_PTHREADS__) || \
(defined(__wasi__) && defined(_REENTRANT)))
#define NAPI_HAS_THREADS 1
#else
#define NAPI_HAS_THREADS 0
#endif
#endif

struct uv_loop_s; // Forward declaration.

#ifdef _WIN32
#define NAPI_MODULE_EXPORT __declspec(dllexport)
#else
#ifdef EMNAPI_UNMODIFIED_UPSTREAM
#define NAPI_MODULE_EXPORT __attribute__((visibility("default")))
#else
#ifdef __EMSCRIPTEN__
#define NAPI_MODULE_EXPORT __attribute__((visibility("default"))) __attribute__((used))
#else
#define NAPI_MODULE_EXPORT __attribute__((visibility("default")))
#endif
#endif
#endif

#if defined(__GNUC__)
#define NAPI_NO_RETURN __attribute__((noreturn))
Expand Down Expand Up @@ -59,19 +67,11 @@ typedef struct napi_module {
NAPI_MODULE_INITIALIZER_X_HELPER(base, version)
#define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version

#ifdef EMNAPI_UNMODIFIED_UPSTREAM
#ifdef __wasm32__
#define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
#else
#define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
#endif
#else
#ifdef __wasm__
#define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
#else
#define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
#endif
#endif

#define NODE_API_MODULE_GET_API_VERSION_BASE node_api_module_get_api_version_v

Expand Down Expand Up @@ -160,7 +160,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_buffer_info(napi_env env,
napi_value value,
void** data,
size_t* length);
#if !defined(EMNAPI_UNMODIFIED_UPSTREAM) || (defined(EMNAPI_UNMODIFIED_UPSTREAM) && !defined(__wasm32__))

#if NAPI_HAS_THREADS
// Methods to manage simple async operations
NAPI_EXTERN napi_status NAPI_CDECL
napi_create_async_work(napi_env env,
Expand All @@ -176,7 +177,7 @@ 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__
#endif // NAPI_HAS_THREADS

// version management
NAPI_EXTERN napi_status NAPI_CDECL
Expand Down Expand Up @@ -214,7 +215,7 @@ napi_close_callback_scope(napi_env env, napi_callback_scope scope);

#if NAPI_VERSION >= 4

#if !defined(EMNAPI_UNMODIFIED_UPSTREAM) || (defined(EMNAPI_UNMODIFIED_UPSTREAM) && !defined(__wasm32__))
#if NAPI_HAS_THREADS
// Calling into JS from other threads
NAPI_EXTERN napi_status NAPI_CDECL
napi_create_threadsafe_function(napi_env env,
Expand Down Expand Up @@ -248,7 +249,7 @@ 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_HAS_THREADS

#endif // NAPI_VERSION >= 4

Expand Down

0 comments on commit b06f26c

Please sign in to comment.