@emnapi/runtime 0.42.0 → 0.43.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/dist/emnapi.cjs.js +72 -28
- package/dist/emnapi.cjs.min.d.ts +19 -8
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.mts +19 -8
- package/dist/emnapi.d.ts +19 -8
- package/dist/emnapi.esm-bundler.js +81 -37
- package/dist/emnapi.iife.d.ts +19 -8
- package/dist/emnapi.iife.js +81 -36
- package/dist/emnapi.js +81 -36
- package/dist/emnapi.min.d.mts +19 -8
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +72 -29
- package/package.json +1 -1
|
@@ -206,7 +206,7 @@ var _Buffer = typeof Buffer === 'function'
|
|
|
206
206
|
catch (_) { }
|
|
207
207
|
return undefined;
|
|
208
208
|
})();
|
|
209
|
-
var version = "0.
|
|
209
|
+
var version = "0.43.1";
|
|
210
210
|
var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
|
|
211
211
|
var NODE_API_SUPPORTED_VERSION_MAX = 9 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
|
|
212
212
|
var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
|
|
@@ -509,53 +509,36 @@ var Finalizer = /*#__PURE__*/ (function () {
|
|
|
509
509
|
return Finalizer;
|
|
510
510
|
}());
|
|
511
511
|
|
|
512
|
-
var
|
|
513
|
-
__extends(
|
|
514
|
-
function
|
|
512
|
+
var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
|
|
513
|
+
__extends(TrackedFinalizer, _super);
|
|
514
|
+
function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
515
515
|
var _this = _super.call(this, envObject, finalize_callback, finalize_data, finalize_hint) || this;
|
|
516
516
|
_this._next = null;
|
|
517
517
|
_this._prev = null;
|
|
518
|
-
_this._refcount = initial_refcount;
|
|
519
|
-
_this._ownership = ownership;
|
|
520
518
|
_this.link(!finalize_callback ? envObject.reflist : envObject.finalizing_reflist);
|
|
521
519
|
return _this;
|
|
522
520
|
}
|
|
523
|
-
|
|
521
|
+
TrackedFinalizer.finalizeAll = function (list) {
|
|
524
522
|
RefTracker.finalizeAll(list);
|
|
525
523
|
};
|
|
526
|
-
|
|
524
|
+
TrackedFinalizer.prototype.link = function (list) {
|
|
527
525
|
RefTracker.prototype.link.call(this, list);
|
|
528
526
|
};
|
|
529
|
-
|
|
527
|
+
TrackedFinalizer.prototype.unlink = function () {
|
|
530
528
|
RefTracker.prototype.unlink.call(this);
|
|
531
529
|
};
|
|
532
|
-
|
|
530
|
+
TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
531
|
+
return new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
532
|
+
};
|
|
533
|
+
TrackedFinalizer.prototype.dispose = function () {
|
|
533
534
|
this.unlink();
|
|
534
535
|
this.envObject.dequeueFinalizer(this);
|
|
535
536
|
_super.prototype.dispose.call(this);
|
|
536
537
|
};
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
};
|
|
540
|
-
RefBase.prototype.ref = function () {
|
|
541
|
-
return ++this._refcount;
|
|
542
|
-
};
|
|
543
|
-
RefBase.prototype.unref = function () {
|
|
544
|
-
if (this._refcount === 0) {
|
|
545
|
-
return 0;
|
|
546
|
-
}
|
|
547
|
-
return --this._refcount;
|
|
538
|
+
TrackedFinalizer.prototype.finalize = function () {
|
|
539
|
+
this.finalizeCore(true);
|
|
548
540
|
};
|
|
549
|
-
|
|
550
|
-
return this._refcount;
|
|
551
|
-
};
|
|
552
|
-
RefBase.prototype.ownership = function () {
|
|
553
|
-
return this._ownership;
|
|
554
|
-
};
|
|
555
|
-
RefBase.prototype.finalize = function () {
|
|
556
|
-
var ownership = this._ownership;
|
|
557
|
-
// Swap out the field finalize_callback so that it can not be accidentally
|
|
558
|
-
// called more than once.
|
|
541
|
+
TrackedFinalizer.prototype.finalizeCore = function (deleteMe) {
|
|
559
542
|
var finalize_callback = this._finalizeCallback;
|
|
560
543
|
var finalize_data = this._finalizeData;
|
|
561
544
|
var finalize_hint = this._finalizeHint;
|
|
@@ -573,16 +556,48 @@ var RefBase = /*#__PURE__*/ (function (_super) {
|
|
|
573
556
|
error = err;
|
|
574
557
|
}
|
|
575
558
|
}
|
|
576
|
-
if (
|
|
559
|
+
if (deleteMe) {
|
|
577
560
|
this.dispose();
|
|
578
561
|
}
|
|
579
562
|
if (caught) {
|
|
580
563
|
throw error;
|
|
581
564
|
}
|
|
582
565
|
};
|
|
583
|
-
return
|
|
566
|
+
return TrackedFinalizer;
|
|
584
567
|
}(Finalizer));
|
|
585
568
|
|
|
569
|
+
var RefBase = /*#__PURE__*/ (function (_super) {
|
|
570
|
+
__extends(RefBase, _super);
|
|
571
|
+
function RefBase(envObject, initial_refcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
572
|
+
var _this = _super.call(this, envObject, finalize_callback, finalize_data, finalize_hint) || this;
|
|
573
|
+
_this._refcount = initial_refcount;
|
|
574
|
+
_this._ownership = ownership;
|
|
575
|
+
return _this;
|
|
576
|
+
}
|
|
577
|
+
RefBase.prototype.data = function () {
|
|
578
|
+
return this._finalizeData;
|
|
579
|
+
};
|
|
580
|
+
RefBase.prototype.ref = function () {
|
|
581
|
+
return ++this._refcount;
|
|
582
|
+
};
|
|
583
|
+
RefBase.prototype.unref = function () {
|
|
584
|
+
if (this._refcount === 0) {
|
|
585
|
+
return 0;
|
|
586
|
+
}
|
|
587
|
+
return --this._refcount;
|
|
588
|
+
};
|
|
589
|
+
RefBase.prototype.refCount = function () {
|
|
590
|
+
return this._refcount;
|
|
591
|
+
};
|
|
592
|
+
RefBase.prototype.ownership = function () {
|
|
593
|
+
return this._ownership;
|
|
594
|
+
};
|
|
595
|
+
RefBase.prototype.finalize = function () {
|
|
596
|
+
this.finalizeCore(this._ownership === 0 /* Ownership.kRuntime */);
|
|
597
|
+
};
|
|
598
|
+
return RefBase;
|
|
599
|
+
}(TrackedFinalizer));
|
|
600
|
+
|
|
586
601
|
function throwNodeApiVersionError(moduleName, moduleApiVersion) {
|
|
587
602
|
var errorMessage = "".concat(moduleName, " requires Node-API version ").concat(moduleApiVersion, ", but this version of Node.js only supports version ").concat(NODE_API_SUPPORTED_VERSION_MAX, " add-ons.");
|
|
588
603
|
throw new Error(errorMessage);
|
|
@@ -612,6 +627,7 @@ var Env = /*#__PURE__*/ (function () {
|
|
|
612
627
|
engineErrorCode: 0,
|
|
613
628
|
engineReserved: 0
|
|
614
629
|
};
|
|
630
|
+
this.inGcFinalizer = false;
|
|
615
631
|
this._bindingMap = new WeakMap();
|
|
616
632
|
this.id = 0;
|
|
617
633
|
}
|
|
@@ -688,6 +704,31 @@ var Env = /*#__PURE__*/ (function () {
|
|
|
688
704
|
this.ctx.closeScope(this, scope);
|
|
689
705
|
}
|
|
690
706
|
};
|
|
707
|
+
Env.prototype.invokeFinalizerFromGC = function (finalizer) {
|
|
708
|
+
if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
|
|
709
|
+
this.enqueueFinalizer(finalizer);
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
var saved = this.inGcFinalizer;
|
|
713
|
+
this.inGcFinalizer = true;
|
|
714
|
+
try {
|
|
715
|
+
finalizer.finalize();
|
|
716
|
+
}
|
|
717
|
+
finally {
|
|
718
|
+
this.inGcFinalizer = saved;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
Env.prototype.checkGCAccess = function () {
|
|
723
|
+
if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) {
|
|
724
|
+
this.abort('Finalizer is calling a function that may affect GC state.\n' +
|
|
725
|
+
'The finalizers are run directly from GC and must not affect GC ' +
|
|
726
|
+
'state.\n' +
|
|
727
|
+
'Use `node_api_post_finalizer` from inside of the finalizer to work ' +
|
|
728
|
+
'around this issue.\n' +
|
|
729
|
+
'It schedules the call as a new task in the event loop.');
|
|
730
|
+
}
|
|
731
|
+
};
|
|
691
732
|
/** @virtual */
|
|
692
733
|
Env.prototype.enqueueFinalizer = function (finalizer) {
|
|
693
734
|
if (this.pendingFinalizers.indexOf(finalizer) === -1) {
|
|
@@ -756,7 +797,7 @@ var NodeEnv = /*#__PURE__*/ (function (_super) {
|
|
|
756
797
|
_super.prototype.deleteMe.call(this);
|
|
757
798
|
};
|
|
758
799
|
NodeEnv.prototype.canCallIntoJs = function () {
|
|
759
|
-
return this.ctx.canCallIntoJs();
|
|
800
|
+
return _super.prototype.canCallIntoJs.call(this) && this.ctx.canCallIntoJs();
|
|
760
801
|
};
|
|
761
802
|
NodeEnv.prototype.triggerFatalException = function (err) {
|
|
762
803
|
if (this.nodeBinding) {
|
|
@@ -782,7 +823,7 @@ var NodeEnv = /*#__PURE__*/ (function (_super) {
|
|
|
782
823
|
}
|
|
783
824
|
var hasProcess = typeof process === 'object' && process !== null;
|
|
784
825
|
var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
|
|
785
|
-
if (!hasForceFlag && !enforceUncaughtExceptionPolicy) {
|
|
826
|
+
if (envObject.moduleApiVersion < NAPI_VERSION_EXPERIMENTAL && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
|
|
786
827
|
var warn = hasProcess && typeof process.emitWarning === 'function'
|
|
787
828
|
? process.emitWarning
|
|
788
829
|
: function (warning, type, code) {
|
|
@@ -998,7 +1039,7 @@ var Persistent = /*#__PURE__*/ (function () {
|
|
|
998
1039
|
|
|
999
1040
|
function weakCallback(ref) {
|
|
1000
1041
|
ref.persistent.reset();
|
|
1001
|
-
ref.envObject.
|
|
1042
|
+
ref.envObject.invokeFinalizerFromGC(ref);
|
|
1002
1043
|
}
|
|
1003
1044
|
function canBeHeldWeakly(value) {
|
|
1004
1045
|
return value.isObject() || value.isFunction() || value.isSymbol();
|
|
@@ -1286,6 +1327,9 @@ var Context = /*#__PURE__*/ (function () {
|
|
|
1286
1327
|
Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
|
|
1287
1328
|
return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
|
|
1288
1329
|
};
|
|
1330
|
+
Context.prototype.createTrackedFinalizer = function (envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
1331
|
+
return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
1332
|
+
};
|
|
1289
1333
|
Context.prototype.getCurrentScope = function () {
|
|
1290
1334
|
return this.scopeStore.currentScope;
|
|
1291
1335
|
};
|
|
@@ -1354,4 +1398,4 @@ function getDefaultContext() {
|
|
|
1354
1398
|
return defaultContext;
|
|
1355
1399
|
}
|
|
1356
1400
|
|
|
1357
|
-
export { CallbackInfo, CallbackInfoStack, ConstHandle, Context, Deferred, EmnapiError, Env, Finalizer, Handle, HandleScope, HandleStore, NAPI_VERSION_EXPERIMENTAL, NODE_API_DEFAULT_MODULE_API_VERSION, NODE_API_SUPPORTED_VERSION_MAX, NODE_API_SUPPORTED_VERSION_MIN, NodeEnv, NotSupportBufferError, NotSupportWeakRefError, Persistent, RefBase, RefTracker, Reference, ScopeStore, Store, TryCatch, createContext, getDefaultContext, isReferenceType, version };
|
|
1401
|
+
export { CallbackInfo, CallbackInfoStack, ConstHandle, Context, Deferred, EmnapiError, Env, Finalizer, Handle, HandleScope, HandleStore, NAPI_VERSION_EXPERIMENTAL, NODE_API_DEFAULT_MODULE_API_VERSION, NODE_API_SUPPORTED_VERSION_MAX, NODE_API_SUPPORTED_VERSION_MIN, NodeEnv, NotSupportBufferError, NotSupportWeakRefError, Persistent, RefBase, RefTracker, Reference, ScopeStore, Store, TrackedFinalizer, TryCatch, createContext, getDefaultContext, isReferenceType, version };
|
package/dist/emnapi.iife.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ export class Context {
|
|
|
65
65
|
createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
|
|
66
66
|
createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
|
|
67
67
|
createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
|
|
68
|
+
createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
|
|
68
69
|
getCurrentScope(): HandleScope | null;
|
|
69
70
|
addToCurrentScope<V>(value: V): Handle<V>;
|
|
70
71
|
openScope(envObject: Env): HandleScope;
|
|
@@ -117,6 +118,7 @@ export class Env implements IStoreValue {
|
|
|
117
118
|
engineErrorCode: number;
|
|
118
119
|
engineReserved: Ptr;
|
|
119
120
|
};
|
|
121
|
+
inGcFinalizer: boolean;
|
|
120
122
|
constructor(ctx: Context, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never);
|
|
121
123
|
canCallIntoJs(): boolean;
|
|
122
124
|
terminatedOrTerminating(): boolean;
|
|
@@ -129,6 +131,8 @@ export class Env implements IStoreValue {
|
|
|
129
131
|
getReturnStatus(): napi_status;
|
|
130
132
|
callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
|
|
131
133
|
callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
|
|
134
|
+
invokeFinalizerFromGC(finalizer: RefTracker): void;
|
|
135
|
+
checkGCAccess(): void;
|
|
132
136
|
enqueueFinalizer(finalizer: RefTracker): void;
|
|
133
137
|
dequeueFinalizer(finalizer: RefTracker): void;
|
|
134
138
|
deleteMe(): void;
|
|
@@ -276,17 +280,10 @@ export class Persistent<T> {
|
|
|
276
280
|
deref(): T | undefined;
|
|
277
281
|
}
|
|
278
282
|
|
|
279
|
-
export
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export class RefBase extends Finalizer {
|
|
283
|
-
static finalizeAll(list: RefTracker): void;
|
|
284
|
-
link(list: RefTracker): void;
|
|
285
|
-
unlink(): void;
|
|
283
|
+
export class RefBase extends TrackedFinalizer {
|
|
286
284
|
private _refcount;
|
|
287
285
|
private readonly _ownership;
|
|
288
286
|
constructor(envObject: Env, initial_refcount: uint32_t, ownership: number, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
|
|
289
|
-
dispose(): void;
|
|
290
287
|
data(): void_p;
|
|
291
288
|
ref(): uint32_t;
|
|
292
289
|
unref(): uint32_t;
|
|
@@ -340,6 +337,20 @@ export class Store<V extends IStoreValue> {
|
|
|
340
337
|
dispose(): void;
|
|
341
338
|
}
|
|
342
339
|
|
|
340
|
+
export interface TrackedFinalizer extends Finalizer, RefTracker {
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export class TrackedFinalizer extends Finalizer {
|
|
344
|
+
static finalizeAll(list: RefTracker): void;
|
|
345
|
+
link(list: RefTracker): void;
|
|
346
|
+
unlink(): void;
|
|
347
|
+
static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
|
|
348
|
+
protected constructor(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
|
|
349
|
+
dispose(): void;
|
|
350
|
+
finalize(): void;
|
|
351
|
+
protected finalizeCore(deleteMe: boolean): void;
|
|
352
|
+
}
|
|
353
|
+
|
|
343
354
|
export class TryCatch {
|
|
344
355
|
private _exception;
|
|
345
356
|
private _caught;
|
package/dist/emnapi.iife.js
CHANGED
|
@@ -242,7 +242,7 @@ var emnapi = (function (exports) {
|
|
|
242
242
|
catch (_) { }
|
|
243
243
|
return undefined;
|
|
244
244
|
})();
|
|
245
|
-
var version = "0.
|
|
245
|
+
var version = "0.43.1";
|
|
246
246
|
var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
|
|
247
247
|
var NODE_API_SUPPORTED_VERSION_MAX = 9 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
|
|
248
248
|
var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
|
|
@@ -545,53 +545,36 @@ var emnapi = (function (exports) {
|
|
|
545
545
|
return Finalizer;
|
|
546
546
|
}());
|
|
547
547
|
|
|
548
|
-
var
|
|
549
|
-
__extends(
|
|
550
|
-
function
|
|
548
|
+
var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
|
|
549
|
+
__extends(TrackedFinalizer, _super);
|
|
550
|
+
function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
551
551
|
var _this = _super.call(this, envObject, finalize_callback, finalize_data, finalize_hint) || this;
|
|
552
552
|
_this._next = null;
|
|
553
553
|
_this._prev = null;
|
|
554
|
-
_this._refcount = initial_refcount;
|
|
555
|
-
_this._ownership = ownership;
|
|
556
554
|
_this.link(!finalize_callback ? envObject.reflist : envObject.finalizing_reflist);
|
|
557
555
|
return _this;
|
|
558
556
|
}
|
|
559
|
-
|
|
557
|
+
TrackedFinalizer.finalizeAll = function (list) {
|
|
560
558
|
RefTracker.finalizeAll(list);
|
|
561
559
|
};
|
|
562
|
-
|
|
560
|
+
TrackedFinalizer.prototype.link = function (list) {
|
|
563
561
|
RefTracker.prototype.link.call(this, list);
|
|
564
562
|
};
|
|
565
|
-
|
|
563
|
+
TrackedFinalizer.prototype.unlink = function () {
|
|
566
564
|
RefTracker.prototype.unlink.call(this);
|
|
567
565
|
};
|
|
568
|
-
|
|
566
|
+
TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
567
|
+
return new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
568
|
+
};
|
|
569
|
+
TrackedFinalizer.prototype.dispose = function () {
|
|
569
570
|
this.unlink();
|
|
570
571
|
this.envObject.dequeueFinalizer(this);
|
|
571
572
|
_super.prototype.dispose.call(this);
|
|
572
573
|
};
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
};
|
|
576
|
-
RefBase.prototype.ref = function () {
|
|
577
|
-
return ++this._refcount;
|
|
578
|
-
};
|
|
579
|
-
RefBase.prototype.unref = function () {
|
|
580
|
-
if (this._refcount === 0) {
|
|
581
|
-
return 0;
|
|
582
|
-
}
|
|
583
|
-
return --this._refcount;
|
|
574
|
+
TrackedFinalizer.prototype.finalize = function () {
|
|
575
|
+
this.finalizeCore(true);
|
|
584
576
|
};
|
|
585
|
-
|
|
586
|
-
return this._refcount;
|
|
587
|
-
};
|
|
588
|
-
RefBase.prototype.ownership = function () {
|
|
589
|
-
return this._ownership;
|
|
590
|
-
};
|
|
591
|
-
RefBase.prototype.finalize = function () {
|
|
592
|
-
var ownership = this._ownership;
|
|
593
|
-
// Swap out the field finalize_callback so that it can not be accidentally
|
|
594
|
-
// called more than once.
|
|
577
|
+
TrackedFinalizer.prototype.finalizeCore = function (deleteMe) {
|
|
595
578
|
var finalize_callback = this._finalizeCallback;
|
|
596
579
|
var finalize_data = this._finalizeData;
|
|
597
580
|
var finalize_hint = this._finalizeHint;
|
|
@@ -609,16 +592,48 @@ var emnapi = (function (exports) {
|
|
|
609
592
|
error = err;
|
|
610
593
|
}
|
|
611
594
|
}
|
|
612
|
-
if (
|
|
595
|
+
if (deleteMe) {
|
|
613
596
|
this.dispose();
|
|
614
597
|
}
|
|
615
598
|
if (caught) {
|
|
616
599
|
throw error;
|
|
617
600
|
}
|
|
618
601
|
};
|
|
619
|
-
return
|
|
602
|
+
return TrackedFinalizer;
|
|
620
603
|
}(Finalizer));
|
|
621
604
|
|
|
605
|
+
var RefBase = /*#__PURE__*/ (function (_super) {
|
|
606
|
+
__extends(RefBase, _super);
|
|
607
|
+
function RefBase(envObject, initial_refcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
608
|
+
var _this = _super.call(this, envObject, finalize_callback, finalize_data, finalize_hint) || this;
|
|
609
|
+
_this._refcount = initial_refcount;
|
|
610
|
+
_this._ownership = ownership;
|
|
611
|
+
return _this;
|
|
612
|
+
}
|
|
613
|
+
RefBase.prototype.data = function () {
|
|
614
|
+
return this._finalizeData;
|
|
615
|
+
};
|
|
616
|
+
RefBase.prototype.ref = function () {
|
|
617
|
+
return ++this._refcount;
|
|
618
|
+
};
|
|
619
|
+
RefBase.prototype.unref = function () {
|
|
620
|
+
if (this._refcount === 0) {
|
|
621
|
+
return 0;
|
|
622
|
+
}
|
|
623
|
+
return --this._refcount;
|
|
624
|
+
};
|
|
625
|
+
RefBase.prototype.refCount = function () {
|
|
626
|
+
return this._refcount;
|
|
627
|
+
};
|
|
628
|
+
RefBase.prototype.ownership = function () {
|
|
629
|
+
return this._ownership;
|
|
630
|
+
};
|
|
631
|
+
RefBase.prototype.finalize = function () {
|
|
632
|
+
this.finalizeCore(this._ownership === 0 /* Ownership.kRuntime */);
|
|
633
|
+
};
|
|
634
|
+
return RefBase;
|
|
635
|
+
}(TrackedFinalizer));
|
|
636
|
+
|
|
622
637
|
function throwNodeApiVersionError(moduleName, moduleApiVersion) {
|
|
623
638
|
var errorMessage = "".concat(moduleName, " requires Node-API version ").concat(moduleApiVersion, ", but this version of Node.js only supports version ").concat(NODE_API_SUPPORTED_VERSION_MAX, " add-ons.");
|
|
624
639
|
throw new Error(errorMessage);
|
|
@@ -648,6 +663,7 @@ var emnapi = (function (exports) {
|
|
|
648
663
|
engineErrorCode: 0,
|
|
649
664
|
engineReserved: 0
|
|
650
665
|
};
|
|
666
|
+
this.inGcFinalizer = false;
|
|
651
667
|
this._bindingMap = new WeakMap();
|
|
652
668
|
this.id = 0;
|
|
653
669
|
}
|
|
@@ -724,6 +740,31 @@ var emnapi = (function (exports) {
|
|
|
724
740
|
this.ctx.closeScope(this, scope);
|
|
725
741
|
}
|
|
726
742
|
};
|
|
743
|
+
Env.prototype.invokeFinalizerFromGC = function (finalizer) {
|
|
744
|
+
if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
|
|
745
|
+
this.enqueueFinalizer(finalizer);
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
var saved = this.inGcFinalizer;
|
|
749
|
+
this.inGcFinalizer = true;
|
|
750
|
+
try {
|
|
751
|
+
finalizer.finalize();
|
|
752
|
+
}
|
|
753
|
+
finally {
|
|
754
|
+
this.inGcFinalizer = saved;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
Env.prototype.checkGCAccess = function () {
|
|
759
|
+
if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) {
|
|
760
|
+
this.abort('Finalizer is calling a function that may affect GC state.\n' +
|
|
761
|
+
'The finalizers are run directly from GC and must not affect GC ' +
|
|
762
|
+
'state.\n' +
|
|
763
|
+
'Use `node_api_post_finalizer` from inside of the finalizer to work ' +
|
|
764
|
+
'around this issue.\n' +
|
|
765
|
+
'It schedules the call as a new task in the event loop.');
|
|
766
|
+
}
|
|
767
|
+
};
|
|
727
768
|
/** @virtual */
|
|
728
769
|
Env.prototype.enqueueFinalizer = function (finalizer) {
|
|
729
770
|
if (this.pendingFinalizers.indexOf(finalizer) === -1) {
|
|
@@ -792,7 +833,7 @@ var emnapi = (function (exports) {
|
|
|
792
833
|
_super.prototype.deleteMe.call(this);
|
|
793
834
|
};
|
|
794
835
|
NodeEnv.prototype.canCallIntoJs = function () {
|
|
795
|
-
return this.ctx.canCallIntoJs();
|
|
836
|
+
return _super.prototype.canCallIntoJs.call(this) && this.ctx.canCallIntoJs();
|
|
796
837
|
};
|
|
797
838
|
NodeEnv.prototype.triggerFatalException = function (err) {
|
|
798
839
|
if (this.nodeBinding) {
|
|
@@ -818,7 +859,7 @@ var emnapi = (function (exports) {
|
|
|
818
859
|
}
|
|
819
860
|
var hasProcess = typeof process === 'object' && process !== null;
|
|
820
861
|
var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
|
|
821
|
-
if (!hasForceFlag && !enforceUncaughtExceptionPolicy) {
|
|
862
|
+
if (envObject.moduleApiVersion < NAPI_VERSION_EXPERIMENTAL && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
|
|
822
863
|
var warn = hasProcess && typeof process.emitWarning === 'function'
|
|
823
864
|
? process.emitWarning
|
|
824
865
|
: function (warning, type, code) {
|
|
@@ -1034,7 +1075,7 @@ var emnapi = (function (exports) {
|
|
|
1034
1075
|
|
|
1035
1076
|
function weakCallback(ref) {
|
|
1036
1077
|
ref.persistent.reset();
|
|
1037
|
-
ref.envObject.
|
|
1078
|
+
ref.envObject.invokeFinalizerFromGC(ref);
|
|
1038
1079
|
}
|
|
1039
1080
|
function canBeHeldWeakly(value) {
|
|
1040
1081
|
return value.isObject() || value.isFunction() || value.isSymbol();
|
|
@@ -1322,6 +1363,9 @@ var emnapi = (function (exports) {
|
|
|
1322
1363
|
Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
|
|
1323
1364
|
return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
|
|
1324
1365
|
};
|
|
1366
|
+
Context.prototype.createTrackedFinalizer = function (envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
1367
|
+
return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
1368
|
+
};
|
|
1325
1369
|
Context.prototype.getCurrentScope = function () {
|
|
1326
1370
|
return this.scopeStore.currentScope;
|
|
1327
1371
|
};
|
|
@@ -1414,6 +1458,7 @@ var emnapi = (function (exports) {
|
|
|
1414
1458
|
exports.Reference = Reference;
|
|
1415
1459
|
exports.ScopeStore = ScopeStore;
|
|
1416
1460
|
exports.Store = Store;
|
|
1461
|
+
exports.TrackedFinalizer = TrackedFinalizer;
|
|
1417
1462
|
exports.TryCatch = TryCatch;
|
|
1418
1463
|
exports.createContext = createContext;
|
|
1419
1464
|
exports.getDefaultContext = getDefaultContext;
|