emnapi 1.7.0 → 1.8.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 +9 -0
- package/dist/library_napi.js +73 -30
- package/include/node/emnapi.h +1 -1
- package/include/node/js_native_api.h +6 -16
- package/include/node/js_native_api_types.h +28 -0
- package/include/node/node_api.h +0 -4
- package/include/node/node_api_types.h +4 -0
- package/package.json +1 -1
package/CMakeLists.txt
CHANGED
|
@@ -134,6 +134,15 @@ endif()
|
|
|
134
134
|
if(NAPI_VERSION)
|
|
135
135
|
add_compile_definitions("NAPI_VERSION=${NAPI_VERSION}")
|
|
136
136
|
endif()
|
|
137
|
+
if(NAPI_EXPERIMENTAL)
|
|
138
|
+
add_compile_definitions("NAPI_EXPERIMENTAL=${NAPI_EXPERIMENTAL}")
|
|
139
|
+
endif()
|
|
140
|
+
if(NODE_API_EXPERIMENTAL_NO_WARNING)
|
|
141
|
+
add_compile_definitions("NODE_API_EXPERIMENTAL_NO_WARNING=${NODE_API_EXPERIMENTAL_NO_WARNING}")
|
|
142
|
+
endif()
|
|
143
|
+
if(NODE_WANT_INTERNALS)
|
|
144
|
+
add_compile_definitions("NODE_WANT_INTERNALS=${NODE_WANT_INTERNALS}")
|
|
145
|
+
endif()
|
|
137
146
|
|
|
138
147
|
add_library(${EMNAPI_TARGET_NAME} STATIC ${EMNAPI_SRC} ${UV_SRC})
|
|
139
148
|
target_include_directories(${EMNAPI_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
|
package/dist/library_napi.js
CHANGED
|
@@ -53,11 +53,11 @@ function emnapiInit(options) {
|
|
|
53
53
|
var scope = emnapiCtx.openScope(envObject);
|
|
54
54
|
try {
|
|
55
55
|
envObject.callIntoModule(function (_envObject) {
|
|
56
|
-
var exports = emnapiModule.exports;
|
|
56
|
+
var exports$1 = emnapiModule.exports;
|
|
57
57
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
|
-
var exportsHandle = scope.add(exports);
|
|
58
|
+
var exportsHandle = scope.add(exports$1);
|
|
59
59
|
var napiValue = _napi_register_wasm_v1({{{ to64('_envObject.id') }}}, {{{ to64('exportsHandle.id') }}});
|
|
60
|
-
emnapiModule.exports = (!napiValue) ? exports : emnapiCtx.handleStore.get(napiValue).value;
|
|
60
|
+
emnapiModule.exports = (!napiValue) ? exports$1 : emnapiCtx.handleStore.get(napiValue).value;
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
catch (err) {
|
|
@@ -1143,6 +1143,44 @@ function _napi_get_arraybuffer_info(env, arraybuffer, data, byte_length) {
|
|
|
1143
1143
|
}
|
|
1144
1144
|
return envObject.clearLastError();
|
|
1145
1145
|
}
|
|
1146
|
+
/**
|
|
1147
|
+
* @__sig ippp
|
|
1148
|
+
*/
|
|
1149
|
+
function _node_api_set_prototype(env, object, value) {
|
|
1150
|
+
if (!env)
|
|
1151
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
1152
|
+
// @ts-expect-error
|
|
1153
|
+
var envObject = emnapiCtx.envStore.get(env);
|
|
1154
|
+
envObject.checkGCAccess();
|
|
1155
|
+
if (!envObject.tryCatch.isEmpty())
|
|
1156
|
+
return envObject.setLastError(10 /* napi_status.napi_pending_exception */);
|
|
1157
|
+
if (!envObject.canCallIntoJs())
|
|
1158
|
+
return envObject.setLastError(envObject.moduleApiVersion >= 10 ? 23 /* napi_status.napi_cannot_run_js */ : 10 /* napi_status.napi_pending_exception */);
|
|
1159
|
+
envObject.clearLastError();
|
|
1160
|
+
try {
|
|
1161
|
+
if (!value)
|
|
1162
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
1163
|
+
var obj = emnapiCtx.handleStore.get(object).value;
|
|
1164
|
+
if (obj == null) {
|
|
1165
|
+
throw new TypeError('Cannot convert undefined or null to object');
|
|
1166
|
+
}
|
|
1167
|
+
var type = typeof obj;
|
|
1168
|
+
var v = void 0;
|
|
1169
|
+
try {
|
|
1170
|
+
v = (type === 'object' && obj !== null) || type === 'function' ? obj : Object(obj);
|
|
1171
|
+
}
|
|
1172
|
+
catch (_) {
|
|
1173
|
+
return envObject.setLastError(2 /* napi_status.napi_object_expected */);
|
|
1174
|
+
}
|
|
1175
|
+
var val = emnapiCtx.handleStore.get(value).value;
|
|
1176
|
+
Object.setPrototypeOf(v, val);
|
|
1177
|
+
return envObject.getReturnStatus();
|
|
1178
|
+
}
|
|
1179
|
+
catch (err) {
|
|
1180
|
+
envObject.tryCatch.setError(err);
|
|
1181
|
+
return envObject.setLastError(10 /* napi_status.napi_pending_exception */);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1146
1184
|
/**
|
|
1147
1185
|
* @__sig ippp
|
|
1148
1186
|
*/
|
|
@@ -3416,8 +3454,6 @@ function _node_api_create_buffer_from_arraybuffer(env, arraybuffer, byte_offset,
|
|
|
3416
3454
|
* @__sig ippppp
|
|
3417
3455
|
*/
|
|
3418
3456
|
function _napi_create_dataview(env, byte_length, arraybuffer, byte_offset, result) {
|
|
3419
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3420
|
-
var value;
|
|
3421
3457
|
if (!env)
|
|
3422
3458
|
return 1 /* napi_status.napi_invalid_arg */;
|
|
3423
3459
|
// @ts-expect-error
|
|
@@ -3437,33 +3473,37 @@ function _napi_create_dataview(env, byte_length, arraybuffer, byte_offset, resul
|
|
|
3437
3473
|
{{{ from64('byte_offset') }}};
|
|
3438
3474
|
byte_length = byte_length >>> 0;
|
|
3439
3475
|
byte_offset = byte_offset >>> 0;
|
|
3440
|
-
var
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
var err = new RangeError('byte_offset + byte_length should be less than or equal to the size in bytes of the array passed in');
|
|
3447
|
-
err.code = 'ERR_NAPI_INVALID_DATAVIEW_ARGS';
|
|
3448
|
-
throw err;
|
|
3449
|
-
}
|
|
3450
|
-
var dataview = new DataView(buffer, byte_offset, byte_length);
|
|
3451
|
-
if (buffer === wasmMemory.buffer) {
|
|
3452
|
-
if (!emnapiExternalMemory.wasmMemoryViewTable.has(dataview)) {
|
|
3453
|
-
emnapiExternalMemory.wasmMemoryViewTable.set(dataview, {
|
|
3454
|
-
Ctor: DataView,
|
|
3455
|
-
address: byte_offset,
|
|
3456
|
-
length: byte_length,
|
|
3457
|
-
ownership: 1 /* ReferenceOwnership.kUserland */,
|
|
3458
|
-
runtimeAllocated: 0
|
|
3459
|
-
});
|
|
3476
|
+
var value = emnapiCtx.handleStore.get(arraybuffer).value;
|
|
3477
|
+
var createDataview = function (buffer) {
|
|
3478
|
+
if ((byte_length + byte_offset) > buffer.byteLength) {
|
|
3479
|
+
var err = new RangeError('byte_offset + byte_length should be less than or equal to the size in bytes of the array passed in');
|
|
3480
|
+
err.code = 'ERR_NAPI_INVALID_DATAVIEW_ARGS';
|
|
3481
|
+
throw err;
|
|
3460
3482
|
}
|
|
3483
|
+
var dataview = new DataView(buffer, byte_offset, byte_length);
|
|
3484
|
+
if (buffer === wasmMemory.buffer) {
|
|
3485
|
+
if (!emnapiExternalMemory.wasmMemoryViewTable.has(dataview)) {
|
|
3486
|
+
emnapiExternalMemory.wasmMemoryViewTable.set(dataview, {
|
|
3487
|
+
Ctor: DataView,
|
|
3488
|
+
address: byte_offset,
|
|
3489
|
+
length: byte_length,
|
|
3490
|
+
ownership: 1 /* ReferenceOwnership.kUserland */,
|
|
3491
|
+
runtimeAllocated: 0
|
|
3492
|
+
});
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
{{{ from64('result') }}};
|
|
3496
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3497
|
+
var v = emnapiCtx.addToCurrentScope(dataview).id;
|
|
3498
|
+
{{{ makeSetValue('result', 0, 'v', '*') }}};
|
|
3499
|
+
return envObject.getReturnStatus();
|
|
3500
|
+
};
|
|
3501
|
+
if (value instanceof ArrayBuffer || emnapiExternalMemory.isSharedArrayBuffer(value)) {
|
|
3502
|
+
return createDataview(value);
|
|
3503
|
+
}
|
|
3504
|
+
else {
|
|
3505
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
3461
3506
|
}
|
|
3462
|
-
{{{ from64('result') }}};
|
|
3463
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3464
|
-
value = emnapiCtx.addToCurrentScope(dataview).id;
|
|
3465
|
-
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
3466
|
-
return envObject.getReturnStatus();
|
|
3467
3507
|
}
|
|
3468
3508
|
catch (err) {
|
|
3469
3509
|
envObject.tryCatch.setError(err);
|
|
@@ -7351,6 +7391,9 @@ function _napi_get_version(env, result) {
|
|
|
7351
7391
|
node_api_post_finalizer: _node_api_post_finalizer,
|
|
7352
7392
|
node_api_post_finalizer__deps: ["$emnapiCtx"],
|
|
7353
7393
|
node_api_post_finalizer__sig: "ipppp",
|
|
7394
|
+
node_api_set_prototype: _node_api_set_prototype,
|
|
7395
|
+
node_api_set_prototype__deps: ["$emnapiCtx"],
|
|
7396
|
+
node_api_set_prototype__sig: "ippp",
|
|
7354
7397
|
node_api_symbol_for: _node_api_symbol_for,
|
|
7355
7398
|
node_api_symbol_for__deps: ["$emnapiCtx", "$emnapiString"],
|
|
7356
7399
|
node_api_symbol_for__sig: "ipppp",
|
package/include/node/emnapi.h
CHANGED
|
@@ -5,22 +5,6 @@
|
|
|
5
5
|
#include <stdbool.h> // NOLINT(modernize-deprecated-headers)
|
|
6
6
|
#include <stddef.h> // NOLINT(modernize-deprecated-headers)
|
|
7
7
|
|
|
8
|
-
// Use INT_MAX, this should only be consumed by the pre-processor anyway.
|
|
9
|
-
#define NAPI_VERSION_EXPERIMENTAL 2147483647
|
|
10
|
-
#ifndef NAPI_VERSION
|
|
11
|
-
#ifdef NAPI_EXPERIMENTAL
|
|
12
|
-
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
|
|
13
|
-
#else
|
|
14
|
-
// The baseline version for N-API.
|
|
15
|
-
// The NAPI_VERSION controls which version will be used by default when
|
|
16
|
-
// compilling a native addon. If the addon developer specifically wants to use
|
|
17
|
-
// functions available in a new version of N-API that is not yet ported in all
|
|
18
|
-
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
|
|
19
|
-
// depended on that version.
|
|
20
|
-
#define NAPI_VERSION 8
|
|
21
|
-
#endif
|
|
22
|
-
#endif
|
|
23
|
-
|
|
24
8
|
#ifndef EMNAPI_UNMODIFIED_UPSTREAM
|
|
25
9
|
#if !defined(NAPI_EXTERN) && defined(__EMSCRIPTEN__)
|
|
26
10
|
#define NAPI_EXTERN __attribute__((__import_module__("env")))
|
|
@@ -219,6 +203,12 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_coerce_to_string(napi_env env,
|
|
|
219
203
|
napi_value* result);
|
|
220
204
|
|
|
221
205
|
// Methods to work with Objects
|
|
206
|
+
#ifdef NAPI_EXPERIMENTAL
|
|
207
|
+
#define NODE_API_EXPERIMENTAL_HAS_SET_PROTOTYPE
|
|
208
|
+
NAPI_EXTERN napi_status NAPI_CDECL node_api_set_prototype(napi_env env,
|
|
209
|
+
napi_value object,
|
|
210
|
+
napi_value value);
|
|
211
|
+
#endif
|
|
222
212
|
NAPI_EXTERN napi_status NAPI_CDECL napi_get_prototype(napi_env env,
|
|
223
213
|
napi_value object,
|
|
224
214
|
napi_value* result);
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
#ifndef SRC_JS_NATIVE_API_TYPES_H_
|
|
2
2
|
#define SRC_JS_NATIVE_API_TYPES_H_
|
|
3
3
|
|
|
4
|
+
// Use INT_MAX, this should only be consumed by the pre-processor anyway.
|
|
5
|
+
#define NAPI_VERSION_EXPERIMENTAL 2147483647
|
|
6
|
+
#ifndef NAPI_VERSION
|
|
7
|
+
#ifdef NAPI_EXPERIMENTAL
|
|
8
|
+
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
|
|
9
|
+
#else
|
|
10
|
+
// The baseline version for N-API.
|
|
11
|
+
// The NAPI_VERSION controls which version will be used by default when
|
|
12
|
+
// compilling a native addon. If the addon developer specifically wants to use
|
|
13
|
+
// functions available in a new version of N-API that is not yet ported in all
|
|
14
|
+
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
|
|
15
|
+
// depended on that version.
|
|
16
|
+
#define NAPI_VERSION 8
|
|
17
|
+
#endif
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#if defined(NAPI_EXPERIMENTAL) && \
|
|
21
|
+
!defined(NODE_API_EXPERIMENTAL_NO_WARNING) && \
|
|
22
|
+
!defined(NODE_WANT_INTERNALS)
|
|
23
|
+
#ifdef _MSC_VER
|
|
24
|
+
#pragma message("NAPI_EXPERIMENTAL is enabled. " \
|
|
25
|
+
"Experimental features may be unstable.")
|
|
26
|
+
#else
|
|
27
|
+
#warning "NAPI_EXPERIMENTAL is enabled. " \
|
|
28
|
+
"Experimental features may be unstable."
|
|
29
|
+
#endif
|
|
30
|
+
#endif
|
|
31
|
+
|
|
4
32
|
// This file needs to be compatible with C compilers.
|
|
5
33
|
// This is a public include file, and these includes have essentially
|
|
6
34
|
// became part of it's API.
|
package/include/node/node_api.h
CHANGED
|
@@ -43,10 +43,6 @@ struct uv_loop_s; // Forward declaration.
|
|
|
43
43
|
#define NAPI_NO_RETURN
|
|
44
44
|
#endif
|
|
45
45
|
|
|
46
|
-
typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
|
|
47
|
-
napi_value exports);
|
|
48
|
-
typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
|
|
49
|
-
|
|
50
46
|
// Used by deprecated registration method napi_module_register.
|
|
51
47
|
typedef struct napi_module {
|
|
52
48
|
int nm_version;
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
#include "js_native_api_types.h"
|
|
5
5
|
|
|
6
|
+
typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
|
|
7
|
+
napi_value exports);
|
|
8
|
+
typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
|
|
9
|
+
|
|
6
10
|
typedef struct napi_callback_scope__* napi_callback_scope;
|
|
7
11
|
typedef struct napi_async_context__* napi_async_context;
|
|
8
12
|
typedef struct napi_async_work__* napi_async_work;
|