emnapi 0.31.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.
Files changed (44) hide show
  1. package/CMakeLists.txt +160 -0
  2. package/LICENSE +21 -0
  3. package/README.md +875 -0
  4. package/cmake/wasm32.cmake +32 -0
  5. package/dist/library_napi.js +4784 -0
  6. package/include/common.h +26 -0
  7. package/include/emnapi.h +81 -0
  8. package/include/js_native_api.h +560 -0
  9. package/include/js_native_api_types.h +159 -0
  10. package/include/napi-inl.deprecated.h +186 -0
  11. package/include/napi-inl.h +6299 -0
  12. package/include/napi.h +3127 -0
  13. package/include/node_api.h +226 -0
  14. package/include/node_api_types.h +56 -0
  15. package/include/uv/threadpool.h +41 -0
  16. package/include/uv/unix.h +21 -0
  17. package/include/uv.h +134 -0
  18. package/index.d.ts +4 -0
  19. package/index.js +22 -0
  20. package/lib/wasm32/libdlmalloc.a +0 -0
  21. package/lib/wasm32/libemmalloc.a +0 -0
  22. package/lib/wasm32/libemnapi.a +0 -0
  23. package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
  24. package/lib/wasm32-emscripten/libemnapi.a +0 -0
  25. package/lib/wasm32-emscripten.txt +5 -0
  26. package/lib/wasm32-wasi/libemnapi.a +0 -0
  27. package/lib/wasm32-wasi.txt +4 -0
  28. package/lib/wasm32.txt +4 -0
  29. package/package.json +43 -0
  30. package/src/emnapi.c +1344 -0
  31. package/src/malloc/dlmalloc/dlmalloc.c +92 -0
  32. package/src/malloc/dlmalloc/malloc.c +6395 -0
  33. package/src/malloc/emmalloc/emmalloc.c +1551 -0
  34. package/src/malloc/memcpy.c +136 -0
  35. package/src/malloc/memset.c +98 -0
  36. package/src/malloc/sbrk.c +29 -0
  37. package/src/uv/queue.h +108 -0
  38. package/src/uv/threadpool.c +408 -0
  39. package/src/uv/unix/async.c +206 -0
  40. package/src/uv/unix/core.c +35 -0
  41. package/src/uv/unix/loop.c +36 -0
  42. package/src/uv/unix/thread.c +118 -0
  43. package/src/uv/uv-common.c +51 -0
  44. package/src/uv/uv-common.h +68 -0
