emnapi 0.44.0 → 1.0.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 (48) hide show
  1. package/CMakeLists.txt +30 -16
  2. package/README.md +159 -142
  3. package/cmake/wasm32.cmake +1 -1
  4. package/common.gypi +423 -0
  5. package/dist/library_napi.js +5913 -5152
  6. package/emnapi.gyp +120 -0
  7. package/include/node/config.gypi +5 -0
  8. package/include/{emnapi.h → node/emnapi.h} +2 -2
  9. package/include/{js_native_api.h → node/js_native_api.h} +9 -0
  10. package/index.js +4 -2
  11. package/lib/wasm32/libdlmalloc-mt.a +0 -0
  12. package/lib/wasm32/libdlmalloc.a +0 -0
  13. package/lib/wasm32/libemmalloc-mt.a +0 -0
  14. package/lib/wasm32/libemmalloc.a +0 -0
  15. package/lib/wasm32/libemnapi-basic-mt.a +0 -0
  16. package/lib/wasm32/libemnapi-basic.a +0 -0
  17. package/lib/wasm32/libemnapi.a +0 -0
  18. package/lib/wasm32-emscripten/libemnapi-basic.a +0 -0
  19. package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
  20. package/lib/wasm32-emscripten/libemnapi.a +0 -0
  21. package/lib/wasm32-wasi/libemnapi-basic-mt.a +0 -0
  22. package/lib/wasm32-wasi/libemnapi-basic.a +0 -0
  23. package/lib/wasm32-wasi/libemnapi.a +0 -0
  24. package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
  25. package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
  26. package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
  27. package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
  28. package/lib/wasm64-emscripten/libemnapi-basic.a +0 -0
  29. package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
  30. package/lib/wasm64-emscripten/libemnapi.a +0 -0
  31. package/package.json +1 -1
  32. package/src/async_context.c +2 -4
  33. package/src/async_work.c +2 -4
  34. package/src/emnapi_internal.h +6 -0
  35. package/src/js_native_api.c +2 -0
  36. package/src/malloc/emmalloc/emmalloc.c +8 -3
  37. package/src/threadsafe_function.c +1 -2
  38. package/lib/wasm32-emscripten.txt +0 -5
  39. package/lib/wasm32-wasi-threads.txt +0 -4
  40. package/lib/wasm32-wasi.txt +0 -4
  41. package/lib/wasm32.txt +0 -4
  42. /package/include/{emnapi_common.h → node/emnapi_common.h} +0 -0
  43. /package/include/{js_native_api_types.h → node/js_native_api_types.h} +0 -0
  44. /package/include/{node_api.h → node/node_api.h} +0 -0
  45. /package/include/{node_api_types.h → node/node_api_types.h} +0 -0
  46. /package/include/{uv → node/uv}/threadpool.h +0 -0
  47. /package/include/{uv → node/uv}/unix.h +0 -0
  48. /package/include/{uv.h → node/uv.h} +0 -0
