@emnapi/runtime 1.2.0 → 1.3.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 +161 -109
- package/dist/emnapi.cjs.min.d.ts +73 -37
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.mts +73 -37
- package/dist/emnapi.d.ts +73 -37
- package/dist/emnapi.esm-bundler.js +184 -119
- package/dist/emnapi.iife.d.ts +73 -32
- package/dist/emnapi.iife.js +186 -120
- package/dist/emnapi.js +186 -120
- package/dist/emnapi.min.d.mts +73 -37
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +160 -109
- package/package.json +1 -1
package/dist/emnapi.iife.js
CHANGED
|
@@ -84,7 +84,7 @@ var emnapi = (function (exports) {
|
|
|
84
84
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
85
85
|
PERFORMANCE OF THIS SOFTWARE.
|
|
86
86
|
***************************************************************************** */
|
|
87
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
87
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
88
88
|
|
|
89
89
|
var extendStatics = function(d, b) {
|
|
90
90
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -246,7 +246,7 @@ var emnapi = (function (exports) {
|
|
|
246
246
|
catch (_) { }
|
|
247
247
|
return undefined;
|
|
248
248
|
})();
|
|
249
|
-
var version = "1.
|
|
249
|
+
var version = "1.3.1";
|
|
250
250
|
var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
|
|
251
251
|
var NODE_API_SUPPORTED_VERSION_MAX = 9 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
|
|
252
252
|
var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
|
|
@@ -288,6 +288,8 @@ var emnapi = (function (exports) {
|
|
|
288
288
|
return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
|
|
289
289
|
};
|
|
290
290
|
Handle.prototype.isBuffer = function (BufferConstructor) {
|
|
291
|
+
if (ArrayBuffer.isView(this.value))
|
|
292
|
+
return true;
|
|
291
293
|
BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer);
|
|
292
294
|
return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value);
|
|
293
295
|
};
|
|
@@ -499,6 +501,8 @@ var emnapi = (function (exports) {
|
|
|
499
501
|
this._prev = null;
|
|
500
502
|
}
|
|
501
503
|
/** @virtual */
|
|
504
|
+
RefTracker.prototype.dispose = function () { };
|
|
505
|
+
/** @virtual */
|
|
502
506
|
RefTracker.prototype.finalize = function () { };
|
|
503
507
|
RefTracker.prototype.link = function (list) {
|
|
504
508
|
this._prev = list;
|
|
@@ -535,17 +539,37 @@ var emnapi = (function (exports) {
|
|
|
535
539
|
this._finalizeCallback = _finalizeCallback;
|
|
536
540
|
this._finalizeData = _finalizeData;
|
|
537
541
|
this._finalizeHint = _finalizeHint;
|
|
542
|
+
this._makeDynCall_vppp = envObject.makeDynCall_vppp;
|
|
538
543
|
}
|
|
539
544
|
Finalizer.prototype.callback = function () { return this._finalizeCallback; };
|
|
540
545
|
Finalizer.prototype.data = function () { return this._finalizeData; };
|
|
541
546
|
Finalizer.prototype.hint = function () { return this._finalizeHint; };
|
|
547
|
+
Finalizer.prototype.resetEnv = function () {
|
|
548
|
+
this.envObject = undefined;
|
|
549
|
+
};
|
|
542
550
|
Finalizer.prototype.resetFinalizer = function () {
|
|
543
551
|
this._finalizeCallback = 0;
|
|
544
552
|
this._finalizeData = 0;
|
|
545
553
|
this._finalizeHint = 0;
|
|
546
554
|
};
|
|
555
|
+
Finalizer.prototype.callFinalizer = function () {
|
|
556
|
+
var finalize_callback = this._finalizeCallback;
|
|
557
|
+
var finalize_data = this._finalizeData;
|
|
558
|
+
var finalize_hint = this._finalizeHint;
|
|
559
|
+
this.resetFinalizer();
|
|
560
|
+
if (!finalize_callback)
|
|
561
|
+
return;
|
|
562
|
+
var fini = Number(finalize_callback);
|
|
563
|
+
if (!this.envObject) {
|
|
564
|
+
this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
547
570
|
Finalizer.prototype.dispose = function () {
|
|
548
571
|
this.envObject = undefined;
|
|
572
|
+
this._makeDynCall_vppp = undefined;
|
|
549
573
|
};
|
|
550
574
|
return Finalizer;
|
|
551
575
|
}());
|
|
@@ -553,91 +577,45 @@ var emnapi = (function (exports) {
|
|
|
553
577
|
var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
|
|
554
578
|
__extends(TrackedFinalizer, _super);
|
|
555
579
|
function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
556
|
-
var _this = _super.call(this
|
|
557
|
-
_this.
|
|
558
|
-
_this._prev = null;
|
|
559
|
-
_this.link(!finalize_callback ? envObject.reflist : envObject.finalizing_reflist);
|
|
580
|
+
var _this = _super.call(this) || this;
|
|
581
|
+
_this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
560
582
|
return _this;
|
|
561
583
|
}
|
|
562
|
-
TrackedFinalizer.finalizeAll = function (list) {
|
|
563
|
-
RefTracker.finalizeAll(list);
|
|
564
|
-
};
|
|
565
|
-
TrackedFinalizer.prototype.link = function (list) {
|
|
566
|
-
RefTracker.prototype.link.call(this, list);
|
|
567
|
-
};
|
|
568
|
-
TrackedFinalizer.prototype.unlink = function () {
|
|
569
|
-
RefTracker.prototype.unlink.call(this);
|
|
570
|
-
};
|
|
571
584
|
TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
572
|
-
|
|
585
|
+
var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
586
|
+
finalizer.link(envObject.finalizing_reflist);
|
|
587
|
+
return finalizer;
|
|
588
|
+
};
|
|
589
|
+
TrackedFinalizer.prototype.data = function () {
|
|
590
|
+
return this._finalizer.data();
|
|
573
591
|
};
|
|
574
592
|
TrackedFinalizer.prototype.dispose = function () {
|
|
593
|
+
if (!this._finalizer)
|
|
594
|
+
return;
|
|
575
595
|
this.unlink();
|
|
576
|
-
this.envObject.dequeueFinalizer(this);
|
|
596
|
+
this._finalizer.envObject.dequeueFinalizer(this);
|
|
597
|
+
this._finalizer.dispose();
|
|
598
|
+
this._finalizer = undefined;
|
|
577
599
|
_super.prototype.dispose.call(this);
|
|
578
600
|
};
|
|
579
601
|
TrackedFinalizer.prototype.finalize = function () {
|
|
580
|
-
this.finalizeCore(true);
|
|
581
|
-
};
|
|
582
|
-
TrackedFinalizer.prototype.finalizeCore = function (deleteMe) {
|
|
583
|
-
var finalize_callback = this._finalizeCallback;
|
|
584
|
-
var finalize_data = this._finalizeData;
|
|
585
|
-
var finalize_hint = this._finalizeHint;
|
|
586
|
-
this.resetFinalizer();
|
|
587
602
|
this.unlink();
|
|
588
603
|
var error;
|
|
589
604
|
var caught = false;
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
try {
|
|
593
|
-
this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
|
|
594
|
-
}
|
|
595
|
-
catch (err) {
|
|
596
|
-
caught = true;
|
|
597
|
-
error = err;
|
|
598
|
-
}
|
|
605
|
+
try {
|
|
606
|
+
this._finalizer.callFinalizer();
|
|
599
607
|
}
|
|
600
|
-
|
|
601
|
-
|
|
608
|
+
catch (err) {
|
|
609
|
+
caught = true;
|
|
610
|
+
error = err;
|
|
602
611
|
}
|
|
612
|
+
this.dispose();
|
|
603
613
|
if (caught) {
|
|
604
614
|
throw error;
|
|
605
615
|
}
|
|
606
616
|
};
|
|
607
617
|
return TrackedFinalizer;
|
|
608
|
-
}(
|
|
609
|
-
|
|
610
|
-
var RefBase = /*#__PURE__*/ (function (_super) {
|
|
611
|
-
__extends(RefBase, _super);
|
|
612
|
-
function RefBase(envObject, initial_refcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
613
|
-
var _this = _super.call(this, envObject, finalize_callback, finalize_data, finalize_hint) || this;
|
|
614
|
-
_this._refcount = initial_refcount;
|
|
615
|
-
_this._ownership = ownership;
|
|
616
|
-
return _this;
|
|
617
|
-
}
|
|
618
|
-
RefBase.prototype.data = function () {
|
|
619
|
-
return this._finalizeData;
|
|
620
|
-
};
|
|
621
|
-
RefBase.prototype.ref = function () {
|
|
622
|
-
return ++this._refcount;
|
|
623
|
-
};
|
|
624
|
-
RefBase.prototype.unref = function () {
|
|
625
|
-
if (this._refcount === 0) {
|
|
626
|
-
return 0;
|
|
627
|
-
}
|
|
628
|
-
return --this._refcount;
|
|
629
|
-
};
|
|
630
|
-
RefBase.prototype.refCount = function () {
|
|
631
|
-
return this._refcount;
|
|
632
|
-
};
|
|
633
|
-
RefBase.prototype.ownership = function () {
|
|
634
|
-
return this._ownership;
|
|
635
|
-
};
|
|
636
|
-
RefBase.prototype.finalize = function () {
|
|
637
|
-
this.finalizeCore(this._ownership === 0 /* Ownership.kRuntime */);
|
|
638
|
-
};
|
|
639
|
-
return RefBase;
|
|
640
|
-
}(TrackedFinalizer));
|
|
618
|
+
}(RefTracker));
|
|
641
619
|
|
|
642
620
|
function throwNodeApiVersionError(moduleName, moduleApiVersion) {
|
|
643
621
|
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.");
|
|
@@ -733,18 +711,6 @@ var emnapi = (function (exports) {
|
|
|
733
711
|
}
|
|
734
712
|
return r;
|
|
735
713
|
};
|
|
736
|
-
/** @virtual */
|
|
737
|
-
Env.prototype.callFinalizer = function (cb, data, hint) {
|
|
738
|
-
var f = this.makeDynCall_vppp(cb);
|
|
739
|
-
var env = this.id;
|
|
740
|
-
var scope = this.ctx.openScope(this);
|
|
741
|
-
try {
|
|
742
|
-
this.callIntoModule(function () { f(env, data, hint); });
|
|
743
|
-
}
|
|
744
|
-
finally {
|
|
745
|
-
this.ctx.closeScope(this, scope);
|
|
746
|
-
}
|
|
747
|
-
};
|
|
748
714
|
Env.prototype.invokeFinalizerFromGC = function (finalizer) {
|
|
749
715
|
if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
|
|
750
716
|
this.enqueueFinalizer(finalizer);
|
|
@@ -785,8 +751,8 @@ var emnapi = (function (exports) {
|
|
|
785
751
|
};
|
|
786
752
|
/** @virtual */
|
|
787
753
|
Env.prototype.deleteMe = function () {
|
|
788
|
-
|
|
789
|
-
|
|
754
|
+
RefTracker.finalizeAll(this.finalizing_reflist);
|
|
755
|
+
RefTracker.finalizeAll(this.reflist);
|
|
790
756
|
this.tryCatch.extractException();
|
|
791
757
|
this.ctx.envStore.remove(this.id);
|
|
792
758
|
};
|
|
@@ -794,6 +760,8 @@ var emnapi = (function (exports) {
|
|
|
794
760
|
if (this.id === 0)
|
|
795
761
|
return;
|
|
796
762
|
this.deleteMe();
|
|
763
|
+
this.finalizing_reflist.dispose();
|
|
764
|
+
this.reflist.dispose();
|
|
797
765
|
this.id = 0;
|
|
798
766
|
};
|
|
799
767
|
Env.prototype.initObjectBinding = function (value) {
|
|
@@ -815,7 +783,7 @@ var emnapi = (function (exports) {
|
|
|
815
783
|
if (this.instanceData) {
|
|
816
784
|
this.instanceData.dispose();
|
|
817
785
|
}
|
|
818
|
-
this.instanceData =
|
|
786
|
+
this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
|
|
819
787
|
};
|
|
820
788
|
Env.prototype.getInstanceData = function () {
|
|
821
789
|
return this.instanceData ? this.instanceData.data() : 0;
|
|
@@ -1078,69 +1046,82 @@ var emnapi = (function (exports) {
|
|
|
1078
1046
|
return Persistent;
|
|
1079
1047
|
}());
|
|
1080
1048
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1049
|
+
exports.ReferenceOwnership = void 0;
|
|
1050
|
+
(function (ReferenceOwnership) {
|
|
1051
|
+
ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
|
|
1052
|
+
ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
|
|
1053
|
+
})(exports.ReferenceOwnership || (exports.ReferenceOwnership = {}));
|
|
1085
1054
|
function canBeHeldWeakly(value) {
|
|
1086
1055
|
return value.isObject() || value.isFunction() || value.isSymbol();
|
|
1087
1056
|
}
|
|
1088
1057
|
var Reference = /*#__PURE__*/ (function (_super) {
|
|
1089
1058
|
__extends(Reference, _super);
|
|
1090
|
-
function Reference(envObject, initialRefcount, ownership
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1059
|
+
function Reference(envObject, handle_id, initialRefcount, ownership) {
|
|
1060
|
+
var _this = _super.call(this) || this;
|
|
1061
|
+
_this.envObject = envObject;
|
|
1062
|
+
_this._refcount = initialRefcount;
|
|
1063
|
+
_this._ownership = ownership;
|
|
1064
|
+
var handle = envObject.ctx.handleStore.get(handle_id);
|
|
1065
|
+
_this.canBeWeak = canBeHeldWeakly(handle);
|
|
1066
|
+
_this.persistent = new Persistent(handle.value);
|
|
1095
1067
|
_this.id = 0;
|
|
1068
|
+
if (initialRefcount === 0) {
|
|
1069
|
+
_this._setWeak();
|
|
1070
|
+
}
|
|
1096
1071
|
return _this;
|
|
1097
1072
|
}
|
|
1098
|
-
Reference.
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
var ref = new Reference(envObject, initialRefcount, ownership
|
|
1073
|
+
Reference.weakCallback = function (ref) {
|
|
1074
|
+
ref.persistent.reset();
|
|
1075
|
+
ref.invokeFinalizerFromGC();
|
|
1076
|
+
};
|
|
1077
|
+
Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
|
|
1078
|
+
var ref = new Reference(envObject, handle_id, initialRefcount, ownership);
|
|
1104
1079
|
envObject.ctx.refStore.add(ref);
|
|
1105
|
-
ref.
|
|
1106
|
-
ref.persistent = new Persistent(handle.value);
|
|
1107
|
-
if (initialRefcount === 0) {
|
|
1108
|
-
ref._setWeak();
|
|
1109
|
-
}
|
|
1080
|
+
ref.link(envObject.reflist);
|
|
1110
1081
|
return ref;
|
|
1111
1082
|
};
|
|
1112
1083
|
Reference.prototype.ref = function () {
|
|
1113
1084
|
if (this.persistent.isEmpty()) {
|
|
1114
1085
|
return 0;
|
|
1115
1086
|
}
|
|
1116
|
-
|
|
1117
|
-
if (count === 1 && this.canBeWeak) {
|
|
1087
|
+
if (++this._refcount === 1 && this.canBeWeak) {
|
|
1118
1088
|
this.persistent.clearWeak();
|
|
1119
1089
|
}
|
|
1120
|
-
return
|
|
1090
|
+
return this._refcount;
|
|
1121
1091
|
};
|
|
1122
1092
|
Reference.prototype.unref = function () {
|
|
1123
|
-
if (this.persistent.isEmpty()) {
|
|
1093
|
+
if (this.persistent.isEmpty() || this._refcount === 0) {
|
|
1124
1094
|
return 0;
|
|
1125
1095
|
}
|
|
1126
|
-
|
|
1127
|
-
var refcount = _super.prototype.unref.call(this);
|
|
1128
|
-
if (oldRefcount === 1 && refcount === 0) {
|
|
1096
|
+
if (--this._refcount === 0) {
|
|
1129
1097
|
this._setWeak();
|
|
1130
1098
|
}
|
|
1131
|
-
return
|
|
1099
|
+
return this._refcount;
|
|
1132
1100
|
};
|
|
1133
|
-
Reference.prototype.get = function () {
|
|
1101
|
+
Reference.prototype.get = function (envObject) {
|
|
1102
|
+
if (envObject === void 0) { envObject = this.envObject; }
|
|
1134
1103
|
if (this.persistent.isEmpty()) {
|
|
1135
1104
|
return 0;
|
|
1136
1105
|
}
|
|
1137
1106
|
var obj = this.persistent.deref();
|
|
1138
|
-
var handle =
|
|
1107
|
+
var handle = envObject.ensureHandle(obj);
|
|
1139
1108
|
return handle.id;
|
|
1140
1109
|
};
|
|
1110
|
+
/** @virtual */
|
|
1111
|
+
Reference.prototype.resetFinalizer = function () { };
|
|
1112
|
+
/** @virtual */
|
|
1113
|
+
Reference.prototype.data = function () { return 0; };
|
|
1114
|
+
Reference.prototype.refcount = function () { return this._refcount; };
|
|
1115
|
+
Reference.prototype.ownership = function () { return this._ownership; };
|
|
1116
|
+
/** @virtual */
|
|
1117
|
+
Reference.prototype.callUserFinalizer = function () { };
|
|
1118
|
+
/** @virtual */
|
|
1119
|
+
Reference.prototype.invokeFinalizerFromGC = function () {
|
|
1120
|
+
this.finalize();
|
|
1121
|
+
};
|
|
1141
1122
|
Reference.prototype._setWeak = function () {
|
|
1142
1123
|
if (this.canBeWeak) {
|
|
1143
|
-
this.persistent.setWeak(this, weakCallback);
|
|
1124
|
+
this.persistent.setWeak(this, Reference.weakCallback);
|
|
1144
1125
|
}
|
|
1145
1126
|
else {
|
|
1146
1127
|
this.persistent.reset();
|
|
@@ -1148,18 +1129,78 @@ var emnapi = (function (exports) {
|
|
|
1148
1129
|
};
|
|
1149
1130
|
Reference.prototype.finalize = function () {
|
|
1150
1131
|
this.persistent.reset();
|
|
1151
|
-
|
|
1132
|
+
var deleteMe = this._ownership === exports.ReferenceOwnership.kRuntime;
|
|
1133
|
+
this.unlink();
|
|
1134
|
+
this.callUserFinalizer();
|
|
1135
|
+
if (deleteMe) {
|
|
1136
|
+
this.dispose();
|
|
1137
|
+
}
|
|
1152
1138
|
};
|
|
1153
1139
|
Reference.prototype.dispose = function () {
|
|
1154
1140
|
if (this.id === 0)
|
|
1155
1141
|
return;
|
|
1142
|
+
this.unlink();
|
|
1156
1143
|
this.persistent.reset();
|
|
1157
1144
|
this.envObject.ctx.refStore.remove(this.id);
|
|
1158
1145
|
_super.prototype.dispose.call(this);
|
|
1146
|
+
this.envObject = undefined;
|
|
1159
1147
|
this.id = 0;
|
|
1160
1148
|
};
|
|
1161
1149
|
return Reference;
|
|
1162
|
-
}(
|
|
1150
|
+
}(RefTracker));
|
|
1151
|
+
var ReferenceWithData = /*#__PURE__*/ (function (_super) {
|
|
1152
|
+
__extends(ReferenceWithData, _super);
|
|
1153
|
+
function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) {
|
|
1154
|
+
var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
|
|
1155
|
+
_this._data = _data;
|
|
1156
|
+
return _this;
|
|
1157
|
+
}
|
|
1158
|
+
ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) {
|
|
1159
|
+
var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
|
|
1160
|
+
envObject.ctx.refStore.add(reference);
|
|
1161
|
+
reference.link(envObject.reflist);
|
|
1162
|
+
return reference;
|
|
1163
|
+
};
|
|
1164
|
+
ReferenceWithData.prototype.data = function () {
|
|
1165
|
+
return this._data;
|
|
1166
|
+
};
|
|
1167
|
+
return ReferenceWithData;
|
|
1168
|
+
}(Reference));
|
|
1169
|
+
var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) {
|
|
1170
|
+
__extends(ReferenceWithFinalizer, _super);
|
|
1171
|
+
function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1172
|
+
var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
|
|
1173
|
+
_this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
1174
|
+
return _this;
|
|
1175
|
+
}
|
|
1176
|
+
ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1177
|
+
var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
|
|
1178
|
+
envObject.ctx.refStore.add(reference);
|
|
1179
|
+
reference.link(envObject.finalizing_reflist);
|
|
1180
|
+
return reference;
|
|
1181
|
+
};
|
|
1182
|
+
ReferenceWithFinalizer.prototype.resetFinalizer = function () {
|
|
1183
|
+
this._finalizer.resetFinalizer();
|
|
1184
|
+
};
|
|
1185
|
+
ReferenceWithFinalizer.prototype.data = function () {
|
|
1186
|
+
return this._finalizer.data();
|
|
1187
|
+
};
|
|
1188
|
+
ReferenceWithFinalizer.prototype.callUserFinalizer = function () {
|
|
1189
|
+
this._finalizer.callFinalizer();
|
|
1190
|
+
};
|
|
1191
|
+
ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () {
|
|
1192
|
+
this._finalizer.envObject.invokeFinalizerFromGC(this);
|
|
1193
|
+
};
|
|
1194
|
+
ReferenceWithFinalizer.prototype.dispose = function () {
|
|
1195
|
+
if (!this._finalizer)
|
|
1196
|
+
return;
|
|
1197
|
+
this._finalizer.envObject.dequeueFinalizer(this);
|
|
1198
|
+
this._finalizer.dispose();
|
|
1199
|
+
_super.prototype.dispose.call(this);
|
|
1200
|
+
this._finalizer = undefined;
|
|
1201
|
+
};
|
|
1202
|
+
return ReferenceWithFinalizer;
|
|
1203
|
+
}(Reference));
|
|
1163
1204
|
|
|
1164
1205
|
var Deferred = /*#__PURE__*/ (function () {
|
|
1165
1206
|
function Deferred(ctx, value) {
|
|
@@ -1316,6 +1357,7 @@ var emnapi = (function (exports) {
|
|
|
1316
1357
|
var _this = this;
|
|
1317
1358
|
this._isStopping = false;
|
|
1318
1359
|
this._canCallIntoJs = true;
|
|
1360
|
+
this._suppressDestroy = false;
|
|
1319
1361
|
this.envStore = new Store();
|
|
1320
1362
|
this.scopeStore = new ScopeStore();
|
|
1321
1363
|
this.refStore = new Store();
|
|
@@ -1337,10 +1379,23 @@ var emnapi = (function (exports) {
|
|
|
1337
1379
|
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
1338
1380
|
this.refCounter = new NodejsWaitingRequestCounter();
|
|
1339
1381
|
process.once('beforeExit', function () {
|
|
1340
|
-
_this.
|
|
1382
|
+
if (!_this._suppressDestroy) {
|
|
1383
|
+
_this.destroy();
|
|
1384
|
+
}
|
|
1341
1385
|
});
|
|
1342
1386
|
}
|
|
1343
1387
|
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Suppress the destroy on `beforeExit` event in Node.js.
|
|
1390
|
+
* Call this method if you want to keep the context and
|
|
1391
|
+
* all associated {@link Env | Env} alive,
|
|
1392
|
+
* this also means that cleanup hooks will not be called.
|
|
1393
|
+
* After call this method, you should call
|
|
1394
|
+
* {@link Context.destroy | `Context.prototype.destroy`} method manually.
|
|
1395
|
+
*/
|
|
1396
|
+
Context.prototype.suppressDestroy = function () {
|
|
1397
|
+
this._suppressDestroy = true;
|
|
1398
|
+
};
|
|
1344
1399
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1345
1400
|
Context.prototype.getRuntimeVersions = function () {
|
|
1346
1401
|
return {
|
|
@@ -1356,11 +1411,17 @@ var emnapi = (function (exports) {
|
|
|
1356
1411
|
Context.prototype.createNotSupportBufferError = function (api, message) {
|
|
1357
1412
|
return new NotSupportBufferError(api, message);
|
|
1358
1413
|
};
|
|
1359
|
-
Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership
|
|
1414
|
+
Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) {
|
|
1415
|
+
return Reference.create(envObject, handle_id, initialRefcount, ownership);
|
|
1416
|
+
};
|
|
1417
|
+
Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) {
|
|
1418
|
+
return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
|
|
1419
|
+
};
|
|
1420
|
+
Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1360
1421
|
if (finalize_callback === void 0) { finalize_callback = 0; }
|
|
1361
1422
|
if (finalize_data === void 0) { finalize_data = 0; }
|
|
1362
1423
|
if (finalize_hint === void 0) { finalize_hint = 0; }
|
|
1363
|
-
return
|
|
1424
|
+
return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
|
|
1364
1425
|
};
|
|
1365
1426
|
Context.prototype.createDeferred = function (value) {
|
|
1366
1427
|
return Deferred.create(this, value);
|
|
@@ -1421,6 +1482,10 @@ var emnapi = (function (exports) {
|
|
|
1421
1482
|
Context.prototype.canCallIntoJs = function () {
|
|
1422
1483
|
return this._canCallIntoJs && !this._isStopping;
|
|
1423
1484
|
};
|
|
1485
|
+
/**
|
|
1486
|
+
* Destroy the context and call cleanup hooks.
|
|
1487
|
+
* Associated {@link Env | Env} will be destroyed.
|
|
1488
|
+
*/
|
|
1424
1489
|
Context.prototype.destroy = function () {
|
|
1425
1490
|
this.setStopping(true);
|
|
1426
1491
|
this.setCanCallIntoJs(false);
|
|
@@ -1458,9 +1523,10 @@ var emnapi = (function (exports) {
|
|
|
1458
1523
|
exports.NotSupportBufferError = NotSupportBufferError;
|
|
1459
1524
|
exports.NotSupportWeakRefError = NotSupportWeakRefError;
|
|
1460
1525
|
exports.Persistent = Persistent;
|
|
1461
|
-
exports.RefBase = RefBase;
|
|
1462
1526
|
exports.RefTracker = RefTracker;
|
|
1463
1527
|
exports.Reference = Reference;
|
|
1528
|
+
exports.ReferenceWithData = ReferenceWithData;
|
|
1529
|
+
exports.ReferenceWithFinalizer = ReferenceWithFinalizer;
|
|
1464
1530
|
exports.ScopeStore = ScopeStore;
|
|
1465
1531
|
exports.Store = Store;
|
|
1466
1532
|
exports.TrackedFinalizer = TrackedFinalizer;
|