emnapi 0.43.1 → 0.45.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/include/emnapi.h CHANGED
@@ -5,6 +5,10 @@
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 45
10
+ #define EMNAPI_PATCH_VERSION 0
11
+
8
12
  typedef enum {
9
13
  emnapi_runtime,
10
14
  emnapi_userland,
@@ -41,17 +45,17 @@ EMNAPI_EXTERN
41
45
  napi_status emnapi_get_module_property(napi_env env,
42
46
  const char* utf8name,
43
47
  napi_value* result);
48
+ #endif
44
49
 
45
50
  typedef struct {
46
51
  uint32_t major;
47
52
  uint32_t minor;
48
53
  uint32_t patch;
49
- } emnapi_emscripten_version;
54
+ } emnapi_runtime_version;
50
55
 
51
56
  EMNAPI_EXTERN
52
- napi_status emnapi_get_emscripten_version(napi_env env,
53
- const emnapi_emscripten_version** version);
54
- #endif
57
+ napi_status emnapi_get_runtime_version(napi_env env,
58
+ emnapi_runtime_version* version);
55
59
 
56
60
  EMNAPI_EXTERN
57
61
  napi_status emnapi_create_memory_view(napi_env env,
@@ -2,23 +2,29 @@
2
2
  #define EMNAPI_INCLUDE_COMMON_H_
3
3
 
4
4
  #ifdef __EMSCRIPTEN__
5
- #define NAPI_EXTERN __attribute__((__import_module__("env")))
6
-
7
5
  #define EMNAPI_EXTERN __attribute__((__import_module__("env")))
8
6
  #else
9
- #define NAPI_EXTERN __attribute__((__import_module__("napi")))
10
-
11
7
  #define EMNAPI_EXTERN __attribute__((__import_module__("emnapi")))
12
8
  #endif
13
9
 
14
10
  #define EMNAPI_INTERNAL_EXTERN __attribute__((__import_module__("env")))
15
11
 
16
12
  #ifdef __cplusplus
13
+ #ifndef EXTERN_C_START
17
14
  #define EXTERN_C_START extern "C" {
15
+ #endif
16
+
17
+ #ifndef EXTERN_C_END
18
18
  #define EXTERN_C_END }
19
+ #endif
19
20
  #else
21
+ #ifndef EXTERN_C_START
20
22
  #define EXTERN_C_START
23
+ #endif
24
+
25
+ #ifndef EXTERN_C_END
21
26
  #define EXTERN_C_END
22
27
  #endif
28
+ #endif
23
29
 
24
30
  #endif
@@ -21,15 +21,20 @@
21
21
  #endif
22
22
  #endif
23
23
 
24
+ #ifndef EMNAPI_UNMODIFIED_UPSTREAM
25
+ #if !defined(NAPI_EXTERN) && defined(__EMSCRIPTEN__)
26
+ #define NAPI_EXTERN __attribute__((__import_module__("env")))
27
+ #endif
28
+ #endif
29
+
24
30
  #include "js_native_api_types.h"
25
31
 
26
- #ifdef EMNAPI_UNMODIFIED_UPSTREAM
27
32
  // If you need __declspec(dllimport), either include <node_api.h> instead, or
28
33
  // define NAPI_EXTERN as __declspec(dllimport) on the compiler's command line.
29
34
  #ifndef NAPI_EXTERN
30
35
  #ifdef _WIN32
31
36
  #define NAPI_EXTERN __declspec(dllexport)
32
- #elif defined(__wasm32__)
37
+ #elif defined(__wasm__)
33
38
  #define NAPI_EXTERN \
34
39
  __attribute__((visibility("default"))) \
35
40
  __attribute__((__import_module__("napi")))
@@ -37,13 +42,9 @@
37
42
  #define NAPI_EXTERN __attribute__((visibility("default")))
38
43
  #endif
39
44
  #endif
40
- #else
41
- #include "emnapi_common.h"
42
- #endif
43
45
 
44
46
  #define NAPI_AUTO_LENGTH SIZE_MAX
45
47
 
46
- #ifdef EMNAPI_UNMODIFIED_UPSTREAM
47
48
  #ifdef __cplusplus
48
49
  #define EXTERN_C_START extern "C" {
49
50
  #define EXTERN_C_END }
@@ -51,7 +52,6 @@
51
52
  #define EXTERN_C_START
52
53
  #define EXTERN_C_END
53
54
  #endif
54
- #endif
55
55
 
56
56
  EXTERN_C_START
57
57
 
@@ -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,
@@ -1,16 +1,24 @@
1
1
  #ifndef SRC_NODE_API_H_
2
2
  #define SRC_NODE_API_H_
3
3
 
4
- #ifdef EMNAPI_UNMODIFIED_UPSTREAM
5
- #ifdef BUILDING_NODE_EXTENSION
4
+ #ifndef EMNAPI_UNMODIFIED_UPSTREAM
5
+ #ifndef BUILDING_NODE_EXTENSION
6
+ #define BUILDING_NODE_EXTENSION
7
+ #endif
8
+
9
+ #if !defined(NAPI_EXTERN) && defined(__EMSCRIPTEN__)
10
+ #define NAPI_EXTERN __attribute__((__import_module__("env")))
11
+ #endif
12
+ #endif
13
+
14
+ #if defined(BUILDING_NODE_EXTENSION) && !defined(NAPI_EXTERN)
6
15
  #ifdef _WIN32
7
16
  // Building native addon against node
8
17
  #define NAPI_EXTERN __declspec(dllimport)
9
- #elif defined(__wasm32__)
18
+ #elif defined(__wasm__)
10
19
  #define NAPI_EXTERN __attribute__((__import_module__("napi")))
11
20
  #endif
12
21
  #endif
13
- #endif
14
22
  #include "js_native_api.h"
15
23
  #include "node_api_types.h"
16
24
 
@@ -19,16 +27,13 @@ struct uv_loop_s; // Forward declaration.
19
27
  #ifdef _WIN32
20
28
  #define NAPI_MODULE_EXPORT __declspec(dllexport)
21
29
  #else
22
- #ifdef EMNAPI_UNMODIFIED_UPSTREAM
23
- #define NAPI_MODULE_EXPORT __attribute__((visibility("default")))
24
- #else
25
30
  #ifdef __EMSCRIPTEN__
26
- #define NAPI_MODULE_EXPORT __attribute__((visibility("default"))) __attribute__((used))
31
+ #define NAPI_MODULE_EXPORT \
32
+ __attribute__((visibility("default"))) __attribute__((used))
27
33
  #else
28
34
  #define NAPI_MODULE_EXPORT __attribute__((visibility("default")))
29
35
  #endif
30
36
  #endif
31
- #endif
32
37
 
33
38
  #if defined(__GNUC__)
34
39
  #define NAPI_NO_RETURN __attribute__((noreturn))
@@ -59,19 +64,11 @@ typedef struct napi_module {
59
64
  NAPI_MODULE_INITIALIZER_X_HELPER(base, version)
60
65
  #define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version
61
66
 
62
- #ifdef EMNAPI_UNMODIFIED_UPSTREAM
63
- #ifdef __wasm32__
64
- #define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
65
- #else
66
- #define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
67
- #endif
68
- #else
69
67
  #ifdef __wasm__
70
68
  #define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
71
69
  #else
72
70
  #define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
73
71
  #endif
74
- #endif
75
72
 
76
73
  #define NODE_API_MODULE_GET_API_VERSION_BASE node_api_module_get_api_version_v
77
74
 
@@ -160,7 +157,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_buffer_info(napi_env env,
160
157
  napi_value value,
161
158
  void** data,
162
159
  size_t* length);
163
- #if !defined(EMNAPI_UNMODIFIED_UPSTREAM) || (defined(EMNAPI_UNMODIFIED_UPSTREAM) && !defined(__wasm32__))
160
+
164
161
  // Methods to manage simple async operations
165
162
  NAPI_EXTERN napi_status NAPI_CDECL
166
163
  napi_create_async_work(napi_env env,
@@ -176,7 +173,6 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(napi_env env,
176
173
  napi_async_work work);
177
174
  NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(napi_env env,
178
175
  napi_async_work work);
179
- #endif // __wasm32__
180
176
 
181
177
  // version management
182
178
  NAPI_EXTERN napi_status NAPI_CDECL
@@ -214,7 +210,6 @@ napi_close_callback_scope(napi_env env, napi_callback_scope scope);
214
210
 
215
211
  #if NAPI_VERSION >= 4
216
212
 
217
- #if !defined(EMNAPI_UNMODIFIED_UPSTREAM) || (defined(EMNAPI_UNMODIFIED_UPSTREAM) && !defined(__wasm32__))
218
213
  // Calling into JS from other threads
219
214
  NAPI_EXTERN napi_status NAPI_CDECL
220
215
  napi_create_threadsafe_function(napi_env env,
@@ -248,7 +243,6 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
248
243
 
249
244
  NAPI_EXTERN napi_status NAPI_CDECL
250
245
  napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
251
- #endif // __wasm32__
252
246
 
253
247
  #endif // NAPI_VERSION >= 4
254
248
 
package/index.js CHANGED
@@ -9,7 +9,6 @@ const jsLibrary = path.join(__dirname, './dist/library_napi.js')
9
9
  const sources = [
10
10
  path.join(__dirname, './src/js_native_api.c'),
11
11
  path.join(__dirname, './src/node_api.c'),
12
- path.join(__dirname, './src/emnapi.c'),
13
12
  path.join(__dirname, './src/async_cleanup_hook.c'),
14
13
  path.join(__dirname, './src/async_context.c'),
15
14
  path.join(__dirname, './src/async_work.c'),
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
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)
1
+ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.44 (bec42dac7873903d09d713963e34020c22a8bd2d)
2
+ clang version 17.0.0 (https://github.com/llvm/llvm-project a8cbd27d1f238e104a5d5ca345d93bc1f4d4ab1f)
3
3
  Target: wasm32-unknown-emscripten
4
4
  Thread model: posix
5
- InstalledDir: /home/runner/work/emnapi/emnapi/emsdk-cache/emsdk-main/upstream/bin
5
+ InstalledDir: /home/runner/work/_temp/14a1b1b6-9a98-4bac-8f31-5c9ebda805ed/emsdk-main/upstream/bin
Binary file
Binary file
Binary file
@@ -1,4 +1,4 @@
1
- clang version 16.0.0
1
+ clang version 17.0.6
2
2
  Target: wasm32-unknown-wasi-threads
3
3
  Thread model: posix
4
- InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-20.0/bin
4
+ InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-21.0/bin
@@ -1,4 +1,4 @@
1
- clang version 16.0.0
1
+ clang version 17.0.6
2
2
  Target: wasm32-unknown-wasi
3
3
  Thread model: posix
4
- InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-20.0/bin
4
+ InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-21.0/bin
package/lib/wasm32.txt CHANGED
@@ -1,4 +1,4 @@
1
- clang version 16.0.0
1
+ clang version 17.0.6
2
2
  Target: wasm32
3
3
  Thread model: posix
4
- InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-20.0/bin
4
+ InstalledDir: /home/runner/work/emnapi/emnapi/wasi-sdk-21.0/bin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emnapi",
3
- "version": "0.43.1",
3
+ "version": "0.45.0",
4
4
  "description": "Node-API implementation for Emscripten",
5
5
  "main": "index.js",
6
6
  "peerDependencies": {
@@ -12,7 +12,8 @@
12
12
  }
13
13
  },
14
14
  "scripts": {
15
- "build": "node ./script/build.js"
15
+ "build": "node ./script/build.js",
16
+ "version": "node ./script/version.js"
16
17
  },
17
18
  "repository": {
18
19
  "type": "git",
@@ -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)) { \
@@ -1,9 +1,5 @@
1
1
  #include "emnapi_internal.h"
2
2
 
3
- #ifdef __EMSCRIPTEN__
4
- #include <emscripten/heap.h>
5
- #endif
6
-
7
3
  EXTERN_C_START
8
4
 
9
5
  static const char* emnapi_error_messages[] = {
@@ -67,34 +63,4 @@ napi_status napi_get_last_error_info(
67
63
  return napi_ok;
68
64
  }
69
65
 
70
- #define PAGESIZE 65536
71
-
72
- napi_status napi_adjust_external_memory(napi_env env,
73
- int64_t change_in_bytes,
74
- int64_t* adjusted_value) {
75
- CHECK_ENV(env);
76
- CHECK_ARG(env, adjusted_value);
77
-
78
- if (change_in_bytes < 0) {
79
- return napi_set_last_error(env, napi_invalid_arg, 0, NULL);
80
- }
81
-
82
- size_t old_size = __builtin_wasm_memory_size(0) << 16;
83
- size_t new_size = old_size + (size_t) change_in_bytes;
84
- #ifdef __EMSCRIPTEN__
85
- if (!emscripten_resize_heap(new_size)) {
86
- return napi_set_last_error(env, napi_generic_failure, 0, NULL);
87
- }
88
- #else
89
- new_size = new_size + (PAGESIZE - new_size % PAGESIZE) % PAGESIZE;
90
- if (-1 == __builtin_wasm_memory_grow(0, (new_size - old_size + 65535) >> 16)) {
91
- return napi_set_last_error(env, napi_generic_failure, 0, NULL);
92
- }
93
- #endif
94
-
95
- *adjusted_value = (int64_t) (__builtin_wasm_memory_size(0) << 16);
96
-
97
- return napi_clear_last_error(env);
98
- }
99
-
100
66
  EXTERN_C_END
@@ -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);
package/src/emnapi.c DELETED
@@ -1,21 +0,0 @@
1
- #include "emnapi_internal.h"
2
-
3
- EXTERN_C_START
4
-
5
- #ifdef __EMSCRIPTEN__
6
- napi_status
7
- emnapi_get_emscripten_version(napi_env env,
8
- const emnapi_emscripten_version** version) {
9
- CHECK_ENV(env);
10
- CHECK_ARG(env, version);
11
- static emnapi_emscripten_version emscripten_version = {
12
- __EMSCRIPTEN_major__,
13
- __EMSCRIPTEN_minor__,
14
- __EMSCRIPTEN_tiny__
15
- };
16
- *version = &emscripten_version;
17
- return napi_clear_last_error(env);
18
- }
19
- #endif
20
-
21
- EXTERN_C_END