package/emnapi.gyp ADDED
@@ -0,0 +1,120 @@
1
+ {
2
+ 'targets': [
3
+ {
4
+ 'target_name': 'dlmalloc',
5
+ 'type': 'static_library',
6
+ 'defines': [
7
+ 'PAGESIZE=65536'
8
+ ],
9
+ 'sources': [
10
+ 'src/malloc/sbrk.c',
11
+ 'src/malloc/memcpy.c',
12
+ 'src/malloc/memset.c',
13
+ 'src/malloc/dlmalloc/dlmalloc.c',
14
+ ],
15
+ 'conditions': [
16
+ ['wasm_threads != 0', {
17
+ 'defines': [
18
+ 'USE_LOCKS=1'
19
+ ],
20
+ }],
21
+ ],
22
+ },
23
+ {
24
+ 'target_name': 'emmalloc',
25
+ 'type': 'static_library',
26
+ 'defines': [
27
+ 'PAGESIZE=65536'
28
+ ],
29
+ 'sources': [
30
+ 'src/malloc/sbrk.c',
31
+ 'src/malloc/memcpy.c',
32
+ 'src/malloc/memset.c',
33
+ 'src/malloc/emmalloc/emmalloc.c',
34
+ ],
35
+ 'cflags': [ '-fno-strict-aliasing' ],
36
+ 'xcode_settings': {
37
+ 'GCC_STRICT_ALIASING': 'NO',
38
+ },
39
+ 'conditions': [
40
+ ['wasm_threads != 0', {
41
+ 'defines': [
42
+ '__EMSCRIPTEN_SHARED_MEMORY__=1'
43
+ ],
44
+ }],
45
+ ],
46
+ },
47
+ {
48
+ 'target_name': 'emnapi_basic',
49
+ 'type': 'static_library',
50
+ 'sources': [
51
+ 'src/js_native_api.c',
52
+ 'src/node_api.c',
53
+ 'src/async_cleanup_hook.c',
54
+ 'src/async_context.c',
55
+ ],
56
+ 'link_settings': {
57
+ 'target_conditions': [
58
+ ['_type == "executable" and OS == "emscripten"', {
59
+ 'libraries': [
60
+ '--js-library=<(emnapi_js_library)',
61
+ ]
62
+ }],
63
+ ]
64
+ },
65
+ 'conditions': [
66
+ ['wasm_threads != 0 and OS in " unknown"', {
67
+ 'sources': [
68
+ 'src/thread/async_worker_create.c',
69
+ 'src/thread/async_worker_init.S',
70
+ ],
71
+ 'link_settings': {
72
+ 'target_conditions': [
73
+ ['_type == "executable"', {
74
+ 'ldflags': [
75
+ '-Wl,--export=emnapi_async_worker_create',
76
+ '-Wl,--export=emnapi_async_worker_init',
77
+ ],
78
+ 'xcode_settings': {
79
+ 'OTHER_LDFLAGS': [
80
+ '-Wl,--export=emnapi_async_worker_create',
81
+ '-Wl,--export=emnapi_async_worker_init',
82
+ ],
83
+ },
84
+ }],
85
+ ]
86
+ },
87
+ }],
88
+ ]
89
+ },
90
+ {
91
+ 'target_name': 'emnapi',
92
+ 'type': 'static_library',
93
+ 'sources': [
94
+ 'src/js_native_api.c',
95
+ 'src/node_api.c',
96
+ 'src/async_cleanup_hook.c',
97
+ 'src/async_context.c',
98
+
99
+ 'src/uv/uv-common.c',
100
+ 'src/uv/threadpool.c',
101
+ 'src/uv/unix/loop.c',
102
+ 'src/uv/unix/thread.c',
103
+ 'src/uv/unix/async.c',
104
+ 'src/uv/unix/core.c',
105
+
106
+ 'src/async_work.c',
107
+ 'src/threadsafe_function.c',
108
+ ],
109
+ 'link_settings': {
110
+ 'target_conditions': [
111
+ ['_type == "executable" and OS == "emscripten"', {
112
+ 'libraries': [
113
+ '--js-library=<(emnapi_js_library)',
114
+ ]
115
+ }],
116
+ ]
117
+ },
118
+ }
119
+ ]
120
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ 'variables': {
3
+ 'napi_build_version': '9'
4
+ }
5
+ }
@@ -5,8 +5,8 @@
5
5
  #include "js_native_api_types.h"
6
6
  #include "emnapi_common.h"
7
7
 
8
- #define EMNAPI_MAJOR_VERSION 0
9
- #define EMNAPI_MINOR_VERSION 44
8
+ #define EMNAPI_MAJOR_VERSION 1
9
+ #define EMNAPI_MINOR_VERSION 0
10
10
  #define EMNAPI_PATCH_VERSION 0
11
11
 
12
12
  typedef enum {
@@ -99,6 +99,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env,
99
99
  size_t length,
100
100
  napi_value* result);
101
101
  #ifdef NAPI_EXPERIMENTAL
102
+ #define NODE_API_EXPERIMENTAL_HAS_EXTERNAL_STRINGS
102
103
  NAPI_EXTERN napi_status NAPI_CDECL
