emnapi 1.7.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 +32 -30
- package/include/node/emnapi.h +1 -1
- package/include/node/js_native_api.h +0 -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) {
|
|
@@ -3416,8 +3416,6 @@ function _node_api_create_buffer_from_arraybuffer(env, arraybuffer, byte_offset,
|
|
|
3416
3416
|
* @__sig ippppp
|
|
3417
3417
|
*/
|
|
3418
3418
|
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
3419
|
if (!env)
|
|
3422
3420
|
return 1 /* napi_status.napi_invalid_arg */;
|
|
3423
3421
|
// @ts-expect-error
|
|
@@ -3437,33 +3435,37 @@ function _napi_create_dataview(env, byte_length, arraybuffer, byte_offset, resul
|
|
|
3437
3435
|
{{{ from64('byte_offset') }}};
|
|
3438
3436
|
byte_length = byte_length >>> 0;
|
|
3439
3437
|
byte_offset = byte_offset >>> 0;
|
|
3440
|
-
var
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
runtimeAllocated: 0
|
|
3459
|
-
});
|
|
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;
|
|
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
|
+
}
|
|
3460
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 */);
|
|
3461
3468
|
}
|
|
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
3469
|
}
|
|
3468
3470
|
catch (err) {
|
|
3469
3471
|
envObject.tryCatch.setError(err);
|
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")))
|
|
@@ -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;
|