@gjsify/napi 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,249 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Vendored from refs/node/src/js_native_api_types.h (Node.js contributors, MIT).
3
+ // Copied unmodified (apart from this attribution header) so the @gjsify/napi
4
+ // shim compiles standalone against the exact Node-API ABI it implements.
5
+
6
+ #ifndef SRC_JS_NATIVE_API_TYPES_H_
7
+ #define SRC_JS_NATIVE_API_TYPES_H_
8
+
9
+ // Use INT_MAX, this should only be consumed by the pre-processor anyway.
10
+ #define NAPI_VERSION_EXPERIMENTAL 2147483647
11
+ #ifndef NAPI_VERSION
12
+ #ifdef NAPI_EXPERIMENTAL
13
+ #define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
14
+ #else
15
+ // The baseline version for Node-API.
16
+ // NAPI_VERSION controls which version is used by default when compiling
17
+ // a native addon. If the addon developer wants to use functions from a
18
+ // newer Node-API version not yet available in all LTS versions, they can
19
+ // set NAPI_VERSION to explicitly depend on that version.
20
+ #define NAPI_VERSION 8
21
+ #endif
22
+ #endif
23
+
24
+ #if defined(NAPI_EXPERIMENTAL) && \
25
+ !defined(NODE_API_EXPERIMENTAL_NO_WARNING) && \
26
+ !defined(NODE_WANT_INTERNALS)
27
+ #ifdef _MSC_VER
28
+ #pragma message("NAPI_EXPERIMENTAL is enabled. " \
29
+ "Experimental features may be unstable.")
30
+ #else
31
+ #warning "NAPI_EXPERIMENTAL is enabled. " \
32
+ "Experimental features may be unstable."
33
+ #endif
34
+ #endif
35
+
36
+ // This file needs to be compatible with C compilers.
37
+ // This is a public include file, and these includes have essentially
38
+ // become part of its API.
39
+ #include <stddef.h> // NOLINT(modernize-deprecated-headers)
40
+ #include <stdint.h> // NOLINT(modernize-deprecated-headers)
41
+
42
+ #if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900)
43
+ typedef uint16_t char16_t;
44
+ #endif
45
+
46
+ #ifndef NAPI_CDECL
47
+ #ifdef _WIN32
48
+ #define NAPI_CDECL __cdecl
49
+ #else
50
+ #define NAPI_CDECL
51
+ #endif
52
+ #endif
53
+
54
+ // JSVM API types are all opaque pointers for ABI stability
55
+ // typedef undefined structs instead of void* for compile time type safety
56
+ typedef struct napi_env__* napi_env;
57
+
58
+ // We need to mark APIs which can be called during garbage collection (GC),
59
+ // meaning that they do not affect the state of the JS engine, and can
60
+ // therefore be called synchronously from a finalizer that itself runs
61
+ // synchronously during GC. Such APIs can receive either a `napi_env` or a
62
+ // `node_api_basic_env` as their first parameter, because we should be able to
63
+ // also call them during normal, non-garbage-collecting operations, whereas
64
+ // APIs that affect the state of the JS engine can only receive a `napi_env` as
65
+ // their first parameter, because we must not call them during GC. In lieu of
66
+ // inheritance, we use the properties of the const qualifier to accomplish
67
+ // this, because both a const and a non-const value can be passed to an API
68
+ // expecting a const value, but only a non-const value can be passed to an API
69
+ // expecting a non-const value.
70
+ //
71
+ // In conjunction with appropriate CFLAGS to warn us if we're passing a const
72
+ // (basic) environment into an API that expects a non-const environment, and
73
+ // the definition of basic finalizer function pointer types below, which
74
+ // receive a basic environment as their first parameter, and can thus only call
75
+ // basic APIs (unless the user explicitly casts the environment), we achieve
76
+ // the ability to ensure at compile time that we do not call APIs that affect
77
+ // the state of the JS engine from a synchronous (basic) finalizer.
78
+ #if !defined(NAPI_EXPERIMENTAL) || \
79
+ (defined(NAPI_EXPERIMENTAL) && \
80
+ (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \
81
+ defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
82
+ typedef struct napi_env__* node_api_nogc_env;
83
+ #else
84
+ typedef const struct napi_env__* node_api_nogc_env;
85
+ #endif
86
+ typedef node_api_nogc_env node_api_basic_env;
87
+
88
+ typedef struct napi_value__* napi_value;
89
+ typedef struct napi_ref__* napi_ref;
90
+ typedef struct napi_handle_scope__* napi_handle_scope;
91
+ typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
92
+ typedef struct napi_callback_info__* napi_callback_info;
93
+ typedef struct napi_deferred__* napi_deferred;
94
+
95
+ typedef enum {
96
+ napi_default = 0,
97
+ napi_writable = 1 << 0,
98
+ napi_enumerable = 1 << 1,
99
+ napi_configurable = 1 << 2,
100
+
101
+ // Used with napi_define_class to distinguish static properties
102
+ // from instance properties. Ignored by napi_define_properties.
103
+ napi_static = 1 << 10,
104
+
105
+ #if NAPI_VERSION >= 8
106
+ // Default for class methods.
107
+ napi_default_method = napi_writable | napi_configurable,
108
+
109
+ // Default for object properties, like in JS obj[prop].
110
+ napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable,
111
+ #endif // NAPI_VERSION >= 8
112
+ } napi_property_attributes;
113
+
114
+ typedef enum {
115
+ // ES6 types (corresponds to typeof)
116
+ napi_undefined,
117
+ napi_null,
118
+ napi_boolean,
119
+ napi_number,
120
+ napi_string,
121
+ napi_symbol,
122
+ napi_object,
123
+ napi_function,
124
+ napi_external,
125
+ napi_bigint,
126
+ } napi_valuetype;
127
+
128
+ typedef enum {
129
+ napi_int8_array,
130
+ napi_uint8_array,
131
+ napi_uint8_clamped_array,
132
+ napi_int16_array,
133
+ napi_uint16_array,
134
+ napi_int32_array,
135
+ napi_uint32_array,
136
+ napi_float32_array,
137
+ napi_float64_array,
138
+ napi_bigint64_array,
139
+ napi_biguint64_array,
140
+ #define NODE_API_HAS_FLOAT16_ARRAY
141
+ napi_float16_array,
142
+ } napi_typedarray_type;
143
+
144
+ typedef enum {
145
+ napi_ok,
146
+ napi_invalid_arg,
147
+ napi_object_expected,
148
+ napi_string_expected,
149
+ napi_name_expected,
150
+ napi_function_expected,
151
+ napi_number_expected,
152
+ napi_boolean_expected,
153
+ napi_array_expected,
154
+ napi_generic_failure,
155
+ napi_pending_exception,
156
+ napi_cancelled,
157
+ napi_escape_called_twice,
158
+ napi_handle_scope_mismatch,
159
+ napi_callback_scope_mismatch,
160
+ napi_queue_full,
161
+ napi_closing,
162
+ napi_bigint_expected,
163
+ napi_date_expected,
164
+ napi_arraybuffer_expected,
165
+ napi_detachable_arraybuffer_expected,
166
+ napi_would_deadlock, // unused
167
+ napi_no_external_buffers_allowed,
168
+ napi_cannot_run_js,
169
+ } napi_status;
170
+ // Note: when adding a new enum value to `napi_status`, please also update
171
+ // * `const int last_status` in the definition of `napi_get_last_error_info()'
172
+ // in file js_native_api_v8.cc.
173
+ // * `const char* error_messages[]` in file js_native_api_v8.cc with a brief
174
+ // message explaining the error.
175
+ // * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
176
+ // added value(s).
177
+
178
+ typedef napi_value(NAPI_CDECL* napi_callback)(napi_env env,
179
+ napi_callback_info info);
180
+ typedef void(NAPI_CDECL* napi_finalize)(napi_env env,
181
+ void* finalize_data,
182
+ void* finalize_hint);
183
+
184
+ #if !defined(NAPI_EXPERIMENTAL) || \
185
+ (defined(NAPI_EXPERIMENTAL) && \
186
+ (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \
187
+ defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
188
+ typedef napi_finalize node_api_nogc_finalize;
189
+ #else
190
+ typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env,
191
+ void* finalize_data,
192
+ void* finalize_hint);
193
+ #endif
194
+ typedef node_api_nogc_finalize node_api_basic_finalize;
195
+
196
+ // A finalizer that can be called from any thread and at any time.
197
+ typedef void(NAPI_CDECL* node_api_noenv_finalize)(void* finalize_data,
198
+ void* finalize_hint);
199
+
200
+ typedef struct {
201
+ // One of utf8name or name should be NULL.
202
+ const char* utf8name;
203
+ napi_value name;
204
+
205
+ napi_callback method;
206
+ napi_callback getter;
207
+ napi_callback setter;
208
+ napi_value value;
209
+
210
+ napi_property_attributes attributes;
211
+ void* data;
212
+ } napi_property_descriptor;
213
+
214
+ typedef struct {
215
+ const char* error_message;
216
+ void* engine_reserved;
217
+ uint32_t engine_error_code;
218
+ napi_status error_code;
219
+ } napi_extended_error_info;
220
+
221
+ #if NAPI_VERSION >= 6
222
+ typedef enum {
223
+ napi_key_include_prototypes,
224
+ napi_key_own_only
225
+ } napi_key_collection_mode;
226
+
227
+ typedef enum {
228
+ napi_key_all_properties = 0,
229
+ napi_key_writable = 1,
230
+ napi_key_enumerable = 1 << 1,
231
+ napi_key_configurable = 1 << 2,
232
+ napi_key_skip_strings = 1 << 3,
233
+ napi_key_skip_symbols = 1 << 4
234
+ } napi_key_filter;
235
+
236
+ typedef enum {
237
+ napi_key_keep_numbers,
238
+ napi_key_numbers_to_strings
239
+ } napi_key_conversion;
240
+ #endif // NAPI_VERSION >= 6
241
+
242
+ #if NAPI_VERSION >= 8
243
+ typedef struct {
244
+ uint64_t lower;
245
+ uint64_t upper;
246
+ } napi_type_tag;
247
+ #endif // NAPI_VERSION >= 8
248
+
249
+ #endif // SRC_JS_NATIVE_API_TYPES_H_
@@ -0,0 +1,270 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Vendored from refs/node/src/node_api.h (Node.js contributors, MIT).
3
+ // Copied unmodified (apart from this attribution header) so the @gjsify/napi
4
+ // shim compiles standalone against the exact Node-API ABI it implements.
5
+
6
+ #ifndef SRC_NODE_API_H_
7
+ #define SRC_NODE_API_H_
8
+
9
+ #if defined(BUILDING_NODE_EXTENSION) && !defined(NAPI_EXTERN)
10
+ #ifdef _WIN32
11
+ // Building native addon against node
12
+ #define NAPI_EXTERN __declspec(dllimport)
13
+ #elif defined(__wasm__)
14
+ #define NAPI_EXTERN __attribute__((__import_module__("napi")))
15
+ #endif
16
+ #endif
17
+ #include "js_native_api.h"
18
+ #include "node_api_types.h"
19
+
20
+ struct uv_loop_s; // Forward declaration.
21
+
22
+ #ifdef _WIN32
23
+ #define NAPI_MODULE_EXPORT __declspec(dllexport)
24
+ #else
25
+ #ifdef __EMSCRIPTEN__
26
+ #define NAPI_MODULE_EXPORT \
27
+ __attribute__((visibility("default"))) __attribute__((used))
28
+ #else
29
+ #define NAPI_MODULE_EXPORT __attribute__((visibility("default")))
30
+ #endif
31
+ #endif
32
+
33
+ #if defined(__GNUC__)
34
+ #define NAPI_NO_RETURN __attribute__((noreturn))
35
+ #elif defined(_WIN32)
36
+ #define NAPI_NO_RETURN __declspec(noreturn)
37
+ #else
38
+ #define NAPI_NO_RETURN
39
+ #endif
40
+
41
+ // Used by deprecated registration method napi_module_register.
42
+ typedef struct napi_module {
43
+ int nm_version;
44
+ unsigned int nm_flags;
45
+ const char* nm_filename;
46
+ napi_addon_register_func nm_register_func;
47
+ const char* nm_modname;
48
+ void* nm_priv;
49
+ void* reserved[4];
50
+ } napi_module;
51
+
52
+ #define NAPI_MODULE_VERSION 1
53
+
54
+ #define NAPI_MODULE_INITIALIZER_X(base, version) \
55
+ NAPI_MODULE_INITIALIZER_X_HELPER(base, version)
56
+ #define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version
57
+
58
+ #ifdef __wasm__
59
+ #define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
60
+ #else
61
+ #define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
62
+ #endif
63
+
64
+ #define NODE_API_MODULE_GET_API_VERSION_BASE node_api_module_get_api_version_v
65
+
66
+ #define NAPI_MODULE_INITIALIZER \
67
+ NAPI_MODULE_INITIALIZER_X(NAPI_MODULE_INITIALIZER_BASE, NAPI_MODULE_VERSION)
68
+
69
+ #define NODE_API_MODULE_GET_API_VERSION \
70
+ NAPI_MODULE_INITIALIZER_X(NODE_API_MODULE_GET_API_VERSION_BASE, \
71
+ NAPI_MODULE_VERSION)
72
+
73
+ #define NAPI_MODULE_INIT() \
74
+ EXTERN_C_START \
75
+ NAPI_MODULE_EXPORT int32_t NODE_API_MODULE_GET_API_VERSION(void) { \
76
+ return NAPI_VERSION; \
77
+ } \
78
+ NAPI_MODULE_EXPORT napi_value NAPI_MODULE_INITIALIZER(napi_env env, \
79
+ napi_value exports); \
80
+ EXTERN_C_END \
81
+ napi_value NAPI_MODULE_INITIALIZER(napi_env env, napi_value exports)
82
+
83
+ #define NAPI_MODULE(modname, regfunc) \
84
+ NAPI_MODULE_INIT() { return regfunc(env, exports); }
85
+
86
+ // Deprecated. Use NAPI_MODULE.
87
+ #define NAPI_MODULE_X(modname, regfunc, priv, flags) \
88
+ NAPI_MODULE(modname, regfunc)
89
+
90
+ EXTERN_C_START
91
+
92
+ // Deprecated. Replaced by symbol-based registration defined by NAPI_MODULE
93
+ // and NAPI_MODULE_INIT macros.
94
+ NAPI_EXTERN void NAPI_CDECL
95
+ napi_module_register(napi_module* mod);
96
+
97
+ NAPI_EXTERN NAPI_NO_RETURN void NAPI_CDECL
98
+ napi_fatal_error(const char* location,
99
+ size_t location_len,
100
+ const char* message,
101
+ size_t message_len);
102
+
103
+ // Methods for custom handling of async operations
104
+ NAPI_EXTERN napi_status NAPI_CDECL
105
+ napi_async_init(napi_env env,
106
+ napi_value async_resource,
107
+ napi_value async_resource_name,
108
+ napi_async_context* result);
109
+
110
+ NAPI_EXTERN napi_status NAPI_CDECL
111
+ napi_async_destroy(napi_env env, napi_async_context async_context);
112
+
113
+ NAPI_EXTERN napi_status NAPI_CDECL
114
+ napi_make_callback(napi_env env,
115
+ napi_async_context async_context,
116
+ napi_value recv,
117
+ napi_value func,
118
+ size_t argc,
119
+ const napi_value* argv,
120
+ napi_value* result);
121
+
122
+ // Methods to provide node::Buffer functionality with napi types
123
+ NAPI_EXTERN napi_status NAPI_CDECL napi_create_buffer(napi_env env,
124
+ size_t length,
125
+ void** data,
126
+ napi_value* result);
127
+ #ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
128
+ NAPI_EXTERN napi_status NAPI_CDECL
129
+ napi_create_external_buffer(napi_env env,
130
+ size_t length,
131
+ void* data,
132
+ node_api_basic_finalize finalize_cb,
133
+ void* finalize_hint,
134
+ napi_value* result);
135
+ #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
136
+
137
+ #if NAPI_VERSION >= 10
138
+
139
+ NAPI_EXTERN napi_status NAPI_CDECL
140
+ node_api_create_buffer_from_arraybuffer(napi_env env,
141
+ napi_value arraybuffer,
142
+ size_t byte_offset,
143
+ size_t byte_length,
144
+ napi_value* result);
145
+ #endif // NAPI_VERSION >= 10
146
+
147
+ NAPI_EXTERN napi_status NAPI_CDECL napi_create_buffer_copy(napi_env env,
148
+ size_t length,
149
+ const void* data,
150
+ void** result_data,
151
+ napi_value* result);
152
+ NAPI_EXTERN napi_status NAPI_CDECL napi_is_buffer(napi_env env,
153
+ napi_value value,
154
+ bool* result);
155
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_buffer_info(napi_env env,
156
+ napi_value value,
157
+ void** data,
158
+ size_t* length);
159
+
160
+ // Methods to manage simple async operations
161
+ NAPI_EXTERN napi_status NAPI_CDECL
162
+ napi_create_async_work(napi_env env,
163
+ napi_value async_resource,
164
+ napi_value async_resource_name,
165
+ napi_async_execute_callback execute,
166
+ napi_async_complete_callback complete,
167
+ void* data,
168
+ napi_async_work* result);
169
+ NAPI_EXTERN napi_status NAPI_CDECL napi_delete_async_work(napi_env env,
170
+ napi_async_work work);
171
+ NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(node_api_basic_env env,
172
+ napi_async_work work);
173
+ NAPI_EXTERN napi_status NAPI_CDECL
174
+ napi_cancel_async_work(node_api_basic_env env, napi_async_work work);
175
+
176
+ // version management
177
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_node_version(
178
+ node_api_basic_env env, const napi_node_version** version);
179
+
180
+ #if NAPI_VERSION >= 2
181
+
182
+ // Return the current libuv event loop for a given environment
183
+ NAPI_EXTERN napi_status NAPI_CDECL
184
+ napi_get_uv_event_loop(node_api_basic_env env, struct uv_loop_s** loop);
185
+
186
+ #endif // NAPI_VERSION >= 2
187
+
188
+ #if NAPI_VERSION >= 3
189
+
190
+ NAPI_EXTERN napi_status NAPI_CDECL napi_fatal_exception(napi_env env,
191
+ napi_value err);
192
+
193
+ NAPI_EXTERN napi_status NAPI_CDECL napi_add_env_cleanup_hook(
194
+ node_api_basic_env env, napi_cleanup_hook fun, void* arg);
195
+
196
+ NAPI_EXTERN napi_status NAPI_CDECL napi_remove_env_cleanup_hook(
197
+ node_api_basic_env env, napi_cleanup_hook fun, void* arg);
198
+
199
+ NAPI_EXTERN napi_status NAPI_CDECL
200
+ napi_open_callback_scope(napi_env env,
201
+ napi_value resource_object,
202
+ napi_async_context context,
203
+ napi_callback_scope* result);
204
+
205
+ NAPI_EXTERN napi_status NAPI_CDECL
206
+ napi_close_callback_scope(napi_env env, napi_callback_scope scope);
207
+
208
+ #endif // NAPI_VERSION >= 3
209
+
210
+ #if NAPI_VERSION >= 4
211
+
212
+ // Calling into JS from other threads
213
+ NAPI_EXTERN napi_status NAPI_CDECL
214
+ napi_create_threadsafe_function(napi_env env,
215
+ napi_value func,
216
+ napi_value async_resource,
217
+ napi_value async_resource_name,
218
+ size_t max_queue_size,
219
+ size_t initial_thread_count,
220
+ void* thread_finalize_data,
221
+ napi_finalize thread_finalize_cb,
222
+ void* context,
223
+ napi_threadsafe_function_call_js call_js_cb,
224
+ napi_threadsafe_function* result);
225
+
226
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_threadsafe_function_context(
227
+ napi_threadsafe_function func, void** result);
228
+
229
+ NAPI_EXTERN napi_status NAPI_CDECL
230
+ napi_call_threadsafe_function(napi_threadsafe_function func,
231
+ void* data,
232
+ napi_threadsafe_function_call_mode is_blocking);
233
+
234
+ NAPI_EXTERN napi_status NAPI_CDECL
235
+ napi_acquire_threadsafe_function(napi_threadsafe_function func);
236
+
237
+ NAPI_EXTERN napi_status NAPI_CDECL napi_release_threadsafe_function(
238
+ napi_threadsafe_function func, napi_threadsafe_function_release_mode mode);
239
+
240
+ NAPI_EXTERN napi_status NAPI_CDECL napi_unref_threadsafe_function(
241
+ node_api_basic_env env, napi_threadsafe_function func);
242
+
243
+ NAPI_EXTERN napi_status NAPI_CDECL napi_ref_threadsafe_function(
244
+ node_api_basic_env env, napi_threadsafe_function func);
245
+
246
+ #endif // NAPI_VERSION >= 4
247
+
248
+ #if NAPI_VERSION >= 8
249
+
250
+ NAPI_EXTERN napi_status NAPI_CDECL
251
+ napi_add_async_cleanup_hook(node_api_basic_env env,
252
+ napi_async_cleanup_hook hook,
253
+ void* arg,
254
+ napi_async_cleanup_hook_handle* remove_handle);
255
+
256
+ NAPI_EXTERN napi_status NAPI_CDECL
257
+ napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle);
258
+
259
+ #endif // NAPI_VERSION >= 8
260
+
261
+ #if NAPI_VERSION >= 9
262
+
263
+ NAPI_EXTERN napi_status NAPI_CDECL
264
+ node_api_get_module_file_name(node_api_basic_env env, const char** result);
265
+
266
+ #endif // NAPI_VERSION >= 9
267
+
268
+ EXTERN_C_END
269
+
270
+ #endif // SRC_NODE_API_H_
@@ -0,0 +1,63 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Vendored from refs/node/src/node_api_types.h (Node.js contributors, MIT).
3
+ // Copied unmodified (apart from this attribution header) so the @gjsify/napi
4
+ // shim compiles standalone against the exact Node-API ABI it implements.
5
+
6
+ #ifndef SRC_NODE_API_TYPES_H_
7
+ #define SRC_NODE_API_TYPES_H_
8
+
9
+ #include "js_native_api_types.h"
10
+
11
+ typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
12
+ napi_value exports);
13
+ // False positive: https://github.com/cpplint/cpplint/issues/409
14
+ // NOLINTNEXTLINE (readability/casting)
15
+ typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
16
+
17
+ typedef struct napi_callback_scope__* napi_callback_scope;
18
+ typedef struct napi_async_context__* napi_async_context;
19
+ typedef struct napi_async_work__* napi_async_work;
20
+
21
+ #if NAPI_VERSION >= 3
22
+ typedef void(NAPI_CDECL* napi_cleanup_hook)(void* arg);
23
+ #endif // NAPI_VERSION >= 3
24
+
25
+ #if NAPI_VERSION >= 4
26
+ typedef struct napi_threadsafe_function__* napi_threadsafe_function;
27
+ #endif // NAPI_VERSION >= 4
28
+
29
+ #if NAPI_VERSION >= 4
30
+ typedef enum {
31
+ napi_tsfn_release,
32
+ napi_tsfn_abort
33
+ } napi_threadsafe_function_release_mode;
34
+
35
+ typedef enum {
36
+ napi_tsfn_nonblocking,
37
+ napi_tsfn_blocking
38
+ } napi_threadsafe_function_call_mode;
39
+ #endif // NAPI_VERSION >= 4
40
+
41
+ typedef void(NAPI_CDECL* napi_async_execute_callback)(napi_env env, void* data);
42
+ typedef void(NAPI_CDECL* napi_async_complete_callback)(napi_env env,
43
+ napi_status status,
44
+ void* data);
45
+ #if NAPI_VERSION >= 4
46
+ typedef void(NAPI_CDECL* napi_threadsafe_function_call_js)(
47
+ napi_env env, napi_value js_callback, void* context, void* data);
48
+ #endif // NAPI_VERSION >= 4
49
+
50
+ typedef struct {
51
+ uint32_t major;
52
+ uint32_t minor;
53
+ uint32_t patch;
54
+ const char* release;
55
+ } napi_node_version;
56
+
57
+ #if NAPI_VERSION >= 8
58
+ typedef struct napi_async_cleanup_hook_handle__* napi_async_cleanup_hook_handle;
59
+ typedef void(NAPI_CDECL* napi_async_cleanup_hook)(
60
+ napi_async_cleanup_hook_handle handle, void* data);
61
+ #endif // NAPI_VERSION >= 8
62
+
63
+ #endif // SRC_NODE_API_TYPES_H_
@@ -0,0 +1,6 @@
1
+ /* SPDX-License-Identifier: MIT
2
+ *
3
+ * Stub vapi: gjs-1.0 (the context accessors) is a C++-only dependency of the
4
+ * shim's .cc TUs. Meson forwards every dependency() to valac as --pkg; this
5
+ * empty vapi satisfies that lookup — Vala never touches the GJS C API.
6
+ */
@@ -0,0 +1,6 @@
1
+ /* SPDX-License-Identifier: MIT
2
+ *
3
+ * Stub vapi: mozjs-140 is a C++-only dependency of the shim's .cc TUs.
4
+ * Meson forwards every dependency() to valac as --pkg; this empty vapi
5
+ * satisfies that lookup — no JSAPI is (or must ever be) reachable from Vala.
6
+ */
@@ -0,0 +1,49 @@
1
+ /*
2
+ * SPDX-License-Identifier: MIT
3
+ *
4
+ * GjsifyNapi — bootstrap-only GI surface for the @gjsify/napi N-API host.
5
+ *
6
+ * The introspectable surface is deliberately ONE call: `init()` installs the
7
+ * `globalThis.__gjsifyNapiLoadAddon` JSNative via the C++ bridge compiled
8
+ * into this same shared library (src/cc/module.cc). Everything after that —
9
+ * loading addons, exports, errors — happens as plain JS→JSNative calls with
10
+ * no GI marshalling involved (ADR 0011 / plan §3a).
11
+ *
12
+ * Mirrors the `@gjsify/tls-native` packaging template: Vala class + C code in
13
+ * one `.so` + `.gir` + `.typelib`, loaded from GJS via `imports.gi`.
14
+ */
15
+
16
+ using GLib;
17
+
18
+ namespace GjsifyNapi {
19
+
20
+ /*
21
+ * The extern C++ bridge (extern "C" in src/cc/module.cc, same .so).
22
+ * Returns false when there is no current GjsContext/JSContext — i.e.
23
+ * when called outside a GJS runtime.
24
+ */
25
+ [CCode (cname = "gjsify_napi_install")]
26
+ private extern bool install_bridge ();
27
+
28
+ /**
29
+ * Install the N-API host into the running GJS context.
30
+ *
31
+ * Defines the non-enumerable `globalThis.__gjsifyNapiLoadAddon` native.
32
+ * Idempotent — a second call is a no-op returning true. The TS L1
33
+ * (`@gjsify/napi`) captures the native and deletes the global property.
34
+ *
35
+ * @return true when the loader native was (or already is) installed.
36
+ */
37
+ public bool init () {
38
+ return install_bridge ();
39
+ }
40
+
41
+ /**
42
+ * Whether the native shim is loaded. The interesting availability
43
+ * question ("did init() manage to reach a JSContext?") is answered by
44
+ * init()'s return value; this exists so the L1 can probe the typelib.
45
+ */
46
+ public bool is_available () {
47
+ return true;
48
+ }
49
+ }