@emnapi/runtime 0.41.0 → 0.42.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/dist/emnapi.cjs.js +58 -31
- package/dist/emnapi.cjs.min.d.ts +606 -0
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.mts +606 -0
- package/dist/emnapi.d.ts +15 -13
- package/dist/emnapi.esm-bundler.js +58 -32
- package/dist/emnapi.iife.d.ts +13 -12
- package/dist/emnapi.iife.js +65 -34
- package/dist/emnapi.js +65 -34
- package/dist/emnapi.min.d.mts +606 -0
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +57 -30
- package/package.json +11 -7
package/dist/emnapi.cjs.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
const EMPTY_ARGS = [];
|
|
1
2
|
class CallbackInfo {
|
|
2
|
-
constructor(parent, thiz, data, args, fn) {
|
|
3
|
+
constructor(id, parent, child, thiz, data, args, fn) {
|
|
4
|
+
this.id = id;
|
|
3
5
|
this.parent = parent;
|
|
6
|
+
this.child = child;
|
|
4
7
|
this.thiz = thiz;
|
|
5
8
|
this.data = data;
|
|
6
9
|
this.args = args;
|
|
@@ -12,21 +15,50 @@ class CallbackInfo {
|
|
|
12
15
|
return 0;
|
|
13
16
|
return thiz instanceof this.fn ? envObject.ensureHandleId(thiz.constructor) : 0;
|
|
14
17
|
}
|
|
18
|
+
dispose() {
|
|
19
|
+
if (this.thiz !== undefined)
|
|
20
|
+
this.thiz = undefined;
|
|
21
|
+
this.args = EMPTY_ARGS;
|
|
22
|
+
this.fn = null;
|
|
23
|
+
}
|
|
15
24
|
}
|
|
25
|
+
const ROOT_CBINFO = new CallbackInfo(0, null, null, null, 0, null, null);
|
|
16
26
|
class CallbackInfoStack {
|
|
17
27
|
constructor() {
|
|
18
|
-
this.current =
|
|
28
|
+
this.current = ROOT_CBINFO;
|
|
29
|
+
}
|
|
30
|
+
get(id) {
|
|
31
|
+
if (id === 1)
|
|
32
|
+
return ROOT_CBINFO.child;
|
|
33
|
+
let info = ROOT_CBINFO;
|
|
34
|
+
for (let i = 0; i < id; ++i) {
|
|
35
|
+
info = info.child;
|
|
36
|
+
if (info === null)
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return info === ROOT_CBINFO ? null : info;
|
|
19
40
|
}
|
|
20
41
|
pop() {
|
|
21
42
|
const current = this.current;
|
|
22
|
-
if (current ===
|
|
43
|
+
if (current === ROOT_CBINFO)
|
|
23
44
|
return;
|
|
24
45
|
this.current = current.parent;
|
|
46
|
+
current.dispose();
|
|
25
47
|
}
|
|
26
48
|
push(thiz, data, args, fn) {
|
|
27
|
-
|
|
49
|
+
let info = this.current.child;
|
|
50
|
+
if (info) {
|
|
51
|
+
info.thiz = thiz;
|
|
52
|
+
info.data = data;
|
|
53
|
+
info.args = args;
|
|
54
|
+
info.fn = fn;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
info = new CallbackInfo(this.current.id + 1, this.current, null, thiz, data, args, fn);
|
|
58
|
+
this.current.child = info;
|
|
59
|
+
}
|
|
28
60
|
this.current = info;
|
|
29
|
-
return info;
|
|
61
|
+
return info.id;
|
|
30
62
|
}
|
|
31
63
|
dispose() {
|
|
32
64
|
this.current = null;
|
|
@@ -167,8 +199,9 @@ const _Buffer = typeof Buffer === 'function'
|
|
|
167
199
|
catch (_) { }
|
|
168
200
|
return undefined;
|
|
169
201
|
})();
|
|
170
|
-
const version = "0.
|
|
171
|
-
const
|
|
202
|
+
const version = "0.42.0";
|
|
203
|
+
const NODE_API_SUPPORTED_VERSION_MIN = 1;
|
|
204
|
+
const NODE_API_SUPPORTED_VERSION_MAX = 9;
|
|
172
205
|
const NAPI_VERSION_EXPERIMENTAL = 2147483647;
|
|
173
206
|
const NODE_API_DEFAULT_MODULE_API_VERSION = 8;
|
|
174
207
|
|
|
@@ -526,7 +559,7 @@ class RefBase extends Finalizer {
|
|
|
526
559
|
}
|
|
527
560
|
|
|
528
561
|
function throwNodeApiVersionError(moduleName, moduleApiVersion) {
|
|
529
|
-
const errorMessage = `${moduleName} requires Node-API version ${moduleApiVersion}, but this version of Node.js only supports version ${
|
|
562
|
+
const errorMessage = `${moduleName} requires Node-API version ${moduleApiVersion}, but this version of Node.js only supports version ${NODE_API_SUPPORTED_VERSION_MAX} add-ons.`;
|
|
530
563
|
throw new Error(errorMessage);
|
|
531
564
|
}
|
|
532
565
|
function handleThrow(envObject, value) {
|
|
@@ -714,12 +747,19 @@ class NodeEnv extends Env {
|
|
|
714
747
|
const hasProcess = typeof process === 'object' && process !== null;
|
|
715
748
|
const hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
|
|
716
749
|
if (!hasForceFlag && !enforceUncaughtExceptionPolicy) {
|
|
717
|
-
|
|
718
|
-
process.emitWarning
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
750
|
+
const warn = hasProcess && typeof process.emitWarning === 'function'
|
|
751
|
+
? process.emitWarning
|
|
752
|
+
: function (warning, type, code) {
|
|
753
|
+
if (warning instanceof Error) {
|
|
754
|
+
console.warn(warning.toString());
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
const prefix = code ? `[${code}] ` : '';
|
|
758
|
+
console.warn(`${prefix}${type || 'Warning'}: ${warning}`);
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
warn('Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
|
|
762
|
+
return;
|
|
723
763
|
}
|
|
724
764
|
envObject.triggerFatalException(err);
|
|
725
765
|
});
|
|
@@ -762,7 +802,7 @@ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_v
|
|
|
762
802
|
if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
|
|
763
803
|
moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
|
|
764
804
|
}
|
|
765
|
-
else if (moduleApiVersion >
|
|
805
|
+
else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
|
|
766
806
|
throwNodeApiVersionError(filename, moduleApiVersion);
|
|
767
807
|
}
|
|
768
808
|
const env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
|
|
@@ -805,16 +845,6 @@ Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
|
|
|
805
845
|
writable: true,
|
|
806
846
|
value: 'NotSupportWeakRefError'
|
|
807
847
|
});
|
|
808
|
-
class NotSupportBigIntError extends EmnapiError {
|
|
809
|
-
constructor(api, message) {
|
|
810
|
-
super(`${api}: The current runtime does not support "BigInt".${message ? ` ${message}` : ''}`);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
Object.defineProperty(NotSupportBigIntError.prototype, 'name', {
|
|
814
|
-
configurable: true,
|
|
815
|
-
writable: true,
|
|
816
|
-
value: 'NotSupportBigIntError'
|
|
817
|
-
});
|
|
818
848
|
class NotSupportBufferError extends EmnapiError {
|
|
819
849
|
constructor(api, message) {
|
|
820
850
|
super(`${api}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${message ? ` ${message}` : ''}`);
|
|
@@ -1166,7 +1196,7 @@ class Context {
|
|
|
1166
1196
|
getRuntimeVersions() {
|
|
1167
1197
|
return {
|
|
1168
1198
|
version,
|
|
1169
|
-
|
|
1199
|
+
NODE_API_SUPPORTED_VERSION_MAX,
|
|
1170
1200
|
NAPI_VERSION_EXPERIMENTAL,
|
|
1171
1201
|
NODE_API_DEFAULT_MODULE_API_VERSION
|
|
1172
1202
|
};
|
|
@@ -1174,9 +1204,6 @@ class Context {
|
|
|
1174
1204
|
createNotSupportWeakRefError(api, message) {
|
|
1175
1205
|
return new NotSupportWeakRefError(api, message);
|
|
1176
1206
|
}
|
|
1177
|
-
createNotSupportBigIntError(api, message) {
|
|
1178
|
-
return new NotSupportBigIntError(api, message);
|
|
1179
|
-
}
|
|
1180
1207
|
createNotSupportBufferError(api, message) {
|
|
1181
1208
|
return new NotSupportBufferError(api, message);
|
|
1182
1209
|
}
|
|
@@ -1267,11 +1294,11 @@ exports.Finalizer = Finalizer;
|
|
|
1267
1294
|
exports.Handle = Handle;
|
|
1268
1295
|
exports.HandleScope = HandleScope;
|
|
1269
1296
|
exports.HandleStore = HandleStore;
|
|
1270
|
-
exports.NAPI_VERSION = NAPI_VERSION;
|
|
1271
1297
|
exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL;
|
|
1272
1298
|
exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION;
|
|
1299
|
+
exports.NODE_API_SUPPORTED_VERSION_MAX = NODE_API_SUPPORTED_VERSION_MAX;
|
|
1300
|
+
exports.NODE_API_SUPPORTED_VERSION_MIN = NODE_API_SUPPORTED_VERSION_MIN;
|
|
1273
1301
|
exports.NodeEnv = NodeEnv;
|
|
1274
|
-
exports.NotSupportBigIntError = NotSupportBigIntError;
|
|
1275
1302
|
exports.NotSupportBufferError = NotSupportBufferError;
|
|
1276
1303
|
exports.NotSupportWeakRefError = NotSupportWeakRefError;
|
|
1277
1304
|
exports.Persistent = Persistent;
|