emnapi 0.38.3 → 0.40.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.
- package/README.md +15 -4
- package/dist/library_napi.js +1931 -1839
- package/include/js_native_api.h +24 -6
- package/include/js_native_api_types.h +2 -1
- package/include/node_api.h +12 -2
- package/lib/wasm32/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32/libemnapi-basic.a +0 -0
- package/lib/wasm32/libemnapi.a +0 -0
- package/lib/wasm32-emscripten/libemnapi-basic.a +0 -0
- package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm32-emscripten/libemnapi.a +0 -0
- package/lib/wasm32-emscripten.txt +1 -1
- package/lib/wasm32-wasi/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi/libemnapi.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
- package/package.json +1 -4
- package/src/async_work.c +2 -2
- package/src/emnapi_internal.h +5 -4
- package/src/js_native_api.c +4 -10
- package/src/node_api.c +3 -3
- package/src/threadsafe_function.c +5 -5
package/include/js_native_api.h
CHANGED
|
@@ -98,16 +98,34 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env,
|
|
|
98
98
|
const char16_t* str,
|
|
99
99
|
size_t length,
|
|
100
100
|
napi_value* result);
|
|
101
|
+
#ifdef NAPI_EXPERIMENTAL
|
|
102
|
+
NAPI_EXTERN napi_status NAPI_CDECL
|
|
103
|
+
node_api_create_external_string_latin1(napi_env env,
|
|
104
|
+
char* str,
|
|
105
|
+
size_t length,
|
|
106
|
+
napi_finalize finalize_callback,
|
|
107
|
+
void* finalize_hint,
|
|
108
|
+
napi_value* result,
|
|
109
|
+
bool* copied);
|
|
110
|
+
NAPI_EXTERN napi_status NAPI_CDECL
|
|
111
|
+
node_api_create_external_string_utf16(napi_env env,
|
|
112
|
+
char16_t* str,
|
|
113
|
+
size_t length,
|
|
114
|
+
napi_finalize finalize_callback,
|
|
115
|
+
void* finalize_hint,
|
|
116
|
+
napi_value* result,
|
|
117
|
+
bool* copied);
|
|
118
|
+
#endif // NAPI_EXPERIMENTAL
|
|
101
119
|
NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol(napi_env env,
|
|
102
120
|
napi_value description,
|
|
103
121
|
napi_value* result);
|
|
104
|
-
#
|
|
122
|
+
#if NAPI_VERSION >= 9
|
|
105
123
|
NAPI_EXTERN napi_status NAPI_CDECL
|
|
106
124
|
node_api_symbol_for(napi_env env,
|
|
107
125
|
const char* utf8description,
|
|
108
126
|
size_t length,
|
|
109
127
|
napi_value* result);
|
|
110
|
-
#endif //
|
|
128
|
+
#endif // NAPI_VERSION >= 9
|
|
111
129
|
NAPI_EXTERN napi_status NAPI_CDECL napi_create_function(napi_env env,
|
|
112
130
|
const char* utf8name,
|
|
113
131
|
size_t length,
|
|
@@ -126,10 +144,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_range_error(napi_env env,
|
|
|
126
144
|
napi_value code,
|
|
127
145
|
napi_value msg,
|
|
128
146
|
napi_value* result);
|
|
129
|
-
#
|
|
147
|
+
#if NAPI_VERSION >= 9
|
|
130
148
|
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_syntax_error(
|
|
131
149
|
napi_env env, napi_value code, napi_value msg, napi_value* result);
|
|
132
|
-
#endif //
|
|
150
|
+
#endif // NAPI_VERSION >= 9
|
|
133
151
|
|
|
134
152
|
// Methods to get the native napi_value from Primitive type
|
|
135
153
|
NAPI_EXTERN napi_status NAPI_CDECL napi_typeof(napi_env env,
|
|
@@ -384,11 +402,11 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_throw_type_error(napi_env env,
|
|
|
384
402
|
NAPI_EXTERN napi_status NAPI_CDECL napi_throw_range_error(napi_env env,
|
|
385
403
|
const char* code,
|
|
386
404
|
const char* msg);
|
|
387
|
-
#
|
|
405
|
+
#if NAPI_VERSION >= 9
|
|
388
406
|
NAPI_EXTERN napi_status NAPI_CDECL node_api_throw_syntax_error(napi_env env,
|
|
389
407
|
const char* code,
|
|
390
408
|
const char* msg);
|
|
391
|
-
#endif //
|
|
409
|
+
#endif // NAPI_VERSION >= 9
|
|
392
410
|
NAPI_EXTERN napi_status NAPI_CDECL napi_is_error(napi_env env,
|
|
393
411
|
napi_value value,
|
|
394
412
|
bool* result);
|
|
@@ -99,7 +99,8 @@ typedef enum {
|
|
|
99
99
|
napi_arraybuffer_expected,
|
|
100
100
|
napi_detachable_arraybuffer_expected,
|
|
101
101
|
napi_would_deadlock, // unused
|
|
102
|
-
napi_no_external_buffers_allowed
|
|
102
|
+
napi_no_external_buffers_allowed,
|
|
103
|
+
napi_cannot_run_js,
|
|
103
104
|
} napi_status;
|
|
104
105
|
// Note: when adding a new enum value to `napi_status`, please also update
|
|
105
106
|
// * `const int last_status` in the definition of `napi_get_last_error_info()'
|
package/include/node_api.h
CHANGED
|
@@ -40,6 +40,7 @@ struct uv_loop_s; // Forward declaration.
|
|
|
40
40
|
|
|
41
41
|
typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
|
|
42
42
|
napi_value exports);
|
|
43
|
+
typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)();
|
|
43
44
|
|
|
44
45
|
// Used by deprecated registration method napi_module_register.
|
|
45
46
|
typedef struct napi_module {
|
|
@@ -72,11 +73,20 @@ typedef struct napi_module {
|
|
|
72
73
|
#endif
|
|
73
74
|
#endif
|
|
74
75
|
|
|
76
|
+
#define NODE_API_MODULE_GET_API_VERSION_BASE node_api_module_get_api_version_v
|
|
77
|
+
|
|
75
78
|
#define NAPI_MODULE_INITIALIZER \
|
|
76
79
|
NAPI_MODULE_INITIALIZER_X(NAPI_MODULE_INITIALIZER_BASE, NAPI_MODULE_VERSION)
|
|
77
80
|
|
|
81
|
+
#define NODE_API_MODULE_GET_API_VERSION \
|
|
82
|
+
NAPI_MODULE_INITIALIZER_X(NODE_API_MODULE_GET_API_VERSION_BASE, \
|
|
83
|
+
NAPI_MODULE_VERSION)
|
|
84
|
+
|
|
78
85
|
#define NAPI_MODULE_INIT() \
|
|
79
86
|
EXTERN_C_START \
|
|
87
|
+
NAPI_MODULE_EXPORT int32_t NODE_API_MODULE_GET_API_VERSION() { \
|
|
88
|
+
return NAPI_VERSION; \
|
|
89
|
+
} \
|
|
80
90
|
NAPI_MODULE_EXPORT napi_value NAPI_MODULE_INITIALIZER(napi_env env, \
|
|
81
91
|
napi_value exports); \
|
|
82
92
|
EXTERN_C_END \
|
|
@@ -255,12 +265,12 @@ napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle);
|
|
|
255
265
|
|
|
256
266
|
#endif // NAPI_VERSION >= 8
|
|
257
267
|
|
|
258
|
-
#
|
|
268
|
+
#if NAPI_VERSION >= 9
|
|
259
269
|
|
|
260
270
|
NAPI_EXTERN napi_status NAPI_CDECL
|
|
261
271
|
node_api_get_module_file_name(napi_env env, const char** result);
|
|
262
272
|
|
|
263
|
-
#endif //
|
|
273
|
+
#endif // NAPI_VERSION >= 9
|
|
264
274
|
|
|
265
275
|
EXTERN_C_END
|
|
266
276
|
|
|
Binary file
|
|
Binary file
|
package/lib/wasm32/libemnapi.a
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2,4 +2,4 @@ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.36 (5
|
|
|
2
2
|
clang version 17.0.0 (https://github.com/llvm/llvm-project 5084abbea933b1a510556726a9e226b5ae22f19f)
|
|
3
3
|
Target: wasm32-unknown-emscripten
|
|
4
4
|
Thread model: posix
|
|
5
|
-
InstalledDir: /home/runner/work/
|
|
5
|
+
InstalledDir: /home/runner/work/emnapi/emnapi/emsdk-cache/emsdk-main/upstream/bin
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emnapi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"description": "Node-API implementation for Emscripten",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"peerDependencies": {
|
|
@@ -11,9 +11,6 @@
|
|
|
11
11
|
"optional": true
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"ts-macros": "2.0.1"
|
|
16
|
-
},
|
|
17
14
|
"scripts": {
|
|
18
15
|
"build": "node ./script/build.js"
|
|
19
16
|
},
|
package/src/async_work.c
CHANGED
|
@@ -77,7 +77,7 @@ static napi_value async_work_after_cb(napi_env env, napi_callback_info info) {
|
|
|
77
77
|
void* data = NULL;
|
|
78
78
|
EMNAPI_ASSERT_CALL(napi_get_cb_info(env, info, NULL, NULL, NULL, &data));
|
|
79
79
|
complete_wrap_t* wrap = (complete_wrap_t*) data;
|
|
80
|
-
|
|
80
|
+
_emnapi_callback_into_module(1, env, async_work_on_complete, wrap, 1);
|
|
81
81
|
return NULL;
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -103,7 +103,7 @@ static void async_work_after_thread_pool_work(napi_async_work work, int status)
|
|
|
103
103
|
work->async_context_.trigger_async_id,
|
|
104
104
|
NULL);
|
|
105
105
|
} else {
|
|
106
|
-
|
|
106
|
+
_emnapi_callback_into_module(1, env, async_work_on_complete, wrap, 1);
|
|
107
107
|
}
|
|
108
108
|
EMNAPI_ASSERT_CALL(napi_close_handle_scope(env, scope));
|
|
109
109
|
}
|
package/src/emnapi_internal.h
CHANGED
|
@@ -110,10 +110,11 @@ EMNAPI_INTERNAL_EXTERN void _emnapi_ctx_decrease_waiting_request_counter();
|
|
|
110
110
|
|
|
111
111
|
typedef void (*_emnapi_call_into_module_callback)(napi_env env, void* args);
|
|
112
112
|
EMNAPI_INTERNAL_EXTERN
|
|
113
|
-
void
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
void _emnapi_callback_into_module(int force_uncaught,
|
|
114
|
+
napi_env env,
|
|
115
|
+
_emnapi_call_into_module_callback callback,
|
|
116
|
+
void* args,
|
|
117
|
+
int close_scope_if_throw);
|
|
117
118
|
|
|
118
119
|
#endif
|
|
119
120
|
|
package/src/js_native_api.c
CHANGED
|
@@ -29,7 +29,8 @@ static const char* emnapi_error_messages[] = {
|
|
|
29
29
|
"An arraybuffer was expected",
|
|
30
30
|
"A detachable arraybuffer was expected",
|
|
31
31
|
"Main thread would deadlock",
|
|
32
|
-
"External buffers are not allowed"
|
|
32
|
+
"External buffers are not allowed",
|
|
33
|
+
"Cannot run JavaScript",
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
EMNAPI_INTERNAL_EXTERN void _emnapi_get_last_error_info(napi_env env,
|
|
@@ -43,9 +44,9 @@ napi_status napi_get_last_error_info(
|
|
|
43
44
|
CHECK_ENV(env);
|
|
44
45
|
CHECK_ARG(env, result);
|
|
45
46
|
|
|
46
|
-
const int last_status =
|
|
47
|
+
const int last_status = napi_cannot_run_js;
|
|
47
48
|
|
|
48
|
-
static_assert((sizeof(emnapi_error_messages) / sizeof(const char*)) ==
|
|
49
|
+
static_assert((sizeof(emnapi_error_messages) / sizeof(const char*)) == napi_cannot_run_js + 1,
|
|
49
50
|
"Count of error messages must match count of error values");
|
|
50
51
|
|
|
51
52
|
_emnapi_get_last_error_info(env,
|
|
@@ -96,11 +97,4 @@ napi_status napi_adjust_external_memory(napi_env env,
|
|
|
96
97
|
return napi_clear_last_error(env);
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
napi_status napi_get_version(napi_env env, uint32_t* result) {
|
|
100
|
-
CHECK_ENV(env);
|
|
101
|
-
CHECK_ARG(env, result);
|
|
102
|
-
*result = NAPI_VERSION;
|
|
103
|
-
return napi_clear_last_error(env);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
100
|
EXTERN_C_END
|
package/src/node_api.c
CHANGED
|
@@ -42,7 +42,7 @@ napi_status napi_get_uv_event_loop(napi_env env,
|
|
|
42
42
|
#endif
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
EMNAPI_INTERNAL_EXTERN int _emnapi_get_filename(char* buf, int len);
|
|
45
|
+
EMNAPI_INTERNAL_EXTERN int _emnapi_get_filename(napi_env env, char* buf, int len);
|
|
46
46
|
|
|
47
47
|
napi_status node_api_get_module_file_name(napi_env env,
|
|
48
48
|
const char** result) {
|
|
@@ -57,12 +57,12 @@ napi_status node_api_get_module_file_name(napi_env env,
|
|
|
57
57
|
filename = NULL;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
int len = _emnapi_get_filename(NULL, 0);
|
|
60
|
+
int len = _emnapi_get_filename(env, NULL, 0);
|
|
61
61
|
if (len == 0) {
|
|
62
62
|
*result = empty_string;
|
|
63
63
|
} else {
|
|
64
64
|
filename = (char*) malloc(len + 1);
|
|
65
|
-
len = _emnapi_get_filename(filename, len + 1);
|
|
65
|
+
len = _emnapi_get_filename(env, filename, len + 1);
|
|
66
66
|
*(filename + len) = '\0';
|
|
67
67
|
*result = filename;
|
|
68
68
|
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
EXTERN_C_START
|
|
13
13
|
|
|
14
|
-
EMNAPI_INTERNAL_EXTERN void _emnapi_call_finalizer(napi_env env, napi_finalize cb, void* data, void* hint);
|
|
14
|
+
EMNAPI_INTERNAL_EXTERN void _emnapi_call_finalizer(int force_uncaught, napi_env env, napi_finalize cb, void* data, void* hint);
|
|
15
15
|
|
|
16
16
|
static const unsigned char kDispatchIdle = 0;
|
|
17
17
|
static const unsigned char kDispatchRunning = 1 << 0;
|
|
@@ -205,7 +205,7 @@ static napi_value _emnapi_tsfn_finalize_in_callback_scope(napi_env env, napi_cal
|
|
|
205
205
|
void* data = NULL;
|
|
206
206
|
EMNAPI_ASSERT_CALL(napi_get_cb_info(env, info, NULL, NULL, NULL, &data));
|
|
207
207
|
napi_threadsafe_function func = (napi_threadsafe_function) data;
|
|
208
|
-
_emnapi_call_finalizer(func->env, func->finalize_cb, func->finalize_data, func->context);
|
|
208
|
+
_emnapi_call_finalizer(0, func->env, func->finalize_cb, func->finalize_data, func->context);
|
|
209
209
|
return NULL;
|
|
210
210
|
}
|
|
211
211
|
|
|
@@ -226,7 +226,7 @@ static void _emnapi_tsfn_finalize(napi_threadsafe_function func) {
|
|
|
226
226
|
func->async_context_.trigger_async_id,
|
|
227
227
|
NULL);
|
|
228
228
|
} else {
|
|
229
|
-
_emnapi_call_finalizer(func->env, func->finalize_cb, func->finalize_data, func->context);
|
|
229
|
+
_emnapi_call_finalizer(0, func->env, func->finalize_cb, func->finalize_data, func->context);
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
_emnapi_tsfn_empty_queue_and_delete(func);
|
|
@@ -275,7 +275,7 @@ static void _emnapi_tsfn_call_js_cb(napi_env env, void* arg) {
|
|
|
275
275
|
static napi_value _emnapi_tsfn_call_js_cb_in_callback_scope(napi_env env, napi_callback_info info) {
|
|
276
276
|
void* data = NULL;
|
|
277
277
|
EMNAPI_ASSERT_CALL(napi_get_cb_info(env, info, NULL, NULL, NULL, &data));
|
|
278
|
-
|
|
278
|
+
_emnapi_callback_into_module(0, env, _emnapi_tsfn_call_js_cb, data, 1);
|
|
279
279
|
return NULL;
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -347,7 +347,7 @@ static bool _emnapi_tsfn_dispatch_one(napi_threadsafe_function func) {
|
|
|
347
347
|
func->async_context_.trigger_async_id,
|
|
348
348
|
NULL);
|
|
349
349
|
} else {
|
|
350
|
-
|
|
350
|
+
_emnapi_callback_into_module(0, func->env, _emnapi_tsfn_call_js_cb, jscb_data, 1);
|
|
351
351
|
}
|
|
352
352
|
EMNAPI_ASSERT_CALL(napi_close_handle_scope(func->env, scope));
|
|
353
353
|
}
|