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.
- package/CMakeLists.txt +160 -0
- package/LICENSE +21 -0
- package/README.md +875 -0
- package/cmake/wasm32.cmake +32 -0
- package/dist/library_napi.js +4784 -0
- package/include/common.h +26 -0
- package/include/emnapi.h +81 -0
- package/include/js_native_api.h +560 -0
- package/include/js_native_api_types.h +159 -0
- package/include/napi-inl.deprecated.h +186 -0
- package/include/napi-inl.h +6299 -0
- package/include/napi.h +3127 -0
- package/include/node_api.h +226 -0
- package/include/node_api_types.h +56 -0
- package/include/uv/threadpool.h +41 -0
- package/include/uv/unix.h +21 -0
- package/include/uv.h +134 -0
- package/index.d.ts +4 -0
- package/index.js +22 -0
- package/lib/wasm32/libdlmalloc.a +0 -0
- package/lib/wasm32/libemmalloc.a +0 -0
- package/lib/wasm32/libemnapi.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 +5 -0
- package/lib/wasm32-wasi/libemnapi.a +0 -0
- package/lib/wasm32-wasi.txt +4 -0
- package/lib/wasm32.txt +4 -0
- package/package.json +43 -0
- package/src/emnapi.c +1344 -0
- package/src/malloc/dlmalloc/dlmalloc.c +92 -0
- package/src/malloc/dlmalloc/malloc.c +6395 -0
- package/src/malloc/emmalloc/emmalloc.c +1551 -0
- package/src/malloc/memcpy.c +136 -0
- package/src/malloc/memset.c +98 -0
- package/src/malloc/sbrk.c +29 -0
- package/src/uv/queue.h +108 -0
- package/src/uv/threadpool.c +408 -0
- package/src/uv/unix/async.c +206 -0
- package/src/uv/unix/core.c +35 -0
- package/src/uv/unix/loop.c +36 -0
- package/src/uv/unix/thread.c +118 -0
- package/src/uv/uv-common.c +51 -0
- package/src/uv/uv-common.h +68 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#ifndef SRC_JS_NATIVE_API_TYPES_H_
|
|
2
|
+
#define SRC_JS_NATIVE_API_TYPES_H_
|
|
3
|
+
|
|
4
|
+
// This file needs to be compatible with C compilers.
|
|
5
|
+
// This is a public include file, and these includes have essentially
|
|
6
|
+
// became part of it's API.
|
|
7
|
+
#include <stddef.h> // NOLINT(modernize-deprecated-headers)
|
|
8
|
+
#include <stdint.h> // NOLINT(modernize-deprecated-headers)
|
|
9
|
+
|
|
10
|
+
#if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900)
|
|
11
|
+
typedef uint16_t char16_t;
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
// JSVM API types are all opaque pointers for ABI stability
|
|
15
|
+
// typedef undefined structs instead of void* for compile time type safety
|
|
16
|
+
typedef struct napi_env__* napi_env;
|
|
17
|
+
typedef struct napi_value__* napi_value;
|
|
18
|
+
typedef struct napi_ref__* napi_ref;
|
|
19
|
+
typedef struct napi_handle_scope__* napi_handle_scope;
|
|
20
|
+
typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
|
|
21
|
+
typedef struct napi_callback_info__* napi_callback_info;
|
|
22
|
+
typedef struct napi_deferred__* napi_deferred;
|
|
23
|
+
|
|
24
|
+
typedef enum {
|
|
25
|
+
napi_default = 0,
|
|
26
|
+
napi_writable = 1 << 0,
|
|
27
|
+
napi_enumerable = 1 << 1,
|
|
28
|
+
napi_configurable = 1 << 2,
|
|
29
|
+
|
|
30
|
+
// Used with napi_define_class to distinguish static properties
|
|
31
|
+
// from instance properties. Ignored by napi_define_properties.
|
|
32
|
+
napi_static = 1 << 10,
|
|
33
|
+
|
|
34
|
+
#if NAPI_VERSION >= 8
|
|
35
|
+
// Default for class methods.
|
|
36
|
+
napi_default_method = napi_writable | napi_configurable,
|
|
37
|
+
|
|
38
|
+
// Default for object properties, like in JS obj[prop].
|
|
39
|
+
napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable,
|
|
40
|
+
#endif // NAPI_VERSION >= 8
|
|
41
|
+
} napi_property_attributes;
|
|
42
|
+
|
|
43
|
+
typedef enum {
|
|
44
|
+
// ES6 types (corresponds to typeof)
|
|
45
|
+
napi_undefined,
|
|
46
|
+
napi_null,
|
|
47
|
+
napi_boolean,
|
|
48
|
+
napi_number,
|
|
49
|
+
napi_string,
|
|
50
|
+
napi_symbol,
|
|
51
|
+
napi_object,
|
|
52
|
+
napi_function,
|
|
53
|
+
napi_external,
|
|
54
|
+
napi_bigint,
|
|
55
|
+
} napi_valuetype;
|
|
56
|
+
|
|
57
|
+
typedef enum {
|
|
58
|
+
napi_int8_array,
|
|
59
|
+
napi_uint8_array,
|
|
60
|
+
napi_uint8_clamped_array,
|
|
61
|
+
napi_int16_array,
|
|
62
|
+
napi_uint16_array,
|
|
63
|
+
napi_int32_array,
|
|
64
|
+
napi_uint32_array,
|
|
65
|
+
napi_float32_array,
|
|
66
|
+
napi_float64_array,
|
|
67
|
+
napi_bigint64_array,
|
|
68
|
+
napi_biguint64_array,
|
|
69
|
+
} napi_typedarray_type;
|
|
70
|
+
|
|
71
|
+
typedef enum {
|
|
72
|
+
napi_ok,
|
|
73
|
+
napi_invalid_arg,
|
|
74
|
+
napi_object_expected,
|
|
75
|
+
napi_string_expected,
|
|
76
|
+
napi_name_expected,
|
|
77
|
+
napi_function_expected,
|
|
78
|
+
napi_number_expected,
|
|
79
|
+
napi_boolean_expected,
|
|
80
|
+
napi_array_expected,
|
|
81
|
+
napi_generic_failure,
|
|
82
|
+
napi_pending_exception,
|
|
83
|
+
napi_cancelled,
|
|
84
|
+
napi_escape_called_twice,
|
|
85
|
+
napi_handle_scope_mismatch,
|
|
86
|
+
napi_callback_scope_mismatch,
|
|
87
|
+
napi_queue_full,
|
|
88
|
+
napi_closing,
|
|
89
|
+
napi_bigint_expected,
|
|
90
|
+
napi_date_expected,
|
|
91
|
+
napi_arraybuffer_expected,
|
|
92
|
+
napi_detachable_arraybuffer_expected,
|
|
93
|
+
napi_would_deadlock, // unused
|
|
94
|
+
napi_no_external_buffers_allowed
|
|
95
|
+
} napi_status;
|
|
96
|
+
// Note: when adding a new enum value to `napi_status`, please also update
|
|
97
|
+
// * `const int last_status` in the definition of `napi_get_last_error_info()'
|
|
98
|
+
// in file js_native_api_v8.cc.
|
|
99
|
+
// * `const char* error_messages[]` in file js_native_api_v8.cc with a brief
|
|
100
|
+
// message explaining the error.
|
|
101
|
+
// * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
|
|
102
|
+
// added value(s).
|
|
103
|
+
|
|
104
|
+
typedef napi_value (*napi_callback)(napi_env env,
|
|
105
|
+
napi_callback_info info);
|
|
106
|
+
typedef void (*napi_finalize)(napi_env env,
|
|
107
|
+
void* finalize_data,
|
|
108
|
+
void* finalize_hint);
|
|
109
|
+
|
|
110
|
+
typedef struct {
|
|
111
|
+
// One of utf8name or name should be NULL.
|
|
112
|
+
const char* utf8name;
|
|
113
|
+
napi_value name;
|
|
114
|
+
|
|
115
|
+
napi_callback method;
|
|
116
|
+
napi_callback getter;
|
|
117
|
+
napi_callback setter;
|
|
118
|
+
napi_value value;
|
|
119
|
+
|
|
120
|
+
napi_property_attributes attributes;
|
|
121
|
+
void* data;
|
|
122
|
+
} napi_property_descriptor;
|
|
123
|
+
|
|
124
|
+
typedef struct {
|
|
125
|
+
const char* error_message;
|
|
126
|
+
void* engine_reserved;
|
|
127
|
+
uint32_t engine_error_code;
|
|
128
|
+
napi_status error_code;
|
|
129
|
+
} napi_extended_error_info;
|
|
130
|
+
|
|
131
|
+
#if NAPI_VERSION >= 6
|
|
132
|
+
typedef enum {
|
|
133
|
+
napi_key_include_prototypes,
|
|
134
|
+
napi_key_own_only
|
|
135
|
+
} napi_key_collection_mode;
|
|
136
|
+
|
|
137
|
+
typedef enum {
|
|
138
|
+
napi_key_all_properties = 0,
|
|
139
|
+
napi_key_writable = 1,
|
|
140
|
+
napi_key_enumerable = 1 << 1,
|
|
141
|
+
napi_key_configurable = 1 << 2,
|
|
142
|
+
napi_key_skip_strings = 1 << 3,
|
|
143
|
+
napi_key_skip_symbols = 1 << 4
|
|
144
|
+
} napi_key_filter;
|
|
145
|
+
|
|
146
|
+
typedef enum {
|
|
147
|
+
napi_key_keep_numbers,
|
|
148
|
+
napi_key_numbers_to_strings
|
|
149
|
+
} napi_key_conversion;
|
|
150
|
+
#endif // NAPI_VERSION >= 6
|
|
151
|
+
|
|
152
|
+
#if NAPI_VERSION >= 8
|
|
153
|
+
typedef struct {
|
|
154
|
+
uint64_t lower;
|
|
155
|
+
uint64_t upper;
|
|
156
|
+
} napi_type_tag;
|
|
157
|
+
#endif // NAPI_VERSION >= 8
|
|
158
|
+
|
|
159
|
+
#endif // SRC_JS_NATIVE_API_TYPES_H_
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#ifndef SRC_NAPI_INL_DEPRECATED_H_
|
|
2
|
+
#define SRC_NAPI_INL_DEPRECATED_H_
|
|
3
|
+
|
|
4
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
// PropertyDescriptor class
|
|
6
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
7
|
+
|
|
8
|
+
template <typename Getter>
|
|
9
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
10
|
+
const char* utf8name,
|
|
11
|
+
Getter getter,
|
|
12
|
+
napi_property_attributes attributes,
|
|
13
|
+
void* /*data*/) {
|
|
14
|
+
using CbData = details::CallbackData<Getter, Napi::Value>;
|
|
15
|
+
// TODO: Delete when the function is destroyed
|
|
16
|
+
auto callbackData = new CbData({getter, nullptr});
|
|
17
|
+
|
|
18
|
+
return PropertyDescriptor({utf8name,
|
|
19
|
+
nullptr,
|
|
20
|
+
nullptr,
|
|
21
|
+
CbData::Wrapper,
|
|
22
|
+
nullptr,
|
|
23
|
+
nullptr,
|
|
24
|
+
attributes,
|
|
25
|
+
callbackData});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
template <typename Getter>
|
|
29
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
30
|
+
const std::string& utf8name,
|
|
31
|
+
Getter getter,
|
|
32
|
+
napi_property_attributes attributes,
|
|
33
|
+
void* data) {
|
|
34
|
+
return Accessor(utf8name.c_str(), getter, attributes, data);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
template <typename Getter>
|
|
38
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
39
|
+
napi_value name,
|
|
40
|
+
Getter getter,
|
|
41
|
+
napi_property_attributes attributes,
|
|
42
|
+
void* /*data*/) {
|
|
43
|
+
using CbData = details::CallbackData<Getter, Napi::Value>;
|
|
44
|
+
// TODO: Delete when the function is destroyed
|
|
45
|
+
auto callbackData = new CbData({getter, nullptr});
|
|
46
|
+
|
|
47
|
+
return PropertyDescriptor({nullptr,
|
|
48
|
+
name,
|
|
49
|
+
nullptr,
|
|
50
|
+
CbData::Wrapper,
|
|
51
|
+
nullptr,
|
|
52
|
+
nullptr,
|
|
53
|
+
attributes,
|
|
54
|
+
callbackData});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
template <typename Getter>
|
|
58
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
59
|
+
Name name, Getter getter, napi_property_attributes attributes, void* data) {
|
|
60
|
+
napi_value nameValue = name;
|
|
61
|
+
return PropertyDescriptor::Accessor(nameValue, getter, attributes, data);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
template <typename Getter, typename Setter>
|
|
65
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
66
|
+
const char* utf8name,
|
|
67
|
+
Getter getter,
|
|
68
|
+
Setter setter,
|
|
69
|
+
napi_property_attributes attributes,
|
|
70
|
+
void* /*data*/) {
|
|
71
|
+
using CbData = details::AccessorCallbackData<Getter, Setter>;
|
|
72
|
+
// TODO: Delete when the function is destroyed
|
|
73
|
+
auto callbackData = new CbData({getter, setter, nullptr});
|
|
74
|
+
|
|
75
|
+
return PropertyDescriptor({utf8name,
|
|
76
|
+
nullptr,
|
|
77
|
+
nullptr,
|
|
78
|
+
CbData::GetterWrapper,
|
|
79
|
+
CbData::SetterWrapper,
|
|
80
|
+
nullptr,
|
|
81
|
+
attributes,
|
|
82
|
+
callbackData});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
template <typename Getter, typename Setter>
|
|
86
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
87
|
+
const std::string& utf8name,
|
|
88
|
+
Getter getter,
|
|
89
|
+
Setter setter,
|
|
90
|
+
napi_property_attributes attributes,
|
|
91
|
+
void* data) {
|
|
92
|
+
return Accessor(utf8name.c_str(), getter, setter, attributes, data);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
template <typename Getter, typename Setter>
|
|
96
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
97
|
+
napi_value name,
|
|
98
|
+
Getter getter,
|
|
99
|
+
Setter setter,
|
|
100
|
+
napi_property_attributes attributes,
|
|
101
|
+
void* /*data*/) {
|
|
102
|
+
using CbData = details::AccessorCallbackData<Getter, Setter>;
|
|
103
|
+
// TODO: Delete when the function is destroyed
|
|
104
|
+
auto callbackData = new CbData({getter, setter, nullptr});
|
|
105
|
+
|
|
106
|
+
return PropertyDescriptor({nullptr,
|
|
107
|
+
name,
|
|
108
|
+
nullptr,
|
|
109
|
+
CbData::GetterWrapper,
|
|
110
|
+
CbData::SetterWrapper,
|
|
111
|
+
nullptr,
|
|
112
|
+
attributes,
|
|
113
|
+
callbackData});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
template <typename Getter, typename Setter>
|
|
117
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
118
|
+
Name name,
|
|
119
|
+
Getter getter,
|
|
120
|
+
Setter setter,
|
|
121
|
+
napi_property_attributes attributes,
|
|
122
|
+
void* data) {
|
|
123
|
+
napi_value nameValue = name;
|
|
124
|
+
return PropertyDescriptor::Accessor(
|
|
125
|
+
nameValue, getter, setter, attributes, data);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
template <typename Callable>
|
|
129
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
130
|
+
const char* utf8name,
|
|
131
|
+
Callable cb,
|
|
132
|
+
napi_property_attributes attributes,
|
|
133
|
+
void* /*data*/) {
|
|
134
|
+
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
|
|
135
|
+
using CbData = details::CallbackData<Callable, ReturnType>;
|
|
136
|
+
// TODO: Delete when the function is destroyed
|
|
137
|
+
auto callbackData = new CbData({cb, nullptr});
|
|
138
|
+
|
|
139
|
+
return PropertyDescriptor({utf8name,
|
|
140
|
+
nullptr,
|
|
141
|
+
CbData::Wrapper,
|
|
142
|
+
nullptr,
|
|
143
|
+
nullptr,
|
|
144
|
+
nullptr,
|
|
145
|
+
attributes,
|
|
146
|
+
callbackData});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
template <typename Callable>
|
|
150
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
151
|
+
const std::string& utf8name,
|
|
152
|
+
Callable cb,
|
|
153
|
+
napi_property_attributes attributes,
|
|
154
|
+
void* data) {
|
|
155
|
+
return Function(utf8name.c_str(), cb, attributes, data);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
template <typename Callable>
|
|
159
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
160
|
+
napi_value name,
|
|
161
|
+
Callable cb,
|
|
162
|
+
napi_property_attributes attributes,
|
|
163
|
+
void* /*data*/) {
|
|
164
|
+
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
|
|
165
|
+
using CbData = details::CallbackData<Callable, ReturnType>;
|
|
166
|
+
// TODO: Delete when the function is destroyed
|
|
167
|
+
auto callbackData = new CbData({cb, nullptr});
|
|
168
|
+
|
|
169
|
+
return PropertyDescriptor({nullptr,
|
|
170
|
+
name,
|
|
171
|
+
CbData::Wrapper,
|
|
172
|
+
nullptr,
|
|
173
|
+
nullptr,
|
|
174
|
+
nullptr,
|
|
175
|
+
attributes,
|
|
176
|
+
callbackData});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
template <typename Callable>
|
|
180
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
181
|
+
Name name, Callable cb, napi_property_attributes attributes, void* data) {
|
|
182
|
+
napi_value nameValue = name;
|
|
183
|
+
return PropertyDescriptor::Function(nameValue, cb, attributes, data);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#endif // !SRC_NAPI_INL_DEPRECATED_H_
|