react-native-windows 0.80.5 → 0.80.6

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,211 @@
1
+ #ifndef SRC_JS_NATIVE_API_TYPES_H_
2
+ #define SRC_JS_NATIVE_API_TYPES_H_
3
+
4
+ // This file needs to be compatible with C compilers.
5
+ // This is a public include file, and these includes have essentially
6
+ // became part of it's API.
7
+ #include <stddef.h> // NOLINT(modernize-deprecated-headers)
8
+ #include <stdint.h> // NOLINT(modernize-deprecated-headers)
9
+
10
+ #if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900)
11
+ typedef uint16_t char16_t;
12
+ #endif
13
+
14
+ #ifndef NAPI_CDECL
15
+ #ifdef _WIN32
16
+ #define NAPI_CDECL __cdecl
17
+ #else
18
+ #define NAPI_CDECL
19
+ #endif
20
+ #endif
21
+
22
+ // JSVM API types are all opaque pointers for ABI stability
23
+ // typedef undefined structs instead of void* for compile time type safety
24
+ typedef struct napi_env__* napi_env;
25
+
26
+ // We need to mark APIs which can be called during garbage collection (GC),
27
+ // meaning that they do not affect the state of the JS engine, and can
28
+ // therefore be called synchronously from a finalizer that itself runs
29
+ // synchronously during GC. Such APIs can receive either a `napi_env` or a
30
+ // `node_api_basic_env` as their first parameter, because we should be able to
31
+ // also call them during normal, non-garbage-collecting operations, whereas
32
+ // APIs that affect the state of the JS engine can only receive a `napi_env` as
33
+ // their first parameter, because we must not call them during GC. In lieu of
34
+ // inheritance, we use the properties of the const qualifier to accomplish
35
+ // this, because both a const and a non-const value can be passed to an API
36
+ // expecting a const value, but only a non-const value can be passed to an API
37
+ // expecting a non-const value.
38
+ //
39
+ // In conjunction with appropriate CFLAGS to warn us if we're passing a const
40
+ // (basic) environment into an API that expects a non-const environment, and
41
+ // the definition of basic finalizer function pointer types below, which
42
+ // receive a basic environment as their first parameter, and can thus only call
43
+ // basic APIs (unless the user explicitly casts the environment), we achieve
44
+ // the ability to ensure at compile time that we do not call APIs that affect
45
+ // the state of the JS engine from a synchronous (basic) finalizer.
46
+ #if !defined(NAPI_EXPERIMENTAL) || \
47
+ (defined(NAPI_EXPERIMENTAL) && \
48
+ (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \
49
+ defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
50
+ typedef struct napi_env__* node_api_nogc_env;
51
+ #else
52
+ typedef const struct napi_env__* node_api_nogc_env;
53
+ #endif
54
+ typedef node_api_nogc_env node_api_basic_env;
55
+
56
+ typedef struct napi_value__* napi_value;
57
+ typedef struct napi_ref__* napi_ref;
58
+ typedef struct napi_handle_scope__* napi_handle_scope;
59
+ typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
60
+ typedef struct napi_callback_info__* napi_callback_info;
61
+ typedef struct napi_deferred__* napi_deferred;
62
+
63
+ typedef enum {
64
+ napi_default = 0,
65
+ napi_writable = 1 << 0,
66
+ napi_enumerable = 1 << 1,
67
+ napi_configurable = 1 << 2,
68
+
69
+ // Used with napi_define_class to distinguish static properties
70
+ // from instance properties. Ignored by napi_define_properties.
71
+ napi_static = 1 << 10,
72
+
73
+ #if NAPI_VERSION >= 8
74
+ // Default for class methods.
75
+ napi_default_method = napi_writable | napi_configurable,
76
+
77
+ // Default for object properties, like in JS obj[prop].
78
+ napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable,
79
+ #endif // NAPI_VERSION >= 8
80
+ } napi_property_attributes;
81
+
82
+ typedef enum {
83
+ // ES6 types (corresponds to typeof)
84
+ napi_undefined,
85
+ napi_null,
86
+ napi_boolean,
87
+ napi_number,
88
+ napi_string,
89
+ napi_symbol,
90
+ napi_object,
91
+ napi_function,
92
+ napi_external,
93
+ napi_bigint,
94
+ } napi_valuetype;
95
+
96
+ typedef enum {
97
+ napi_int8_array,
98
+ napi_uint8_array,
99
+ napi_uint8_clamped_array,
100
+ napi_int16_array,
101
+ napi_uint16_array,
102
+ napi_int32_array,
103
+ napi_uint32_array,
104
+ napi_float32_array,
105
+ napi_float64_array,
106
+ napi_bigint64_array,
107
+ napi_biguint64_array,
108
+ } napi_typedarray_type;
109
+
110
+ typedef enum {
111
+ napi_ok,
112
+ napi_invalid_arg,
113
+ napi_object_expected,
114
+ napi_string_expected,
115
+ napi_name_expected,
116
+ napi_function_expected,
117
+ napi_number_expected,
118
+ napi_boolean_expected,
119
+ napi_array_expected,
120
+ napi_generic_failure,
121
+ napi_pending_exception,
122
+ napi_cancelled,
123
+ napi_escape_called_twice,
124
+ napi_handle_scope_mismatch,
125
+ napi_callback_scope_mismatch,
126
+ napi_queue_full,
127
+ napi_closing,
128
+ napi_bigint_expected,
129
+ napi_date_expected,
130
+ napi_arraybuffer_expected,
131
+ napi_detachable_arraybuffer_expected,
132
+ napi_would_deadlock, // unused
133
+ napi_no_external_buffers_allowed,
134
+ napi_cannot_run_js,
135
+ } napi_status;
136
+ // Note: when adding a new enum value to `napi_status`, please also update
137
+ // * `const int last_status` in the definition of `napi_get_last_error_info()'
138
+ // in file js_native_api_v8.cc.
139
+ // * `const char* error_messages[]` in file js_native_api_v8.cc with a brief
140
+ // message explaining the error.
141
+ // * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
142
+ // added value(s).
143
+
144
+ typedef napi_value(NAPI_CDECL* napi_callback)(napi_env env,
145
+ napi_callback_info info);
146
+ typedef void(NAPI_CDECL* napi_finalize)(napi_env env,
147
+ void* finalize_data,
148
+ void* finalize_hint);
149
+
150
+ #if !defined(NAPI_EXPERIMENTAL) || \
151
+ (defined(NAPI_EXPERIMENTAL) && \
152
+ (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \
153
+ defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
154
+ typedef napi_finalize node_api_nogc_finalize;
155
+ #else
156
+ typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env,
157
+ void* finalize_data,
158
+ void* finalize_hint);
159
+ #endif
160
+ typedef node_api_nogc_finalize node_api_basic_finalize;
161
+
162
+ typedef struct {
163
+ // One of utf8name or name should be NULL.
164
+ const char* utf8name;
165
+ napi_value name;
166
+
167
+ napi_callback method;
168
+ napi_callback getter;
169
+ napi_callback setter;
170
+ napi_value value;
171
+
172
+ napi_property_attributes attributes;
173
+ void* data;
174
+ } napi_property_descriptor;
175
+
176
+ typedef struct {
177
+ const char* error_message;
178
+ void* engine_reserved;
179
+ uint32_t engine_error_code;
180
+ napi_status error_code;
181
+ } napi_extended_error_info;
182
+
183
+ #if NAPI_VERSION >= 6
184
+ typedef enum {
185
+ napi_key_include_prototypes,
186
+ napi_key_own_only
187
+ } napi_key_collection_mode;
188
+
189
+ typedef enum {
190
+ napi_key_all_properties = 0,
191
+ napi_key_writable = 1,
192
+ napi_key_enumerable = 1 << 1,
193
+ napi_key_configurable = 1 << 2,
194
+ napi_key_skip_strings = 1 << 3,
195
+ napi_key_skip_symbols = 1 << 4
196
+ } napi_key_filter;
197
+
198
+ typedef enum {
199
+ napi_key_keep_numbers,
200
+ napi_key_numbers_to_strings
201
+ } napi_key_conversion;
202
+ #endif // NAPI_VERSION >= 6
203
+
204
+ #if NAPI_VERSION >= 8
205
+ typedef struct {
206
+ uint64_t lower;
207
+ uint64_t upper;
208
+ } napi_type_tag;
209
+ #endif // NAPI_VERSION >= 8
210
+
211
+ #endif // SRC_JS_NATIVE_API_TYPES_H_
@@ -0,0 +1,214 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #ifndef SRC_JS_RUNTIME_API_H_
5
+ #define SRC_JS_RUNTIME_API_H_
6
+
7
+ #include "node_api.h"
8
+
9
+ //
10
+ // Node-API extensions required for JavaScript engine hosting.
11
+ //
12
+ // It is a very early version of the APIs which we consider to be experimental.
13
+ // These APIs are not stable yet and are subject to change while we continue
14
+ // their development. After some time we will stabilize the APIs and make them
15
+ // "officially stable".
16
+ //
17
+
18
+ #define JSR_API NAPI_EXTERN napi_status NAPI_CDECL
19
+
20
+ EXTERN_C_START
21
+
22
+ typedef struct jsr_runtime_s* jsr_runtime;
23
+ typedef struct jsr_config_s* jsr_config;
24
+ typedef struct jsr_prepared_script_s* jsr_prepared_script;
25
+ typedef struct jsr_napi_env_scope_s* jsr_napi_env_scope;
26
+
27
+ typedef void(NAPI_CDECL* jsr_data_delete_cb)(void* data, void* deleter_data);
28
+
29
+ //=============================================================================
30
+ // jsr_runtime
31
+ //=============================================================================
32
+
33
+ JSR_API jsr_create_runtime(jsr_config config, jsr_runtime* runtime);
34
+ JSR_API jsr_delete_runtime(jsr_runtime runtime);
35
+ JSR_API jsr_runtime_get_node_api_env(jsr_runtime runtime, napi_env* env);
36
+
37
+ //=============================================================================
38
+ // jsr_config
39
+ //=============================================================================
40
+
41
+ JSR_API jsr_create_config(jsr_config* config);
42
+ JSR_API jsr_delete_config(jsr_config config);
43
+
44
+ JSR_API jsr_config_enable_inspector(jsr_config config, bool value);
45
+ JSR_API jsr_config_set_inspector_runtime_name(jsr_config config,
46
+ const char* name);
47
+ JSR_API jsr_config_set_inspector_port(jsr_config config, uint16_t port);
48
+ JSR_API jsr_config_set_inspector_break_on_start(jsr_config config, bool value);
49
+
50
+ JSR_API jsr_config_enable_gc_api(jsr_config config, bool value);
51
+
52
+ JSR_API jsr_config_set_explicit_microtasks(jsr_config config, bool value);
53
+
54
+ // A callback to process unhandled JS error
55
+ typedef void(NAPI_CDECL* jsr_unhandled_error_cb)(void* cb_data,
56
+ napi_env env,
57
+ napi_value error);
58
+
59
+ JSR_API jsr_config_on_unhandled_error(
60
+ jsr_config config,
61
+ void* cb_data,
62
+ jsr_unhandled_error_cb unhandled_error_cb);
63
+
64
+ //=============================================================================
65
+ // jsr_config task runner
66
+ //=============================================================================
67
+
68
+ // A callback to run task
69
+ typedef void(NAPI_CDECL* jsr_task_run_cb)(void* task_data);
70
+
71
+ // A callback to post task to the task runner
72
+ typedef void(NAPI_CDECL* jsr_task_runner_post_task_cb)(
73
+ void* task_runner_data,
74
+ void* task_data,
75
+ jsr_task_run_cb task_run_cb,
76
+ jsr_data_delete_cb task_data_delete_cb,
77
+ void* deleter_data);
78
+
79
+ JSR_API jsr_config_set_task_runner(
80
+ jsr_config config,
81
+ void* task_runner_data,
82
+ jsr_task_runner_post_task_cb task_runner_post_task_cb,
83
+ jsr_data_delete_cb task_runner_data_delete_cb,
84
+ void* deleter_data);
85
+
86
+ //=============================================================================
87
+ // jsr_config script cache
88
+ //=============================================================================
89
+
90
+ typedef void(NAPI_CDECL* jsr_script_cache_load_cb)(
91
+ void* script_cache_data,
92
+ const char* source_url,
93
+ uint64_t source_hash,
94
+ const char* runtime_name,
95
+ uint64_t runtime_version,
96
+ const char* cache_tag,
97
+ const uint8_t** buffer,
98
+ size_t* buffer_size,
99
+ jsr_data_delete_cb* buffer_delete_cb,
100
+ void** deleter_data);
101
+
102
+ typedef void(NAPI_CDECL* jsr_script_cache_store_cb)(
103
+ void* script_cache_data,
104
+ const char* source_url,
105
+ uint64_t source_hash,
106
+ const char* runtime_name,
107
+ uint64_t runtime_version,
108
+ const char* cache_tag,
109
+ const uint8_t* buffer,
110
+ size_t buffer_size,
111
+ jsr_data_delete_cb buffer_delete_cb,
112
+ void* deleter_data);
113
+
114
+ JSR_API jsr_config_set_script_cache(
115
+ jsr_config config,
116
+ void* script_cache_data,
117
+ jsr_script_cache_load_cb script_cache_load_cb,
118
+ jsr_script_cache_store_cb script_cache_store_cb,
119
+ jsr_data_delete_cb script_cache_data_delete_cb,
120
+ void* deleter_data);
121
+
122
+ //=============================================================================
123
+ // napi_env scope
124
+ //=============================================================================
125
+
126
+ // Opens the napi_env scope in the current thread.
127
+ // Calling Node-API functions without the opened scope may cause a failure.
128
+ // The scope must be closed by the jsr_close_napi_env_scope call.
129
+ JSR_API jsr_open_napi_env_scope(napi_env env, jsr_napi_env_scope* scope);
130
+
131
+ // Closes the napi_env scope in the current thread. It must match to the
132
+ // jsr_open_napi_env_scope call.
133
+ JSR_API jsr_close_napi_env_scope(napi_env env, jsr_napi_env_scope scope);
134
+
135
+ //=============================================================================
136
+ // Additional functions to implement JSI
137
+ //=============================================================================
138
+
139
+ // To implement JSI description()
140
+ JSR_API jsr_get_description(napi_env env, const char** result);
141
+
142
+ // To implement JSI queueMicrotask()
143
+ JSR_API jsr_queue_microtask(napi_env env, napi_value callback);
144
+
145
+ // To implement JSI drainMicrotasks()
146
+ JSR_API
147
+ jsr_drain_microtasks(napi_env env, int32_t max_count_hint, bool* result);
148
+
149
+ // To implement JSI isInspectable()
150
+ JSR_API jsr_is_inspectable(napi_env env, bool* result);
151
+
152
+ //=============================================================================
153
+ // Script preparing and running.
154
+ //
155
+ // Script is usually converted to byte code, or in other words - prepared - for
156
+ // execution. Then, we can run the prepared script.
157
+ //=============================================================================
158
+
159
+ // Run script with source URL.
160
+ JSR_API jsr_run_script(napi_env env,
161
+ napi_value source,
162
+ const char* source_url,
163
+ napi_value* result);
164
+
165
+ // Prepare the script for running.
166
+ JSR_API jsr_create_prepared_script(napi_env env,
167
+ const uint8_t* script_data,
168
+ size_t script_length,
169
+ jsr_data_delete_cb script_delete_cb,
170
+ void* deleter_data,
171
+ const char* source_url,
172
+ jsr_prepared_script* result);
173
+
174
+ // Delete the prepared script.
175
+ JSR_API jsr_delete_prepared_script(napi_env env,
176
+ jsr_prepared_script prepared_script);
177
+
178
+ // Run the prepared script.
179
+ JSR_API jsr_prepared_script_run(napi_env env,
180
+ jsr_prepared_script prepared_script,
181
+ napi_value* result);
182
+
183
+ //=============================================================================
184
+ // Functions to support unit tests.
185
+ //=============================================================================
186
+
187
+ // Provides a hint to run garbage collection.
188
+ // It is typically used for unit tests.
189
+ // It requires enabling GC by calling jsr_config_enable_gc_api.
190
+ JSR_API jsr_collect_garbage(napi_env env);
191
+
192
+ // Checks if the environment has an unhandled promise rejection.
193
+ JSR_API jsr_has_unhandled_promise_rejection(napi_env env, bool* result);
194
+
195
+ // Gets and clears the last unhandled promise rejection.
196
+ JSR_API jsr_get_and_clear_last_unhandled_promise_rejection(napi_env env,
197
+ napi_value* result);
198
+
199
+ // Create new napi_env for the runtime.
200
+ JSR_API
201
+ jsr_create_node_api_env(napi_env root_env, int32_t api_version, napi_env* env);
202
+
203
+ // Run task in the environment context.
204
+ JSR_API jsr_run_task(napi_env env, jsr_task_run_cb task_cb, void* data);
205
+
206
+ // Initializes native module.
207
+ JSR_API jsr_initialize_native_module(napi_env env,
208
+ napi_addon_register_func register_module,
209
+ int32_t api_version,
210
+ napi_value* exports);
211
+
212
+ EXTERN_C_END
213
+
214
+ #endif // !SRC_JS_RUNTIME_API_H_
@@ -0,0 +1,270 @@
1
+ #ifndef SRC_NODE_API_H_
2
+ #define SRC_NODE_API_H_
3
+
4
+ #if defined(BUILDING_NODE_EXTENSION) && !defined(NAPI_EXTERN)
5
+ #ifdef _WIN32
6
+ // Building native addon against node
7
+ #define NAPI_EXTERN __declspec(dllimport)
8
+ #elif defined(__wasm__)
9
+ #define NAPI_EXTERN __attribute__((__import_module__("napi")))
10
+ #endif
11
+ #endif
12
+ #include "js_native_api.h"
13
+ #include "node_api_types.h"
14
+
15
+ struct uv_loop_s; // Forward declaration.
16
+
17
+ #ifdef _WIN32
18
+ #define NAPI_MODULE_EXPORT __declspec(dllexport)
19
+ #else
20
+ #ifdef __EMSCRIPTEN__
21
+ #define NAPI_MODULE_EXPORT \
22
+ __attribute__((visibility("default"))) __attribute__((used))
23
+ #else
24
+ #define NAPI_MODULE_EXPORT __attribute__((visibility("default")))
25
+ #endif
26
+ #endif
27
+
28
+ #if defined(__GNUC__)
29
+ #define NAPI_NO_RETURN __attribute__((noreturn))
30
+ #elif defined(_WIN32)
31
+ #define NAPI_NO_RETURN __declspec(noreturn)
32
+ #else
33
+ #define NAPI_NO_RETURN
34
+ #endif
35
+
36
+ typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
37
+ napi_value exports);
38
+ typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
39
+
40
+ // Used by deprecated registration method napi_module_register.
41
+ typedef struct napi_module {
42
+ int nm_version;
43
+ unsigned int nm_flags;
44
+ const char* nm_filename;
45
+ napi_addon_register_func nm_register_func;
46
+ const char* nm_modname;
47
+ void* nm_priv;
48
+ void* reserved[4];
49
+ } napi_module;
50
+
51
+ #define NAPI_MODULE_VERSION 1
52
+
53
+ #define NAPI_MODULE_INITIALIZER_X(base, version) \
54
+ NAPI_MODULE_INITIALIZER_X_HELPER(base, version)
55
+ #define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version
56
+
57
+ #ifdef __wasm__
58
+ #define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
59
+ #else
60
+ #define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
61
+ #endif
62
+
63
+ #define NODE_API_MODULE_GET_API_VERSION_BASE node_api_module_get_api_version_v
64
+
65
+ #define NAPI_MODULE_INITIALIZER \
66
+ NAPI_MODULE_INITIALIZER_X(NAPI_MODULE_INITIALIZER_BASE, NAPI_MODULE_VERSION)
67
+
68
+ #define NODE_API_MODULE_GET_API_VERSION \
69
+ NAPI_MODULE_INITIALIZER_X(NODE_API_MODULE_GET_API_VERSION_BASE, \
70
+ NAPI_MODULE_VERSION)
71
+
72
+ #define NAPI_MODULE_INIT() \
73
+ EXTERN_C_START \
74
+ NAPI_MODULE_EXPORT int32_t NODE_API_MODULE_GET_API_VERSION(void) { \
75
+ return NAPI_VERSION; \
76
+ } \
77
+ NAPI_MODULE_EXPORT napi_value NAPI_MODULE_INITIALIZER(napi_env env, \
78
+ napi_value exports); \
79
+ EXTERN_C_END \
80
+ napi_value NAPI_MODULE_INITIALIZER(napi_env env, napi_value exports)
81
+
82
+ #define NAPI_MODULE(modname, regfunc) \
83
+ NAPI_MODULE_INIT() { \
84
+ return regfunc(env, exports); \
85
+ }
86
+
87
+ // Deprecated. Use NAPI_MODULE.
88
+ #define NAPI_MODULE_X(modname, regfunc, priv, flags) \
89
+ NAPI_MODULE(modname, regfunc)
90
+
91
+ EXTERN_C_START
92
+
93
+ // Deprecated. Replaced by symbol-based registration defined by NAPI_MODULE
94
+ // and NAPI_MODULE_INIT macros.
95
+ NAPI_EXTERN void NAPI_CDECL 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_