@@ -0,0 +1,118 @@
1
+ #if defined(__EMSCRIPTEN_PTHREADS__) || defined(_REENTRANT)
2
+
3
+ #include <assert.h>
4
+ #include <errno.h>
5
+ #include <stdlib.h>
6
+ #include <time.h>
7
+ #include "uv.h"
8
+
9
+ void uv_sem_post(sem_t* sem) {
10
+ if (sem_post(sem))
11
+ abort();
12
+ }
13
+
14
+ int uv_sem_init(sem_t* sem, unsigned int value) {
15
+ if (sem_init(sem, 0, value))
16
+ return errno;
17
+ return 0;
18
+ }
19
+
20
+ void uv_sem_wait(sem_t* sem) {
21
+ int r;
22
+
23
+ do {
24
+ r = sem_wait(sem);
25
+ } while (r == -1 && errno == EINTR);
26
+
27
+ if (r)
28
+ abort();
29
+ }
30
+
31
+ void uv_sem_destroy(sem_t* sem) {
32
+ if (sem_destroy(sem))
33
+ abort();
34
+ }
35
+
36
+ void uv_once(pthread_once_t* guard, void (*callback)(void)) {
37
+ if (pthread_once(guard, callback))
38
+ abort();
39
+ }
40
+
41
+ int uv_mutex_init(uv_mutex_t* mutex) {
42
+ #if defined(NDEBUG) || !defined(PTHREAD_MUTEX_ERRORCHECK)
43
+ return pthread_mutex_init(mutex, NULL);
44
+ #else
45
+ pthread_mutexattr_t attr;
46
+ int err;
47
+
48
+ if (pthread_mutexattr_init(&attr))
49
+ abort();
50
+
51
+ if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK))
52
+ abort();
53
+
54
+ err = pthread_mutex_init(mutex, &attr);
55
+
56
+ if (pthread_mutexattr_destroy(&attr))
57
+ abort();
58
+
59
+ return err;
60
+ #endif
61
+ }
62
+
63
+ void uv_mutex_destroy(uv_mutex_t* mutex) {
64
+ if (pthread_mutex_destroy(mutex))
65
+ abort();
66
+ }
67
+
68
+ void uv_mutex_lock(uv_mutex_t* mutex) {
69
+ if (pthread_mutex_lock(mutex))
70
+ abort();
71
+ }
72
+
73
+ void uv_mutex_unlock(uv_mutex_t* mutex) {
74
+ if (pthread_mutex_unlock(mutex))
75
+ abort();
76
+ }
77
+
78
+ int uv_cond_init(uv_cond_t* cond) {
79
+ return pthread_cond_init(cond, NULL);
80
+ }
81
+
82
+ void uv_cond_signal(uv_cond_t* cond) {
83
+ if (pthread_cond_signal(cond))
84
+ abort();
85
+ }
86
+
87
+ void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
88
+ if (pthread_cond_wait(cond, mutex))
89
+ abort();
90
+ }
91
+
92
+ int uv_thread_create_ex(uv_thread_t* tid,
93
+ void* params,
94
+ void (*entry)(void *arg),
95
+ void *arg) {
96
+ int err;
97
+
98
+ /* Used to squelch a -Wcast-function-type warning. */
99
+ union {
100
+ void (*in)(void*);
101
+ void* (*out)(void*);
102
+ } f;
103
+
104
+ f.in = entry;
105
+ err = pthread_create(tid, NULL, f.out, arg);
106
+
107
+ return err;
108
+ }
109
+
110
+ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
111
+ return uv_thread_create_ex(tid, NULL, entry, arg);
112
+ }
113
+
114
+ int uv_thread_join(uv_thread_t *tid) {
115
+ return pthread_join(*tid, NULL);
116
+ }
117
+
118
+ #endif
@@ -0,0 +1,51 @@
1
+ #if defined(__EMSCRIPTEN_PTHREADS__) || defined(_REENTRANT)
2
+
3
+ #include <errno.h>
4
+ #include <string.h>
5
+ #include "uv-common.h"
6
+
7
+ static uv_loop_t default_loop_struct;
8
+ static uv_loop_t* default_loop_ptr;
9
+
10
+
11
+ uv_loop_t* uv_default_loop(void) {
12
+ if (default_loop_ptr != NULL)
13
+ return default_loop_ptr;
14
+
15
+ if (uv_loop_init(&default_loop_struct))
16
+ return NULL;
17
+
18
+ default_loop_ptr = &default_loop_struct;
19
+ return default_loop_ptr;
20
+ }
21
+
22
+ int uv_loop_close(uv_loop_t* loop) {
23
+ // QUEUE* q;
24
+ // uv_handle_t* h;
25
+ #ifndef NDEBUG
26
+ void* saved_data;
27
+ #endif
28
+
29
+ if (uv__has_active_reqs(loop))
30
+ return EBUSY;
31
+
32
+ // QUEUE_FOREACH(q, &loop->handle_queue) {
33
+ // h = QUEUE_DATA(q, uv_handle_t, handle_queue);
34
+ // if (!(h->flags & UV_HANDLE_INTERNAL))
35
+ // return UV_EBUSY;
36
+ // }
37
+
38
+ uv__loop_close(loop);
39
+
40
+ #ifndef NDEBUG
41
+ saved_data = loop->data;
42
+ memset(loop, -1, sizeof(*loop));
43
+ loop->data = saved_data;
44
+ #endif
45
+ if (loop == default_loop_ptr)
46
+ default_loop_ptr = NULL;
47
+
48
+ return 0;
49
+ }
50
+
51
+ #endif
@@ -0,0 +1,68 @@
1
+ #ifndef UV_COMMON_H_
2
+ #define UV_COMMON_H_
3
+
4
+ #if defined(__EMSCRIPTEN__)
5
+ #ifndef EMNAPI_USE_PROXYING
6
+ #include <emscripten.h> /* version.h */
7
+ #if __EMSCRIPTEN_major__ * 10000 + __EMSCRIPTEN_minor__ * 100 + __EMSCRIPTEN_tiny__ >= 30109
8
+ #define EMNAPI_USE_PROXYING 1
9
+ #else
10
+ #define EMNAPI_USE_PROXYING 0
11
+ #endif
12
+ #endif
13
+ #else
14
+ #define EMNAPI_USE_PROXYING 0
15
+ #endif
16
+
17
+ #if defined(__EMSCRIPTEN_PTHREADS__) || defined(_REENTRANT)
18
+ #include <assert.h>
19
+ #include "uv.h"
20
+ #include "queue.h"
21
+
22
+ #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
23
+ // #define offsetof(s, m) __builtin_offsetof(s, m)
24
+ #define container_of(ptr, type, member) \
25
+ ((type *) ((char *) (ptr) - offsetof(type, member)))
26
+
27
+ #define UV_REQ_INIT(req, typ) \
28
+ do { \
29
+ (req)->type = (typ); \
30
+ } \
31
+ while (0)
32
+
33
+ #define uv__has_active_reqs(loop) \
34
+ ((loop)->active_reqs.count > 0)
35
+
36
+ #define uv__req_register(loop, req) \
37
+ do { \
38
+ (loop)->active_reqs.count++; \
39
+ } \
40
+ while (0)
41
+
42
+ #define uv__req_unregister(loop, req) \
43
+ do { \
44
+ assert(uv__has_active_reqs(loop)); \
45
+ (loop)->active_reqs.count--; \
46
+ } \
47
+ while (0)
48
+
49
+ #define uv__req_init(loop, req, typ) \
50
+ do { \
51
+ UV_REQ_INIT(req, typ); \
52
+ uv__req_register(loop, req); \
53
+ } \
54
+ while (0)
55
+
56
+ enum uv__work_kind {
57
+ UV__WORK_CPU,
58
+ UV__WORK_FAST_IO,
59
+ UV__WORK_SLOW_IO
60
+ };
61
+
62
+ void uv__work_done(uv_async_t* handle);
63
+ void uv__loop_close(uv_loop_t* loop);
64
+ void uv__async_close(uv_async_t* handle);
65
+
66
+ #endif
67
+
68
+ #endif /* UV_COMMON_H_ */