emnapi 1.8.0 → 1.9.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/CMakeLists.txt +12 -13
- package/dist/library_napi.js +252 -120
- package/emnapi.gyp +8 -1
- package/include/node/emnapi.h +2 -1
- package/include/node/js_native_api.h +6 -6
- package/include/node/js_native_api_types.h +8 -7
- package/index.d.ts +12 -0
- package/index.js +36 -0
- package/lib/wasm32/libdlmalloc-mt.a +0 -0
- package/lib/wasm32/libdlmalloc.a +0 -0
- package/lib/wasm32/libemmalloc-mt.a +0 -0
- package/lib/wasm32/libemmalloc.a +0 -0
- 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-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-napi-rs-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-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasip1/libemnapi.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-basic.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm64-emscripten/libemnapi.a +0 -0
- package/package.json +5 -2
- package/src/async_cleanup_hook.c +0 -2
- package/src/emnapi_internal.h +12 -0
- package/src/node_api.c +1 -7
- package/src/thread/async_worker_create.c +24 -1
- package/src/threadsafe_function.c +110 -94
- package/src/threadsafe_function.h +51 -0
- package/src/uv/uv-common.c +9 -1
- package/src/wasi_wait.c +3 -0
package/emnapi.gyp
CHANGED
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
'target_name': 'emnapi_basic',
|
|
49
49
|
'type': 'static_library',
|
|
50
50
|
'defines': [
|
|
51
|
-
'EMNAPI_DISABLE_UV'
|
|
52
51
|
],
|
|
53
52
|
'sources': [
|
|
54
53
|
'src/js_native_api.c',
|
|
@@ -56,6 +55,14 @@
|
|
|
56
55
|
'src/async_cleanup_hook.c',
|
|
57
56
|
'src/async_context.c',
|
|
58
57
|
'src/wasi_wait.c',
|
|
58
|
+
|
|
59
|
+
'src/uv/uv-common.c',
|
|
60
|
+
'src/uv/threadpool.c',
|
|
61
|
+
'src/uv/unix/loop.c',
|
|
62
|
+
'src/uv/unix/posix-hrtime.c',
|
|
63
|
+
'src/uv/unix/thread.c',
|
|
64
|
+
'src/uv/unix/async.c',
|
|
65
|
+
'src/uv/unix/core.c',
|
|
59
66
|
],
|
|
60
67
|
'link_settings': {
|
|
61
68
|
'target_conditions': [
|
package/include/node/emnapi.h
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#include "emnapi_common.h"
|
|
7
7
|
|
|
8
8
|
#define EMNAPI_MAJOR_VERSION 1
|
|
9
|
-
#define EMNAPI_MINOR_VERSION
|
|
9
|
+
#define EMNAPI_MINOR_VERSION 9
|
|
10
10
|
#define EMNAPI_PATCH_VERSION 0
|
|
11
11
|
|
|
12
12
|
typedef enum {
|
|
@@ -26,6 +26,7 @@ typedef enum {
|
|
|
26
26
|
emnapi_float64_array,
|
|
27
27
|
emnapi_bigint64_array,
|
|
28
28
|
emnapi_biguint64_array,
|
|
29
|
+
emnapi_float16_array,
|
|
29
30
|
emnapi_data_view = -1,
|
|
30
31
|
emnapi_buffer = -2,
|
|
31
32
|
} emnapi_memory_view_type;
|
|
@@ -59,12 +59,12 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_object(napi_env env,
|
|
|
59
59
|
#ifdef NAPI_EXPERIMENTAL
|
|
60
60
|
#define NODE_API_EXPERIMENTAL_HAS_CREATE_OBJECT_WITH_PROPERTIES
|
|
61
61
|
NAPI_EXTERN napi_status NAPI_CDECL
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
node_api_create_object_with_properties(napi_env env,
|
|
63
|
+
napi_value prototype_or_null,
|
|
64
|
+
napi_value* property_names,
|
|
65
|
+
napi_value* property_values,
|
|
66
|
+
size_t property_count,
|
|
67
|
+
napi_value* result);
|
|
68
68
|
#endif // NAPI_EXPERIMENTAL
|
|
69
69
|
|
|
70
70
|
NAPI_EXTERN napi_status NAPI_CDECL napi_create_array(napi_env env,
|
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
#ifdef NAPI_EXPERIMENTAL
|
|
8
8
|
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
|
|
9
9
|
#else
|
|
10
|
-
// The baseline version for
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
// depended on that version.
|
|
10
|
+
// The baseline version for Node-API.
|
|
11
|
+
// NAPI_VERSION controls which version is used by default when compiling
|
|
12
|
+
// a native addon. If the addon developer wants to use functions from a
|
|
13
|
+
// newer Node-API version not yet available in all LTS versions, they can
|
|
14
|
+
// set NAPI_VERSION to explicitly depend on that version.
|
|
16
15
|
#define NAPI_VERSION 8
|
|
17
16
|
#endif
|
|
18
17
|
#endif
|
|
@@ -31,7 +30,7 @@
|
|
|
31
30
|
|
|
32
31
|
// This file needs to be compatible with C compilers.
|
|
33
32
|
// This is a public include file, and these includes have essentially
|
|
34
|
-
//
|
|
33
|
+
// become part of its API.
|
|
35
34
|
#include <stddef.h> // NOLINT(modernize-deprecated-headers)
|
|
36
35
|
#include <stdint.h> // NOLINT(modernize-deprecated-headers)
|
|
37
36
|
|
|
@@ -133,6 +132,8 @@ typedef enum {
|
|
|
133
132
|
napi_float64_array,
|
|
134
133
|
napi_bigint64_array,
|
|
135
134
|
napi_biguint64_array,
|
|
135
|
+
#define NODE_API_HAS_FLOAT16_ARRAY
|
|
136
|
+
napi_float16_array,
|
|
136
137
|
} napi_typedarray_type;
|
|
137
138
|
|
|
138
139
|
typedef enum {
|
package/index.d.ts
CHANGED
|
@@ -2,3 +2,15 @@ export const include: string
|
|
|
2
2
|
export const include_dir: string
|
|
3
3
|
export const js_library: string
|
|
4
4
|
export const sources: string[]
|
|
5
|
+
export const targets: string
|
|
6
|
+
export const requiredConfig: {
|
|
7
|
+
emscripten: {
|
|
8
|
+
settings: Record<string, string | string[]>
|
|
9
|
+
}
|
|
10
|
+
clang: {
|
|
11
|
+
target: string
|
|
12
|
+
cflags: string[]
|
|
13
|
+
ldflags: string[]
|
|
14
|
+
wasmld: string[]
|
|
15
|
+
}
|
|
16
|
+
}
|
package/index.js
CHANGED
|
@@ -28,3 +28,39 @@ exports.include_dir = includeDir
|
|
|
28
28
|
exports.js_library = jsLibrary
|
|
29
29
|
exports.sources = sources
|
|
30
30
|
exports.targets = targets
|
|
31
|
+
|
|
32
|
+
exports.requiredConfig = {
|
|
33
|
+
emscripten: {
|
|
34
|
+
settings: {
|
|
35
|
+
WASM_BIGINT: '1',
|
|
36
|
+
ALLOW_MEMORY_GROWTH: '1',
|
|
37
|
+
MIN_CHROME_VERSION: '85',
|
|
38
|
+
EXPORTED_RUNTIME_METHODS: [
|
|
39
|
+
'emnapiInit'
|
|
40
|
+
],
|
|
41
|
+
EXPORTED_FUNCTIONS: [
|
|
42
|
+
'_malloc',
|
|
43
|
+
'_free',
|
|
44
|
+
'_napi_register_wasm_v1',
|
|
45
|
+
'_node_api_module_get_api_version_v1'
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
clang: {
|
|
50
|
+
target: 'wasm32-wasip1-threads',
|
|
51
|
+
cflags: ['-matomics', '-mbulk-memory'],
|
|
52
|
+
ldflags: ['-mexec-model=reactor'],
|
|
53
|
+
wasmld: [
|
|
54
|
+
'--import-memory',
|
|
55
|
+
'--shared-memory',
|
|
56
|
+
'--export-table',
|
|
57
|
+
'--export=malloc',
|
|
58
|
+
'--export=free',
|
|
59
|
+
'--export=napi_register_wasm_v1',
|
|
60
|
+
'--export-if-defined=node_api_module_get_api_version_v1',
|
|
61
|
+
'--export=emnapi_thread_crashed',
|
|
62
|
+
'--export-if-defined=emnapi_async_worker_create',
|
|
63
|
+
'--export-if-defined=emnapi_async_worker_init'
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
Binary file
|
package/lib/wasm32/libdlmalloc.a
CHANGED
|
Binary file
|
|
Binary file
|
package/lib/wasm32/libemmalloc.a
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/wasm32/libemnapi.a
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
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": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Node-API implementation for Emscripten",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"gypfile": false,
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "node ./script/build.js",
|
|
17
|
-
"version": "node ./script/version.js"
|
|
17
|
+
"version": "node ./script/version.js",
|
|
18
|
+
"generate-struct-info-wasm32": "node -e \"fs.mkdirSync('script/out',{recursive:true})\" && emcc -Iinclude/node -pthread script/generate_struct_info.c -sNODERAWFS -o script/out/generate_struct_info_wasm32.js && node ./script/out/generate_struct_info_wasm32.js",
|
|
19
|
+
"generate-struct-info-wasm64": "node -e \"fs.mkdirSync('script/out',{recursive:true})\" && emcc -Iinclude/node -pthread script/generate_struct_info.c -sNODERAWFS -sMEMORY64 -o script/out/generate_struct_info_wasm64.js && node ./script/out/generate_struct_info_wasm64.js",
|
|
20
|
+
"generate-struct-info": "npm run generate-struct-info-wasm32 && npm run generate-struct-info-wasm64"
|
|
18
21
|
},
|
|
19
22
|
"repository": {
|
|
20
23
|
"type": "git",
|
package/src/async_cleanup_hook.c
CHANGED
|
@@ -82,8 +82,6 @@ _emnapi_ach_handle_create(napi_env env,
|
|
|
82
82
|
return handle;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
EMNAPI_INTERNAL_EXTERN void _emnapi_set_immediate(void (*callback)(void*), void* data);
|
|
86
|
-
|
|
87
85
|
static void _emnapi_ach_handle_env_unref(void* arg) {
|
|
88
86
|
napi_env env = (napi_env) arg;
|
|
89
87
|
_emnapi_env_unref(env);
|
package/src/emnapi_internal.h
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
#ifndef EMNAPI_INTERNAL_H
|
|
2
|
+
#define EMNAPI_INTERNAL_H
|
|
3
|
+
|
|
1
4
|
#include "emnapi.h"
|
|
2
5
|
|
|
3
6
|
#if defined(__EMSCRIPTEN__) || defined(__wasi__)
|
|
@@ -109,6 +112,13 @@ EMNAPI_INTERNAL_EXTERN int _emnapi_is_main_browser_thread();
|
|
|
109
112
|
EMNAPI_INTERNAL_EXTERN int _emnapi_is_main_runtime_thread();
|
|
110
113
|
EMNAPI_INTERNAL_EXTERN double _emnapi_get_now();
|
|
111
114
|
EMNAPI_INTERNAL_EXTERN void _emnapi_unwind();
|
|
115
|
+
EMNAPI_INTERNAL_EXTERN void _emnapi_set_immediate(void (*callback)(void*), void* data);
|
|
116
|
+
EMNAPI_INTERNAL_EXTERN napi_status _emnapi_create_function(napi_env env,
|
|
117
|
+
const char* utf8name,
|
|
118
|
+
size_t length,
|
|
119
|
+
napi_callback cb,
|
|
120
|
+
void* data,
|
|
121
|
+
napi_value* result);
|
|
112
122
|
|
|
113
123
|
#if defined(__EMSCRIPTEN_PTHREADS__) || defined(_REENTRANT)
|
|
114
124
|
#define EMNAPI_HAVE_THREADS 1
|
|
@@ -186,3 +196,5 @@ void _emnapi_env_check_gc_access(napi_env env);
|
|
|
186
196
|
} while (0)
|
|
187
197
|
|
|
188
198
|
EXTERN_C_END
|
|
199
|
+
|
|
200
|
+
#endif
|
package/src/node_api.c
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#include "node_api.h"
|
|
2
2
|
#include "emnapi_internal.h"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
#include "uv.h"
|
|
6
|
-
#endif
|
|
4
|
+
struct uv_loop_s* uv_default_loop(void);
|
|
7
5
|
|
|
8
6
|
EXTERN_C_START
|
|
9
7
|
|
|
@@ -31,15 +29,11 @@ napi_get_node_version(node_api_basic_env env,
|
|
|
31
29
|
|
|
32
30
|
napi_status napi_get_uv_event_loop(node_api_basic_env env,
|
|
33
31
|
struct uv_loop_s** loop) {
|
|
34
|
-
#if EMNAPI_HAVE_THREADS && !defined(EMNAPI_DISABLE_UV)
|
|
35
32
|
CHECK_ENV(env);
|
|
36
33
|
CHECK_ARG(env, loop);
|
|
37
34
|
// Though this is fake libuv loop
|
|
38
35
|
*loop = uv_default_loop();
|
|
39
36
|
return napi_clear_last_error(env);
|
|
40
|
-
#else
|
|
41
|
-
return napi_set_last_error(env, napi_generic_failure, 0, NULL);
|
|
42
|
-
#endif
|
|
43
37
|
}
|
|
44
38
|
|
|
45
39
|
EMNAPI_INTERNAL_EXTERN int _emnapi_get_filename(napi_env env, char* buf, int len);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
#include <stddef.h>
|
|
2
2
|
#include <stdint.h>
|
|
3
3
|
|
|
4
|
+
#if defined(__EMSCRIPTEN_PTHREADS__) || (defined(_REENTRANT) && defined(__wasi__))
|
|
5
|
+
#include <pthread.h>
|
|
6
|
+
#else
|
|
7
|
+
int _emnapi_spawn_worker(void* (*worker)(void*), void* arg);
|
|
4
8
|
void* calloc(size_t n, size_t size);
|
|
5
9
|
|
|
6
10
|
extern unsigned char __heap_base;
|
|
@@ -32,9 +36,27 @@ void* __copy_tls(unsigned char *mem) {
|
|
|
32
36
|
:: "r"(tls_base));
|
|
33
37
|
return mem;
|
|
34
38
|
}
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
void* _emnapi_async_worker(void* arg);
|
|
35
42
|
|
|
36
43
|
__attribute__((visibility("default")))
|
|
37
|
-
void* emnapi_async_worker_create() {
|
|
44
|
+
void* emnapi_async_worker_create(int directly_spawn, void* global_address) {
|
|
45
|
+
#if defined(__EMSCRIPTEN_PTHREADS__) || (defined(_REENTRANT) && defined(__wasi__))
|
|
46
|
+
if (directly_spawn) {
|
|
47
|
+
pthread_t thread;
|
|
48
|
+
int r = pthread_create(&thread, NULL, _emnapi_async_worker, global_address);
|
|
49
|
+
if (r != 0) {
|
|
50
|
+
return NULL;
|
|
51
|
+
}
|
|
52
|
+
return (void*)(uintptr_t)thread;
|
|
53
|
+
}
|
|
54
|
+
return NULL;
|
|
55
|
+
#else
|
|
56
|
+
if (directly_spawn) {
|
|
57
|
+
int index = _emnapi_spawn_worker(_emnapi_async_worker, global_address);
|
|
58
|
+
return (void*)(intptr_t)(-(index + 1));
|
|
59
|
+
}
|
|
38
60
|
size_t args_size = sizeof(struct worker_args);
|
|
39
61
|
size_t size = args_size;
|
|
40
62
|
|
|
@@ -74,4 +96,5 @@ void* emnapi_async_worker_create() {
|
|
|
74
96
|
args->stack_base = block + args_size + tls_block_size + stack_size;
|
|
75
97
|
args->tls_base = tls_base;
|
|
76
98
|
return block;
|
|
99
|
+
#endif
|
|
77
100
|
}
|