@emnapi/runtime 1.3.1 → 1.4.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 +41 -108
- package/dist/emnapi.cjs.min.d.ts +30 -27
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.mts +30 -27
- package/dist/emnapi.d.ts +30 -27
- package/dist/emnapi.esm-bundler.js +44 -112
- package/dist/emnapi.iife.d.ts +29 -26
- package/dist/emnapi.iife.js +49 -116
- package/dist/emnapi.js +49 -116
- package/dist/emnapi.min.d.mts +30 -27
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +39 -107
- package/package.json +1 -1
package/dist/emnapi.iife.js
CHANGED
|
@@ -1,75 +1,5 @@
|
|
|
1
1
|
var emnapi = (function (exports) {
|
|
2
2
|
|
|
3
|
-
var EMPTY_ARGS = [];
|
|
4
|
-
var CallbackInfo = /*#__PURE__*/ (function () {
|
|
5
|
-
function CallbackInfo(id, parent, child, thiz, data, args, fn) {
|
|
6
|
-
this.id = id;
|
|
7
|
-
this.parent = parent;
|
|
8
|
-
this.child = child;
|
|
9
|
-
this.thiz = thiz;
|
|
10
|
-
this.data = data;
|
|
11
|
-
this.args = args;
|
|
12
|
-
this.fn = fn;
|
|
13
|
-
}
|
|
14
|
-
CallbackInfo.prototype.getNewTarget = function (envObject) {
|
|
15
|
-
var thiz = this.thiz;
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
17
|
-
if (thiz == null || thiz.constructor == null)
|
|
18
|
-
return 0;
|
|
19
|
-
return thiz instanceof this.fn ? envObject.ensureHandleId(thiz.constructor) : 0;
|
|
20
|
-
};
|
|
21
|
-
CallbackInfo.prototype.dispose = function () {
|
|
22
|
-
if (this.thiz !== undefined)
|
|
23
|
-
this.thiz = undefined;
|
|
24
|
-
this.args = EMPTY_ARGS;
|
|
25
|
-
this.fn = null;
|
|
26
|
-
};
|
|
27
|
-
return CallbackInfo;
|
|
28
|
-
}());
|
|
29
|
-
var ROOT_CBINFO = new CallbackInfo(0, null, null, null, 0, null, null);
|
|
30
|
-
var CallbackInfoStack = /*#__PURE__*/ (function () {
|
|
31
|
-
function CallbackInfoStack() {
|
|
32
|
-
this.current = ROOT_CBINFO;
|
|
33
|
-
}
|
|
34
|
-
CallbackInfoStack.prototype.get = function (id) {
|
|
35
|
-
if (id === 1)
|
|
36
|
-
return ROOT_CBINFO.child;
|
|
37
|
-
var info = ROOT_CBINFO;
|
|
38
|
-
for (var i = 0; i < id; ++i) {
|
|
39
|
-
info = info.child;
|
|
40
|
-
if (info === null)
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
return info === ROOT_CBINFO ? null : info;
|
|
44
|
-
};
|
|
45
|
-
CallbackInfoStack.prototype.pop = function () {
|
|
46
|
-
var current = this.current;
|
|
47
|
-
if (current === ROOT_CBINFO)
|
|
48
|
-
return;
|
|
49
|
-
this.current = current.parent;
|
|
50
|
-
current.dispose();
|
|
51
|
-
};
|
|
52
|
-
CallbackInfoStack.prototype.push = function (thiz, data, args, fn) {
|
|
53
|
-
var info = this.current.child;
|
|
54
|
-
if (info) {
|
|
55
|
-
info.thiz = thiz;
|
|
56
|
-
info.data = data;
|
|
57
|
-
info.args = args;
|
|
58
|
-
info.fn = fn;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
info = new CallbackInfo(this.current.id + 1, this.current, null, thiz, data, args, fn);
|
|
62
|
-
this.current.child = info;
|
|
63
|
-
}
|
|
64
|
-
this.current = info;
|
|
65
|
-
return info.id;
|
|
66
|
-
};
|
|
67
|
-
CallbackInfoStack.prototype.dispose = function () {
|
|
68
|
-
this.current = null;
|
|
69
|
-
};
|
|
70
|
-
return CallbackInfoStack;
|
|
71
|
-
}());
|
|
72
|
-
|
|
73
3
|
/******************************************************************************
|
|
74
4
|
Copyright (c) Microsoft Corporation.
|
|
75
5
|
|
|
@@ -106,6 +36,28 @@ var emnapi = (function (exports) {
|
|
|
106
36
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
107
37
|
};
|
|
108
38
|
|
|
39
|
+
var externalValue = new WeakMap();
|
|
40
|
+
/** @public */
|
|
41
|
+
function isExternal(object) {
|
|
42
|
+
return externalValue.has(object);
|
|
43
|
+
}
|
|
44
|
+
/** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
45
|
+
var External = (function () {
|
|
46
|
+
function External(value) {
|
|
47
|
+
Object.setPrototypeOf(this, null);
|
|
48
|
+
externalValue.set(this, value);
|
|
49
|
+
}
|
|
50
|
+
External.prototype = null;
|
|
51
|
+
return External;
|
|
52
|
+
})();
|
|
53
|
+
/** @public */
|
|
54
|
+
function getExternalValue(external) {
|
|
55
|
+
if (!isExternal(external)) {
|
|
56
|
+
throw new TypeError('not external');
|
|
57
|
+
}
|
|
58
|
+
return externalValue.get(external);
|
|
59
|
+
}
|
|
60
|
+
|
|
109
61
|
var supportNewFunction = /*#__PURE__*/ (function () {
|
|
110
62
|
var f;
|
|
111
63
|
try {
|
|
@@ -246,9 +198,9 @@ var emnapi = (function (exports) {
|
|
|
246
198
|
catch (_) { }
|
|
247
199
|
return undefined;
|
|
248
200
|
})();
|
|
249
|
-
var version = "1.
|
|
201
|
+
var version = "1.4.0";
|
|
250
202
|
var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
|
|
251
|
-
var NODE_API_SUPPORTED_VERSION_MAX =
|
|
203
|
+
var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
|
|
252
204
|
var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
|
|
253
205
|
var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */;
|
|
254
206
|
|
|
@@ -257,8 +209,8 @@ var emnapi = (function (exports) {
|
|
|
257
209
|
this.id = id;
|
|
258
210
|
this.value = value;
|
|
259
211
|
}
|
|
260
|
-
Handle.prototype.data = function (
|
|
261
|
-
return
|
|
212
|
+
Handle.prototype.data = function () {
|
|
213
|
+
return getExternalValue(this.value);
|
|
262
214
|
};
|
|
263
215
|
Handle.prototype.isNumber = function () {
|
|
264
216
|
return typeof this.value === 'number';
|
|
@@ -273,7 +225,7 @@ var emnapi = (function (exports) {
|
|
|
273
225
|
return typeof this.value === 'function';
|
|
274
226
|
};
|
|
275
227
|
Handle.prototype.isExternal = function () {
|
|
276
|
-
return (
|
|
228
|
+
return isExternal(this.value);
|
|
277
229
|
};
|
|
278
230
|
Handle.prototype.isObject = function () {
|
|
279
231
|
return typeof this.value === 'object' && this.value !== null;
|
|
@@ -327,10 +279,6 @@ var emnapi = (function (exports) {
|
|
|
327
279
|
ConstHandle.prototype.dispose = function () { };
|
|
328
280
|
return ConstHandle;
|
|
329
281
|
}(Handle));
|
|
330
|
-
function External() {
|
|
331
|
-
Object.setPrototypeOf(this, null);
|
|
332
|
-
}
|
|
333
|
-
External.prototype = null;
|
|
334
282
|
var HandleStore = /*#__PURE__*/ (function () {
|
|
335
283
|
function HandleStore() {
|
|
336
284
|
this._values = [
|
|
@@ -401,21 +349,24 @@ var emnapi = (function (exports) {
|
|
|
401
349
|
this.start = start;
|
|
402
350
|
this.end = end;
|
|
403
351
|
this._escapeCalled = false;
|
|
352
|
+
this.callbackInfo = {
|
|
353
|
+
thiz: undefined,
|
|
354
|
+
data: 0,
|
|
355
|
+
args: undefined,
|
|
356
|
+
fn: undefined
|
|
357
|
+
};
|
|
404
358
|
}
|
|
405
359
|
HandleScope.prototype.add = function (value) {
|
|
406
360
|
var h = this.handleStore.push(value);
|
|
407
361
|
this.end++;
|
|
408
362
|
return h;
|
|
409
363
|
};
|
|
410
|
-
HandleScope.prototype.addExternal = function (
|
|
411
|
-
|
|
412
|
-
var h = envObject.ctx.handleStore.push(value);
|
|
413
|
-
var binding = envObject.initObjectBinding(value);
|
|
414
|
-
binding.data = data;
|
|
415
|
-
this.end++;
|
|
416
|
-
return h;
|
|
364
|
+
HandleScope.prototype.addExternal = function (data) {
|
|
365
|
+
return this.add(new External(data));
|
|
417
366
|
};
|
|
418
367
|
HandleScope.prototype.dispose = function () {
|
|
368
|
+
if (this._escapeCalled)
|
|
369
|
+
this._escapeCalled = false;
|
|
419
370
|
if (this.start === this.end)
|
|
420
371
|
return;
|
|
421
372
|
this.handleStore.erase(this.start, this.end);
|
|
@@ -443,27 +394,21 @@ var emnapi = (function (exports) {
|
|
|
443
394
|
function ScopeStore() {
|
|
444
395
|
this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID);
|
|
445
396
|
this.currentScope = this._rootScope;
|
|
397
|
+
this._values = [undefined];
|
|
446
398
|
}
|
|
447
399
|
ScopeStore.prototype.get = function (id) {
|
|
448
|
-
|
|
449
|
-
var scope = this.currentScope;
|
|
450
|
-
while (scope !== this._rootScope) {
|
|
451
|
-
if (scope.id === id) {
|
|
452
|
-
return scope;
|
|
453
|
-
}
|
|
454
|
-
scope = scope.parent;
|
|
455
|
-
}
|
|
456
|
-
return undefined;
|
|
400
|
+
return this._values[id];
|
|
457
401
|
};
|
|
458
402
|
ScopeStore.prototype.openScope = function (envObject) {
|
|
459
403
|
var currentScope = this.currentScope;
|
|
460
404
|
var scope = currentScope.child;
|
|
461
405
|
if (scope !== null) {
|
|
462
406
|
scope.start = scope.end = currentScope.end;
|
|
463
|
-
scope._escapeCalled = false;
|
|
464
407
|
}
|
|
465
408
|
else {
|
|
466
|
-
|
|
409
|
+
var id = currentScope.id + 1;
|
|
410
|
+
scope = new HandleScope(envObject.ctx.handleStore, id, currentScope, currentScope.end);
|
|
411
|
+
this._values[id] = scope;
|
|
467
412
|
}
|
|
468
413
|
this.currentScope = scope;
|
|
469
414
|
envObject.openHandleScopes++;
|
|
@@ -478,19 +423,8 @@ var emnapi = (function (exports) {
|
|
|
478
423
|
envObject.openHandleScopes--;
|
|
479
424
|
};
|
|
480
425
|
ScopeStore.prototype.dispose = function () {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
scope.handleStore = null;
|
|
484
|
-
scope.id = 0;
|
|
485
|
-
scope.parent = null;
|
|
486
|
-
scope.start = HandleStore.MIN_ID;
|
|
487
|
-
scope.end = HandleStore.MIN_ID;
|
|
488
|
-
scope._escapeCalled = false;
|
|
489
|
-
var child = scope.child;
|
|
490
|
-
scope.child = null;
|
|
491
|
-
scope = child;
|
|
492
|
-
}
|
|
493
|
-
this.currentScope = null;
|
|
426
|
+
this.currentScope = this._rootScope;
|
|
427
|
+
this._values.length = 1;
|
|
494
428
|
};
|
|
495
429
|
return ScopeStore;
|
|
496
430
|
}());
|
|
@@ -767,8 +701,7 @@ var emnapi = (function (exports) {
|
|
|
767
701
|
Env.prototype.initObjectBinding = function (value) {
|
|
768
702
|
var binding = {
|
|
769
703
|
wrapped: 0,
|
|
770
|
-
tag: null
|
|
771
|
-
data: 0
|
|
704
|
+
tag: null
|
|
772
705
|
};
|
|
773
706
|
this._bindingMap.set(value, binding);
|
|
774
707
|
return binding;
|
|
@@ -832,7 +765,7 @@ var emnapi = (function (exports) {
|
|
|
832
765
|
}
|
|
833
766
|
var hasProcess = typeof process === 'object' && process !== null;
|
|
834
767
|
var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
|
|
835
|
-
if (envObject.moduleApiVersion <
|
|
768
|
+
if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
|
|
836
769
|
var warn = hasProcess && typeof process.emitWarning === 'function'
|
|
837
770
|
? process.emitWarning
|
|
838
771
|
: function (warning, type, code) {
|
|
@@ -1363,7 +1296,6 @@ var emnapi = (function (exports) {
|
|
|
1363
1296
|
this.refStore = new Store();
|
|
1364
1297
|
this.deferredStore = new Store();
|
|
1365
1298
|
this.handleStore = new HandleStore();
|
|
1366
|
-
this.cbinfoStack = new CallbackInfoStack();
|
|
1367
1299
|
this.feature = {
|
|
1368
1300
|
supportReflect: supportReflect,
|
|
1369
1301
|
supportFinalizer: supportFinalizer,
|
|
@@ -1504,13 +1436,12 @@ var emnapi = (function (exports) {
|
|
|
1504
1436
|
return defaultContext;
|
|
1505
1437
|
}
|
|
1506
1438
|
|
|
1507
|
-
exports.CallbackInfo = CallbackInfo;
|
|
1508
|
-
exports.CallbackInfoStack = CallbackInfoStack;
|
|
1509
1439
|
exports.ConstHandle = ConstHandle;
|
|
1510
1440
|
exports.Context = Context;
|
|
1511
1441
|
exports.Deferred = Deferred;
|
|
1512
1442
|
exports.EmnapiError = EmnapiError;
|
|
1513
1443
|
exports.Env = Env;
|
|
1444
|
+
exports.External = External;
|
|
1514
1445
|
exports.Finalizer = Finalizer;
|
|
1515
1446
|
exports.Handle = Handle;
|
|
1516
1447
|
exports.HandleScope = HandleScope;
|
|
@@ -1533,6 +1464,8 @@ var emnapi = (function (exports) {
|
|
|
1533
1464
|
exports.TryCatch = TryCatch;
|
|
1534
1465
|
exports.createContext = createContext;
|
|
1535
1466
|
exports.getDefaultContext = getDefaultContext;
|
|
1467
|
+
exports.getExternalValue = getExternalValue;
|
|
1468
|
+
exports.isExternal = isExternal;
|
|
1536
1469
|
exports.isReferenceType = isReferenceType;
|
|
1537
1470
|
exports.version = version;
|
|
1538
1471
|
|
package/dist/emnapi.js
CHANGED
|
@@ -3,76 +3,6 @@
|
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.emnapi = {}));
|
|
5
5
|
})(this, (function (exports) {
|
|
6
|
-
var EMPTY_ARGS = [];
|
|
7
|
-
var CallbackInfo = /*#__PURE__*/ (function () {
|
|
8
|
-
function CallbackInfo(id, parent, child, thiz, data, args, fn) {
|
|
9
|
-
this.id = id;
|
|
10
|
-
this.parent = parent;
|
|
11
|
-
this.child = child;
|
|
12
|
-
this.thiz = thiz;
|
|
13
|
-
this.data = data;
|
|
14
|
-
this.args = args;
|
|
15
|
-
this.fn = fn;
|
|
16
|
-
}
|
|
17
|
-
CallbackInfo.prototype.getNewTarget = function (envObject) {
|
|
18
|
-
var thiz = this.thiz;
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
20
|
-
if (thiz == null || thiz.constructor == null)
|
|
21
|
-
return 0;
|
|
22
|
-
return thiz instanceof this.fn ? envObject.ensureHandleId(thiz.constructor) : 0;
|
|
23
|
-
};
|
|
24
|
-
CallbackInfo.prototype.dispose = function () {
|
|
25
|
-
if (this.thiz !== undefined)
|
|
26
|
-
this.thiz = undefined;
|
|
27
|
-
this.args = EMPTY_ARGS;
|
|
28
|
-
this.fn = null;
|
|
29
|
-
};
|
|
30
|
-
return CallbackInfo;
|
|
31
|
-
}());
|
|
32
|
-
var ROOT_CBINFO = new CallbackInfo(0, null, null, null, 0, null, null);
|
|
33
|
-
var CallbackInfoStack = /*#__PURE__*/ (function () {
|
|
34
|
-
function CallbackInfoStack() {
|
|
35
|
-
this.current = ROOT_CBINFO;
|
|
36
|
-
}
|
|
37
|
-
CallbackInfoStack.prototype.get = function (id) {
|
|
38
|
-
if (id === 1)
|
|
39
|
-
return ROOT_CBINFO.child;
|
|
40
|
-
var info = ROOT_CBINFO;
|
|
41
|
-
for (var i = 0; i < id; ++i) {
|
|
42
|
-
info = info.child;
|
|
43
|
-
if (info === null)
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
return info === ROOT_CBINFO ? null : info;
|
|
47
|
-
};
|
|
48
|
-
CallbackInfoStack.prototype.pop = function () {
|
|
49
|
-
var current = this.current;
|
|
50
|
-
if (current === ROOT_CBINFO)
|
|
51
|
-
return;
|
|
52
|
-
this.current = current.parent;
|
|
53
|
-
current.dispose();
|
|
54
|
-
};
|
|
55
|
-
CallbackInfoStack.prototype.push = function (thiz, data, args, fn) {
|
|
56
|
-
var info = this.current.child;
|
|
57
|
-
if (info) {
|
|
58
|
-
info.thiz = thiz;
|
|
59
|
-
info.data = data;
|
|
60
|
-
info.args = args;
|
|
61
|
-
info.fn = fn;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
info = new CallbackInfo(this.current.id + 1, this.current, null, thiz, data, args, fn);
|
|
65
|
-
this.current.child = info;
|
|
66
|
-
}
|
|
67
|
-
this.current = info;
|
|
68
|
-
return info.id;
|
|
69
|
-
};
|
|
70
|
-
CallbackInfoStack.prototype.dispose = function () {
|
|
71
|
-
this.current = null;
|
|
72
|
-
};
|
|
73
|
-
return CallbackInfoStack;
|
|
74
|
-
}());
|
|
75
|
-
|
|
76
6
|
/******************************************************************************
|
|
77
7
|
Copyright (c) Microsoft Corporation.
|
|
78
8
|
|
|
@@ -109,6 +39,28 @@
|
|
|
109
39
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
110
40
|
};
|
|
111
41
|
|
|
42
|
+
var externalValue = new WeakMap();
|
|
43
|
+
/** @public */
|
|
44
|
+
function isExternal(object) {
|
|
45
|
+
return externalValue.has(object);
|
|
46
|
+
}
|
|
47
|
+
/** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
48
|
+
var External = (function () {
|
|
49
|
+
function External(value) {
|
|
50
|
+
Object.setPrototypeOf(this, null);
|
|
51
|
+
externalValue.set(this, value);
|
|
52
|
+
}
|
|
53
|
+
External.prototype = null;
|
|
54
|
+
return External;
|
|
55
|
+
})();
|
|
56
|
+
/** @public */
|
|
57
|
+
function getExternalValue(external) {
|
|
58
|
+
if (!isExternal(external)) {
|
|
59
|
+
throw new TypeError('not external');
|
|
60
|
+
}
|
|
61
|
+
return externalValue.get(external);
|
|
62
|
+
}
|
|
63
|
+
|
|
112
64
|
var supportNewFunction = /*#__PURE__*/ (function () {
|
|
113
65
|
var f;
|
|
114
66
|
try {
|
|
@@ -249,9 +201,9 @@
|
|
|
249
201
|
catch (_) { }
|
|
250
202
|
return undefined;
|
|
251
203
|
})();
|
|
252
|
-
var version = "1.
|
|
204
|
+
var version = "1.4.0";
|
|
253
205
|
var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
|
|
254
|
-
var NODE_API_SUPPORTED_VERSION_MAX =
|
|
206
|
+
var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
|
|
255
207
|
var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
|
|
256
208
|
var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */;
|
|
257
209
|
|
|
@@ -260,8 +212,8 @@
|
|
|
260
212
|
this.id = id;
|
|
261
213
|
this.value = value;
|
|
262
214
|
}
|
|
263
|
-
Handle.prototype.data = function (
|
|
264
|
-
return
|
|
215
|
+
Handle.prototype.data = function () {
|
|
216
|
+
return getExternalValue(this.value);
|
|
265
217
|
};
|
|
266
218
|
Handle.prototype.isNumber = function () {
|
|
267
219
|
return typeof this.value === 'number';
|
|
@@ -276,7 +228,7 @@
|
|
|
276
228
|
return typeof this.value === 'function';
|
|
277
229
|
};
|
|
278
230
|
Handle.prototype.isExternal = function () {
|
|
279
|
-
return (
|
|
231
|
+
return isExternal(this.value);
|
|
280
232
|
};
|
|
281
233
|
Handle.prototype.isObject = function () {
|
|
282
234
|
return typeof this.value === 'object' && this.value !== null;
|
|
@@ -330,10 +282,6 @@
|
|
|
330
282
|
ConstHandle.prototype.dispose = function () { };
|
|
331
283
|
return ConstHandle;
|
|
332
284
|
}(Handle));
|
|
333
|
-
function External() {
|
|
334
|
-
Object.setPrototypeOf(this, null);
|
|
335
|
-
}
|
|
336
|
-
External.prototype = null;
|
|
337
285
|
var HandleStore = /*#__PURE__*/ (function () {
|
|
338
286
|
function HandleStore() {
|
|
339
287
|
this._values = [
|
|
@@ -404,21 +352,24 @@
|
|
|
404
352
|
this.start = start;
|
|
405
353
|
this.end = end;
|
|
406
354
|
this._escapeCalled = false;
|
|
355
|
+
this.callbackInfo = {
|
|
356
|
+
thiz: undefined,
|
|
357
|
+
data: 0,
|
|
358
|
+
args: undefined,
|
|
359
|
+
fn: undefined
|
|
360
|
+
};
|
|
407
361
|
}
|
|
408
362
|
HandleScope.prototype.add = function (value) {
|
|
409
363
|
var h = this.handleStore.push(value);
|
|
410
364
|
this.end++;
|
|
411
365
|
return h;
|
|
412
366
|
};
|
|
413
|
-
HandleScope.prototype.addExternal = function (
|
|
414
|
-
|
|
415
|
-
var h = envObject.ctx.handleStore.push(value);
|
|
416
|
-
var binding = envObject.initObjectBinding(value);
|
|
417
|
-
binding.data = data;
|
|
418
|
-
this.end++;
|
|
419
|
-
return h;
|
|
367
|
+
HandleScope.prototype.addExternal = function (data) {
|
|
368
|
+
return this.add(new External(data));
|
|
420
369
|
};
|
|
421
370
|
HandleScope.prototype.dispose = function () {
|
|
371
|
+
if (this._escapeCalled)
|
|
372
|
+
this._escapeCalled = false;
|
|
422
373
|
if (this.start === this.end)
|
|
423
374
|
return;
|
|
424
375
|
this.handleStore.erase(this.start, this.end);
|
|
@@ -446,27 +397,21 @@
|
|
|
446
397
|
function ScopeStore() {
|
|
447
398
|
this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID);
|
|
448
399
|
this.currentScope = this._rootScope;
|
|
400
|
+
this._values = [undefined];
|
|
449
401
|
}
|
|
450
402
|
ScopeStore.prototype.get = function (id) {
|
|
451
|
-
|
|
452
|
-
var scope = this.currentScope;
|
|
453
|
-
while (scope !== this._rootScope) {
|
|
454
|
-
if (scope.id === id) {
|
|
455
|
-
return scope;
|
|
456
|
-
}
|
|
457
|
-
scope = scope.parent;
|
|
458
|
-
}
|
|
459
|
-
return undefined;
|
|
403
|
+
return this._values[id];
|
|
460
404
|
};
|
|
461
405
|
ScopeStore.prototype.openScope = function (envObject) {
|
|
462
406
|
var currentScope = this.currentScope;
|
|
463
407
|
var scope = currentScope.child;
|
|
464
408
|
if (scope !== null) {
|
|
465
409
|
scope.start = scope.end = currentScope.end;
|
|
466
|
-
scope._escapeCalled = false;
|
|
467
410
|
}
|
|
468
411
|
else {
|
|
469
|
-
|
|
412
|
+
var id = currentScope.id + 1;
|
|
413
|
+
scope = new HandleScope(envObject.ctx.handleStore, id, currentScope, currentScope.end);
|
|
414
|
+
this._values[id] = scope;
|
|
470
415
|
}
|
|
471
416
|
this.currentScope = scope;
|
|
472
417
|
envObject.openHandleScopes++;
|
|
@@ -481,19 +426,8 @@
|
|
|
481
426
|
envObject.openHandleScopes--;
|
|
482
427
|
};
|
|
483
428
|
ScopeStore.prototype.dispose = function () {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
scope.handleStore = null;
|
|
487
|
-
scope.id = 0;
|
|
488
|
-
scope.parent = null;
|
|
489
|
-
scope.start = HandleStore.MIN_ID;
|
|
490
|
-
scope.end = HandleStore.MIN_ID;
|
|
491
|
-
scope._escapeCalled = false;
|
|
492
|
-
var child = scope.child;
|
|
493
|
-
scope.child = null;
|
|
494
|
-
scope = child;
|
|
495
|
-
}
|
|
496
|
-
this.currentScope = null;
|
|
429
|
+
this.currentScope = this._rootScope;
|
|
430
|
+
this._values.length = 1;
|
|
497
431
|
};
|
|
498
432
|
return ScopeStore;
|
|
499
433
|
}());
|
|
@@ -770,8 +704,7 @@
|
|
|
770
704
|
Env.prototype.initObjectBinding = function (value) {
|
|
771
705
|
var binding = {
|
|
772
706
|
wrapped: 0,
|
|
773
|
-
tag: null
|
|
774
|
-
data: 0
|
|
707
|
+
tag: null
|
|
775
708
|
};
|
|
776
709
|
this._bindingMap.set(value, binding);
|
|
777
710
|
return binding;
|
|
@@ -835,7 +768,7 @@
|
|
|
835
768
|
}
|
|
836
769
|
var hasProcess = typeof process === 'object' && process !== null;
|
|
837
770
|
var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
|
|
838
|
-
if (envObject.moduleApiVersion <
|
|
771
|
+
if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
|
|
839
772
|
var warn = hasProcess && typeof process.emitWarning === 'function'
|
|
840
773
|
? process.emitWarning
|
|
841
774
|
: function (warning, type, code) {
|
|
@@ -1366,7 +1299,6 @@
|
|
|
1366
1299
|
this.refStore = new Store();
|
|
1367
1300
|
this.deferredStore = new Store();
|
|
1368
1301
|
this.handleStore = new HandleStore();
|
|
1369
|
-
this.cbinfoStack = new CallbackInfoStack();
|
|
1370
1302
|
this.feature = {
|
|
1371
1303
|
supportReflect: supportReflect,
|
|
1372
1304
|
supportFinalizer: supportFinalizer,
|
|
@@ -1507,13 +1439,12 @@
|
|
|
1507
1439
|
return defaultContext;
|
|
1508
1440
|
}
|
|
1509
1441
|
|
|
1510
|
-
exports.CallbackInfo = CallbackInfo;
|
|
1511
|
-
exports.CallbackInfoStack = CallbackInfoStack;
|
|
1512
1442
|
exports.ConstHandle = ConstHandle;
|
|
1513
1443
|
exports.Context = Context;
|
|
1514
1444
|
exports.Deferred = Deferred;
|
|
1515
1445
|
exports.EmnapiError = EmnapiError;
|
|
1516
1446
|
exports.Env = Env;
|
|
1447
|
+
exports.External = External;
|
|
1517
1448
|
exports.Finalizer = Finalizer;
|
|
1518
1449
|
exports.Handle = Handle;
|
|
1519
1450
|
exports.HandleScope = HandleScope;
|
|
@@ -1536,6 +1467,8 @@
|
|
|
1536
1467
|
exports.TryCatch = TryCatch;
|
|
1537
1468
|
exports.createContext = createContext;
|
|
1538
1469
|
exports.getDefaultContext = getDefaultContext;
|
|
1470
|
+
exports.getExternalValue = getExternalValue;
|
|
1471
|
+
exports.isExternal = isExternal;
|
|
1539
1472
|
exports.isReferenceType = isReferenceType;
|
|
1540
1473
|
exports.version = version;
|
|
1541
1474
|
|
package/dist/emnapi.min.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ export declare const enum GlobalHandle {
|
|
|
24
24
|
export declare const enum Version {
|
|
25
25
|
NODE_API_SUPPORTED_VERSION_MIN = 1,
|
|
26
26
|
NODE_API_DEFAULT_MODULE_API_VERSION = 8,
|
|
27
|
-
NODE_API_SUPPORTED_VERSION_MAX =
|
|
27
|
+
NODE_API_SUPPORTED_VERSION_MAX = 10,
|
|
28
28
|
NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
|
|
29
29
|
}
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -246,27 +246,6 @@ export declare const enum napi_threadsafe_function_release_mode {
|
|
|
246
246
|
napi_tsfn_release,
|
|
247
247
|
napi_tsfn_abort
|
|
248
248
|
}
|
|
249
|
-
export declare class CallbackInfo {
|
|
250
|
-
id: number;
|
|
251
|
-
parent: CallbackInfo;
|
|
252
|
-
child: CallbackInfo | null;
|
|
253
|
-
thiz: any;
|
|
254
|
-
data: void_p;
|
|
255
|
-
args: ArrayLike<any>;
|
|
256
|
-
fn: Function;
|
|
257
|
-
constructor(id: number, parent: CallbackInfo, child: CallbackInfo | null, thiz: any, data: void_p, args: ArrayLike<any>, fn: Function);
|
|
258
|
-
getNewTarget(envObject: Env): number;
|
|
259
|
-
dispose(): void;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export declare class CallbackInfoStack {
|
|
263
|
-
current: CallbackInfo;
|
|
264
|
-
get(id: number): CallbackInfo | null;
|
|
265
|
-
pop(): void;
|
|
266
|
-
push(thiz: any, data: void_p, args: ArrayLike<any>, fn: Function): number;
|
|
267
|
-
dispose(): void;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
249
|
export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
|
|
271
250
|
|
|
272
251
|
export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
|
|
@@ -283,7 +262,6 @@ export declare class Context {
|
|
|
283
262
|
refStore: Store<Reference>;
|
|
284
263
|
deferredStore: Store<Deferred<any>>;
|
|
285
264
|
handleStore: HandleStore;
|
|
286
|
-
cbinfoStack: CallbackInfoStack;
|
|
287
265
|
private readonly refCounter?;
|
|
288
266
|
private readonly cleanupQueue;
|
|
289
267
|
feature: {
|
|
@@ -411,6 +389,17 @@ export declare abstract class Env implements IStoreValue {
|
|
|
411
389
|
getInstanceData(): number;
|
|
412
390
|
}
|
|
413
391
|
|
|
392
|
+
/** @public */
|
|
393
|
+
declare interface External_2 extends Record<any, any> {
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** @public */
|
|
397
|
+
declare const External_2: {
|
|
398
|
+
new (value: number | bigint): External_2;
|
|
399
|
+
prototype: null;
|
|
400
|
+
};
|
|
401
|
+
export { External_2 as External }
|
|
402
|
+
|
|
414
403
|
export declare class Finalizer {
|
|
415
404
|
envObject: Env;
|
|
416
405
|
private _finalizeCallback;
|
|
@@ -429,11 +418,14 @@ export declare class Finalizer {
|
|
|
429
418
|
|
|
430
419
|
export declare function getDefaultContext(): Context;
|
|
431
420
|
|
|
421
|
+
/** @public */
|
|
422
|
+
export declare function getExternalValue(external: External_2): number | bigint;
|
|
423
|
+
|
|
432
424
|
export declare class Handle<S> {
|
|
433
425
|
id: number;
|
|
434
426
|
value: S;
|
|
435
427
|
constructor(id: number, value: S);
|
|
436
|
-
data(
|
|
428
|
+
data(): void_p;
|
|
437
429
|
isNumber(): boolean;
|
|
438
430
|
isBigInt(): boolean;
|
|
439
431
|
isString(): boolean;
|
|
@@ -461,10 +453,11 @@ export declare class HandleScope {
|
|
|
461
453
|
child: HandleScope | null;
|
|
462
454
|
start: number;
|
|
463
455
|
end: number;
|
|
464
|
-
_escapeCalled
|
|
456
|
+
private _escapeCalled;
|
|
457
|
+
callbackInfo: ICallbackInfo;
|
|
465
458
|
constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
|
|
466
459
|
add<V>(value: V): Handle<V>;
|
|
467
|
-
addExternal(
|
|
460
|
+
addExternal(data: void_p): Handle<object>;
|
|
468
461
|
dispose(): void;
|
|
469
462
|
escape(handle: number): Handle<any> | null;
|
|
470
463
|
escapeCalled(): boolean;
|
|
@@ -486,6 +479,13 @@ export declare class HandleStore {
|
|
|
486
479
|
dispose(): void;
|
|
487
480
|
}
|
|
488
481
|
|
|
482
|
+
export declare interface ICallbackInfo {
|
|
483
|
+
thiz: any;
|
|
484
|
+
data: void_p;
|
|
485
|
+
args: ArrayLike<any>;
|
|
486
|
+
fn: Function;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
489
|
export declare interface IDeferrdValue<T = any> {
|
|
490
490
|
resolve: (value: T) => void;
|
|
491
491
|
reject: (reason?: any) => void;
|
|
@@ -494,9 +494,11 @@ export declare interface IDeferrdValue<T = any> {
|
|
|
494
494
|
export declare interface IReferenceBinding {
|
|
495
495
|
wrapped: number;
|
|
496
496
|
tag: Uint32Array | null;
|
|
497
|
-
data: void_p;
|
|
498
497
|
}
|
|
499
498
|
|
|
499
|
+
/** @public */
|
|
500
|
+
export declare function isExternal(object: unknown): object is External_2;
|
|
501
|
+
|
|
500
502
|
export declare function isReferenceType(v: any): v is object;
|
|
501
503
|
|
|
502
504
|
export declare interface IStoreValue {
|
|
@@ -616,6 +618,7 @@ export declare class RefTracker {
|
|
|
616
618
|
export declare class ScopeStore {
|
|
617
619
|
private readonly _rootScope;
|
|
618
620
|
currentScope: HandleScope;
|
|
621
|
+
private readonly _values;
|
|
619
622
|
constructor();
|
|
620
623
|
get(id: number): HandleScope | undefined;
|
|
621
624
|
openScope(envObject: Env): HandleScope;
|