emnapi 1.6.0 → 1.7.1
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 +84 -30
- package/include/node/emnapi.h +2 -2
- package/include/node/js_native_api.h +11 -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) {
|
|
@@ -3071,6 +3071,55 @@ function _napi_create_object(env, result) {
|
|
|
3071
3071
|
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
3072
3072
|
return envObject.clearLastError();
|
|
3073
3073
|
}
|
|
3074
|
+
/**
|
|
3075
|
+
* @__sig ipppppp
|
|
3076
|
+
*/
|
|
3077
|
+
function _napi_create_object_with_properties(env, prototype_or_null, property_names, property_values, property_count, result) {
|
|
3078
|
+
if (!env)
|
|
3079
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
3080
|
+
// @ts-expect-error
|
|
3081
|
+
var envObject = emnapiCtx.envStore.get(env);
|
|
3082
|
+
envObject.checkGCAccess();
|
|
3083
|
+
if (!result)
|
|
3084
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
3085
|
+
{{{ from64('property_count') }}};
|
|
3086
|
+
property_count = property_count >>> 0;
|
|
3087
|
+
if (property_count > 0) {
|
|
3088
|
+
if (!property_names)
|
|
3089
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
3090
|
+
if (!property_values)
|
|
3091
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
3092
|
+
}
|
|
3093
|
+
var v8_prototype_or_null = prototype_or_null
|
|
3094
|
+
? emnapiCtx.handleStore.get(prototype_or_null).value
|
|
3095
|
+
: null;
|
|
3096
|
+
var properties = {};
|
|
3097
|
+
{{{ from64('property_names') }}};
|
|
3098
|
+
{{{ from64('property_values') }}};
|
|
3099
|
+
for (var i = 0; i < property_count; i++) {
|
|
3100
|
+
var name_value = emnapiCtx.handleStore.get({{{ makeGetValue('property_names', 'i * ' + POINTER_SIZE, '*') }}}).value;
|
|
3101
|
+
if (!(typeof name_value === "string" || typeof name_value === "symbol"))
|
|
3102
|
+
return envObject.setLastError(4 /* napi_status.napi_name_expected */);
|
|
3103
|
+
properties[name_value] = {
|
|
3104
|
+
value: emnapiCtx.handleStore.get({{{ makeGetValue('property_values', 'i * ' + POINTER_SIZE, '*') }}}).value,
|
|
3105
|
+
writable: true,
|
|
3106
|
+
enumerable: true,
|
|
3107
|
+
configurable: true
|
|
3108
|
+
};
|
|
3109
|
+
}
|
|
3110
|
+
var obj;
|
|
3111
|
+
try {
|
|
3112
|
+
obj = Object.defineProperties(Object.create(v8_prototype_or_null), properties);
|
|
3113
|
+
}
|
|
3114
|
+
catch (_) {
|
|
3115
|
+
return envObject.setLastError(9 /* napi_status.napi_generic_failure */);
|
|
3116
|
+
}
|
|
3117
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3118
|
+
var value = emnapiCtx.addToCurrentScope(obj).id;
|
|
3119
|
+
{{{ from64('result') }}};
|
|
3120
|
+
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
3121
|
+
return envObject.clearLastError();
|
|
3122
|
+
}
|
|
3074
3123
|
/**
|
|
3075
3124
|
* @__sig ippp
|
|
3076
3125
|
*/
|
|
@@ -3367,8 +3416,6 @@ function _node_api_create_buffer_from_arraybuffer(env, arraybuffer, byte_offset,
|
|
|
3367
3416
|
* @__sig ippppp
|
|
3368
3417
|
*/
|
|
3369
3418
|
function _napi_create_dataview(env, byte_length, arraybuffer, byte_offset, result) {
|
|
3370
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3371
|
-
var value;
|
|
3372
3419
|
if (!env)
|
|
3373
3420
|
return 1 /* napi_status.napi_invalid_arg */;
|
|
3374
3421
|
// @ts-expect-error
|
|
@@ -3388,33 +3435,37 @@ function _napi_create_dataview(env, byte_length, arraybuffer, byte_offset, resul
|
|
|
3388
3435
|
{{{ from64('byte_offset') }}};
|
|
3389
3436
|
byte_length = byte_length >>> 0;
|
|
3390
3437
|
byte_offset = byte_offset >>> 0;
|
|
3391
|
-
var
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
var err = new RangeError('byte_offset + byte_length should be less than or equal to the size in bytes of the array passed in');
|
|
3398
|
-
err.code = 'ERR_NAPI_INVALID_DATAVIEW_ARGS';
|
|
3399
|
-
throw err;
|
|
3400
|
-
}
|
|
3401
|
-
var dataview = new DataView(buffer, byte_offset, byte_length);
|
|
3402
|
-
if (buffer === wasmMemory.buffer) {
|
|
3403
|
-
if (!emnapiExternalMemory.wasmMemoryViewTable.has(dataview)) {
|
|
3404
|
-
emnapiExternalMemory.wasmMemoryViewTable.set(dataview, {
|
|
3405
|
-
Ctor: DataView,
|
|
3406
|
-
address: byte_offset,
|
|
3407
|
-
length: byte_length,
|
|
3408
|
-
ownership: 1 /* ReferenceOwnership.kUserland */,
|
|
3409
|
-
runtimeAllocated: 0
|
|
3410
|
-
});
|
|
3438
|
+
var value = emnapiCtx.handleStore.get(arraybuffer).value;
|
|
3439
|
+
var createDataview = function (buffer) {
|
|
3440
|
+
if ((byte_length + byte_offset) > buffer.byteLength) {
|
|
3441
|
+
var err = new RangeError('byte_offset + byte_length should be less than or equal to the size in bytes of the array passed in');
|
|
3442
|
+
err.code = 'ERR_NAPI_INVALID_DATAVIEW_ARGS';
|
|
3443
|
+
throw err;
|
|
3411
3444
|
}
|
|
3445
|
+
var dataview = new DataView(buffer, byte_offset, byte_length);
|
|
3446
|
+
if (buffer === wasmMemory.buffer) {
|
|
3447
|
+
if (!emnapiExternalMemory.wasmMemoryViewTable.has(dataview)) {
|
|
3448
|
+
emnapiExternalMemory.wasmMemoryViewTable.set(dataview, {
|
|
3449
|
+
Ctor: DataView,
|
|
3450
|
+
address: byte_offset,
|
|
3451
|
+
length: byte_length,
|
|
3452
|
+
ownership: 1 /* ReferenceOwnership.kUserland */,
|
|
3453
|
+
runtimeAllocated: 0
|
|
3454
|
+
});
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
{{{ from64('result') }}};
|
|
3458
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3459
|
+
var v = emnapiCtx.addToCurrentScope(dataview).id;
|
|
3460
|
+
{{{ makeSetValue('result', 0, 'v', '*') }}};
|
|
3461
|
+
return envObject.getReturnStatus();
|
|
3462
|
+
};
|
|
3463
|
+
if (value instanceof ArrayBuffer || emnapiExternalMemory.isSharedArrayBuffer(value)) {
|
|
3464
|
+
return createDataview(value);
|
|
3465
|
+
}
|
|
3466
|
+
else {
|
|
3467
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
3412
3468
|
}
|
|
3413
|
-
{{{ from64('result') }}};
|
|
3414
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3415
|
-
value = emnapiCtx.addToCurrentScope(dataview).id;
|
|
3416
|
-
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
3417
|
-
return envObject.getReturnStatus();
|
|
3418
3469
|
}
|
|
3419
3470
|
catch (err) {
|
|
3420
3471
|
envObject.tryCatch.setError(err);
|
|
@@ -6955,6 +7006,9 @@ function _napi_get_version(env, result) {
|
|
|
6955
7006
|
napi_create_object: _napi_create_object,
|
|
6956
7007
|
napi_create_object__deps: ["$emnapiCtx"],
|
|
6957
7008
|
napi_create_object__sig: "ipp",
|
|
7009
|
+
napi_create_object_with_properties: _napi_create_object_with_properties,
|
|
7010
|
+
napi_create_object_with_properties__deps: ["$emnapiCtx"],
|
|
7011
|
+
napi_create_object_with_properties__sig: "ipppppp",
|
|
6958
7012
|
napi_create_promise: _napi_create_promise,
|
|
6959
7013
|
napi_create_promise__deps: ["$emnapiCtx"],
|
|
6960
7014
|
napi_create_promise__sig: "ippp",
|
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")))
|
|
@@ -72,6 +56,17 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_boolean(napi_env env,
|
|
|
72
56
|
// Methods to create Primitive types/Objects
|
|
73
57
|
NAPI_EXTERN napi_status NAPI_CDECL napi_create_object(napi_env env,
|
|
74
58
|
napi_value* result);
|
|
59
|
+
#ifdef NAPI_EXPERIMENTAL
|
|
60
|
+
#define NODE_API_EXPERIMENTAL_HAS_CREATE_OBJECT_WITH_PROPERTIES
|
|
61
|
+
NAPI_EXTERN napi_status NAPI_CDECL
|
|
62
|
+
napi_create_object_with_properties(napi_env env,
|
|
63
|
+
napi_value prototype_or_null,
|
|
64
|
+
napi_value* property_names,
|
|
65
|
+
napi_value* property_values,
|
|
66
|
+
size_t property_count,
|
|
67
|
+
napi_value* result);
|
|
68
|
+
#endif // NAPI_EXPERIMENTAL
|
|
69
|
+
|
|
75
70
|
NAPI_EXTERN napi_status NAPI_CDECL napi_create_array(napi_env env,
|
|
76
71
|
napi_value* result);
|
|
77
72
|
NAPI_EXTERN napi_status NAPI_CDECL
|
|
@@ -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;
|