103
104
  node_api_create_external_string_latin1(napi_env env,
104
105
  char* str,
@@ -116,6 +117,13 @@ node_api_create_external_string_utf16(napi_env env,
116
117
  napi_value* result,
117
118
  bool* copied);
118
119
  #endif // NAPI_EXPERIMENTAL
120
+
121
+ #ifdef NAPI_EXPERIMENTAL
122
+ #define NODE_API_EXPERIMENTAL_HAS_PROPERTY_KEYS
123
+ NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_utf16(
124
+ napi_env env, const char16_t* str, size_t length, napi_value* result);
125
+ #endif // NAPI_EXPERIMENTAL
126
+
119
127
  NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol(napi_env env,
120
128
  napi_value description,
121
129
  napi_value* result);
@@ -524,6 +532,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env,
524
532
  #endif // NAPI_VERSION >= 5
525
533
 
526
534
  #ifdef NAPI_EXPERIMENTAL
535
+ #define NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
527
536
 
528
537
  NAPI_EXTERN napi_status NAPI_CDECL
529
538
  node_api_post_finalizer(napi_env env,
package/index.js CHANGED
@@ -3,9 +3,9 @@ Object.defineProperty(exports, '__esModule', { value: true })
3
3
 
4
4
  const path = require('path')
5
5
 
6
- const include = path.join(__dirname, 'include')
6
+ const include = path.join(__dirname, 'include/node')
7
7
  const includeDir = path.relative(process.cwd(), include)
8
- const jsLibrary = path.join(__dirname, './dist/library_napi.js')
8
+ const jsLibrary = path.join(__dirname, './dist/library_napi.js').replace(/\\|\\\\/g, '/')
9
9
  const sources = [
10
10
  path.join(__dirname, './src/js_native_api.c'),
11
11
  path.join(__dirname, './src/node_api.c'),
@@ -20,8 +20,10 @@ const sources = [
20
20
  path.join(__dirname, './src/uv/unix/async.c'),
21
21
  path.join(__dirname, './src/uv/unix/core.c')
22
22
  ]
23
+ const targets = path.relative(process.cwd(), path.join(__dirname, 'emnapi.gyp'))
23
24
 
24
25
  exports.include = include
25
26
  exports.include_dir = includeDir
26
27
  exports.js_library = jsLibrary
27
28
  exports.sources = sources
29
+ exports.targets = targets
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": "0.44.0",
3
+ "version": "1.0.0",
4
4
  "description": "Node-API implementation for Emscripten",
5
5
  "main": "index.js",
6
6
  "peerDependencies": {
@@ -20,8 +20,7 @@ napi_async_init(napi_env env,
20
20
  napi_value async_resource,
21
21
  napi_value async_resource_name,
22
22
  napi_async_context* result) {
23
- CHECK_ENV(env);
24
- _emnapi_env_check_gc_access(env);
23
+ CHECK_ENV_NOT_IN_GC(env);
25
24
  CHECK_ARG(env, async_resource_name);
26
25
  CHECK_ARG(env, result);
27
26
 
@@ -39,8 +38,7 @@ napi_async_init(napi_env env,
39
38
 
40
39
  napi_status napi_async_destroy(napi_env env,
41
40
  napi_async_context async_context) {
42
- CHECK_ENV(env);
43
- _emnapi_env_check_gc_access(env);
41
+ CHECK_ENV_NOT_IN_GC(env);
44
42
  CHECK_ARG(env, async_context);
45
43
 
46
44
  napi_status status = _emnapi_async_destroy_js(async_context);
package/src/async_work.c CHANGED
@@ -148,8 +148,7 @@ napi_status napi_create_async_work(napi_env env,
148
148
  void* data,
149
149
  napi_async_work* result) {
150
150
  #if EMNAPI_HAVE_THREADS
151
- CHECK_ENV(env);
152
- _emnapi_env_check_gc_access(env);
151
+ CHECK_ENV_NOT_IN_GC(env);
153
152
  CHECK_ARG(env, execute);
154
153
  CHECK_ARG(env, result);
155
154
 
@@ -188,8 +187,7 @@ napi_status napi_create_async_work(napi_env env,
188
187
 
189
188
  napi_status napi_delete_async_work(napi_env env, napi_async_work work) {
190
189
  #if EMNAPI_HAVE_THREADS
191
- CHECK_ENV(env);
192
- _emnapi_env_check_gc_access(env);
190
+ CHECK_ENV_NOT_IN_GC(env);
193
191
  CHECK_ARG(env, work);
194
192
 
195
193
  async_work_delete(work);
@@ -52,6 +52,12 @@ EXTERN_C_END
52
52
  #define CHECK_ARG(env, arg) \
53
53
  RETURN_STATUS_IF_FALSE((env), ((arg) != NULL), napi_invalid_arg)
54
54
 
55
+ #define CHECK_ENV_NOT_IN_GC(env) \
56
+ do { \
57
+ CHECK_ENV((env)); \
58
+ _emnapi_env_check_gc_access((env)); \
59
+ } while (0)
60
+
55
61
  #define CHECK(expr) \
56
62
  do { \
57
63
  if (!(expr)) { \
@@ -42,8 +42,10 @@ napi_status napi_get_last_error_info(
42
42
 
43
43
  const int last_status = napi_cannot_run_js;
44
44
 
45
+ #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || defined(__cplusplus)
45
46
  static_assert((sizeof(emnapi_error_messages) / sizeof(const char*)) == napi_cannot_run_js + 1,
46
47
  "Count of error messages must match count of error values");
48
+ #endif
47
49
 
48
50
  _emnapi_get_last_error_info(env,
49
51
  &last_error.error_code,
@@ -77,6 +77,7 @@ _Noreturn void __assert_fail(const char *expr, const char *file, int line, const
77
77
 
78
78
  // Defind by the linker to have the address of the start of the heap.
79
79
  extern unsigned char __heap_base;
80
+ extern unsigned char __heap_end;
80
81
 
81
82
  // Behavior of right shifting a signed integer is compiler implementation defined.
82
83
  static_assert((((int32_t)0x80000000U) >> 31) == -1, "This malloc implementation requires that right-shifting a signed integer produces a sign-extending (arithmetic) shift!");
@@ -566,9 +567,13 @@ static bool claim_more_memory(size_t numBytes)
566
567
  // If this is the first time we're called, see if we can use
567
568
  // the initial heap memory set up by wasm-ld.
568
569
  if (!listOfAllRegions) {
569
- unsigned char *heap_end = sbrk(0);
570
- if (numBytes <= (size_t)(heap_end - &__heap_base)) {
571
- startPtr = &__heap_base;
570
+ unsigned char *heap_base = &__heap_base;
571
+ unsigned char *heap_end = &__heap_end;
572
+ if (heap_end < heap_base) {
573
+ __builtin_trap();
574
+ }
575
+ if (numBytes <= (size_t)(heap_end - heap_base)) {
576
+ startPtr = heap_base;
572
577
  endPtr = heap_end;
573
578
  break;
574
579
  }
@@ -408,8 +408,7 @@ napi_create_threadsafe_function(napi_env env,
408
408
  napi_threadsafe_function_call_js call_js_cb,
409
409
  napi_threadsafe_function* result) {
410
410
  #if EMNAPI_HAVE_THREADS
411
- CHECK_ENV(env);
412
- _emnapi_env_check_gc_access(env);
411
+ CHECK_ENV_NOT_IN_GC(env);
413
412
  CHECK_ARG(env, async_resource_name);
414
413
  RETURN_STATUS_IF_FALSE(env, initial_thread_count > 0, napi_invalid_arg);
415
414
  CHECK_ARG(env, result);
@@ -1,5 +0,0 @@
1
- emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.36 (518d9fea335f7cd2b5771e43df76e0535c6df5dd)
2
- clang version 17.0.0 (https://github.com/llvm/llvm-project 5084abbea933b1a510556726a9e226b5ae22f19f)
3
- Target: wasm32-unknown-emscripten
4
- Thread model: posix
5
- InstalledDir: /home/runner/work/emnapi/emnapi/emsdk-cache/emsdk-main/upstream/bin
@@ -1,4 +0,0 @@
1
- clang version 16.0.0
2
- Target: wasm32-unknown-wasi-threads
3
- Thread model: posix
4
- InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-20.0/bin
@@ -1,4 +0,0 @@
1
- clang version 16.0.0
2
- Target: wasm32-unknown-wasi
3
- Thread model: posix
4
- InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-20.0/bin
package/lib/wasm32.txt DELETED
@@ -1,4 +0,0 @@
1
- clang version 16.0.0
2
- Target: wasm32
3
- Thread model: posix
4
- InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-20.0/bin
File without changes
File without changes
File without changes
File without changes