@emnapi/runtime 0.38.2 → 0.38.3
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 +42 -26
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.ts +5 -1
- package/dist/emnapi.esm-bundler.js +42 -26
- package/dist/emnapi.iife.d.ts +5 -1
- package/dist/emnapi.iife.js +42 -26
- package/dist/emnapi.js +42 -26
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +42 -26
- package/index.js +1 -1
- package/package.json +1 -1
package/dist/emnapi.cjs.js
CHANGED
|
@@ -170,19 +170,6 @@ const supportBigInt = typeof BigInt !== 'undefined';
|
|
|
170
170
|
function isReferenceType(v) {
|
|
171
171
|
return (typeof v === 'object' && v !== null) || typeof v === 'function';
|
|
172
172
|
}
|
|
173
|
-
const _setImmediate = typeof setImmediate === 'function'
|
|
174
|
-
? setImmediate
|
|
175
|
-
: function (f) {
|
|
176
|
-
if (typeof f !== 'function')
|
|
177
|
-
return;
|
|
178
|
-
let channel = new MessageChannel();
|
|
179
|
-
channel.port1.onmessage = function () {
|
|
180
|
-
channel.port1.onmessage = null;
|
|
181
|
-
channel = undefined;
|
|
182
|
-
f();
|
|
183
|
-
};
|
|
184
|
-
channel.port2.postMessage(null);
|
|
185
|
-
};
|
|
186
173
|
const _require = (function () {
|
|
187
174
|
let nativeRequire;
|
|
188
175
|
if (typeof __webpack_public_path__ !== 'undefined') {
|
|
@@ -197,15 +184,43 @@ const _require = (function () {
|
|
|
197
184
|
}
|
|
198
185
|
return nativeRequire;
|
|
199
186
|
})();
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
})();
|
|
187
|
+
const _MessageChannel = typeof MessageChannel === 'function'
|
|
188
|
+
? MessageChannel
|
|
189
|
+
: (function () {
|
|
190
|
+
try {
|
|
191
|
+
return _require('worker_threads').MessageChannel;
|
|
192
|
+
}
|
|
193
|
+
catch (_) { }
|
|
194
|
+
return undefined;
|
|
195
|
+
})();
|
|
196
|
+
const _setImmediate = typeof setImmediate === 'function'
|
|
197
|
+
? setImmediate
|
|
198
|
+
: function (callback) {
|
|
199
|
+
if (typeof callback !== 'function') {
|
|
200
|
+
throw new TypeError('The "callback" argument must be of type function');
|
|
201
|
+
}
|
|
202
|
+
if (_MessageChannel) {
|
|
203
|
+
let channel = new _MessageChannel();
|
|
204
|
+
channel.port1.onmessage = function () {
|
|
205
|
+
channel.port1.onmessage = null;
|
|
206
|
+
channel = undefined;
|
|
207
|
+
callback();
|
|
208
|
+
};
|
|
209
|
+
channel.port2.postMessage(null);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
setTimeout(callback, 0);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const _Buffer = typeof Buffer === 'function'
|
|
216
|
+
? Buffer
|
|
217
|
+
: (function () {
|
|
218
|
+
try {
|
|
219
|
+
return _require('buffer').Buffer;
|
|
220
|
+
}
|
|
221
|
+
catch (_) { }
|
|
222
|
+
return undefined;
|
|
223
|
+
})();
|
|
209
224
|
|
|
210
225
|
class Handle {
|
|
211
226
|
constructor(id, value) {
|
|
@@ -250,7 +265,7 @@ class Handle {
|
|
|
250
265
|
return !this.isEmpty() && (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
|
|
251
266
|
}
|
|
252
267
|
isBuffer() {
|
|
253
|
-
return !this.isEmpty() && typeof
|
|
268
|
+
return !this.isEmpty() && typeof _Buffer === 'function' && _Buffer.isBuffer(this.value);
|
|
254
269
|
}
|
|
255
270
|
isDataView() {
|
|
256
271
|
return !this.isEmpty() && (this.value instanceof DataView);
|
|
@@ -1014,7 +1029,7 @@ class CleanupQueue {
|
|
|
1014
1029
|
}
|
|
1015
1030
|
class NodejsWaitingRequestCounter {
|
|
1016
1031
|
constructor() {
|
|
1017
|
-
this.refHandle = new
|
|
1032
|
+
this.refHandle = new _MessageChannel().port1;
|
|
1018
1033
|
this.count = 0;
|
|
1019
1034
|
}
|
|
1020
1035
|
increase() {
|
|
@@ -1048,7 +1063,8 @@ class Context {
|
|
|
1048
1063
|
supportNewFunction,
|
|
1049
1064
|
canSetFunctionName,
|
|
1050
1065
|
setImmediate: _setImmediate,
|
|
1051
|
-
Buffer
|
|
1066
|
+
Buffer: _Buffer,
|
|
1067
|
+
MessageChannel: _MessageChannel
|
|
1052
1068
|
};
|
|
1053
1069
|
this.cleanupQueue = new CleanupQueue();
|
|
1054
1070
|
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
@@ -1132,7 +1148,7 @@ function getDefaultContext() {
|
|
|
1132
1148
|
return defaultContext;
|
|
1133
1149
|
}
|
|
1134
1150
|
|
|
1135
|
-
const version = "0.38.
|
|
1151
|
+
const version = "0.38.3";
|
|
1136
1152
|
|
|
1137
1153
|
exports.CallbackInfo = CallbackInfo;
|
|
1138
1154
|
exports.CallbackInfoStack = CallbackInfoStack;
|
package/dist/emnapi.cjs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:!0});class e{constructor(e,t,s,i,r){this.parent=e,this.thiz=t,this.data=s,this.args=i,this.fn=r}getNewTarget(e){const t=this.thiz;return null==t||null==t.constructor?0:t instanceof this.fn?e.ensureHandleId(t.constructor):0}}class t{constructor(){this.current=null}pop(){const e=this.current;null!==e&&(this.current=e.parent)}push(t,s,i,r){const n=new e(this.current,t,s,i,r);return this.current=n,n}dispose(){this.current=null}}class s{constructor(e){this._values=[void 0],this._values.length=e,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=Math.ceil(1.5*e))}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}class i extends s{constructor(){super(2)}}const r=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),n=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&r)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}(),o=new Error;class a{constructor(){this._exception=o}hasCaught(){return this._exception!==o}exception(){return this._exception}setError(e){this._exception=e}reset(){this._exception=o}extractException(){const e=this._exception;return this.reset(),e}}const u=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),c="object"==typeof Reflect,l="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),p="undefined"!=typeof BigInt;function f(e){return"object"==typeof e&&null!==e||"function"==typeof e}const d="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)return;let t=new MessageChannel;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)},_=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),v=function(){if("function"==typeof n.Buffer)return n.Buffer;try{return _("buffer").Buffer}catch(e){}}();class y{constructor(e,t){this.id=e,this.value=t}init(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isEmpty(){return 0===this.id}isNumber(){return!this.isEmpty()&&"number"==typeof this.value}isBigInt(){return!this.isEmpty()&&"bigint"==typeof this.value}isString(){return!this.isEmpty()&&"string"==typeof this.value}isFunction(){return!this.isEmpty()&&"function"==typeof this.value}isExternal(){return!this.isEmpty()&&f(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return!this.isEmpty()&&"object"==typeof this.value&&null!==this.value}isArray(){return!this.isEmpty()&&Array.isArray(this.value)}isArrayBuffer(){return!this.isEmpty()&&this.value instanceof ArrayBuffer}isTypedArray(){return!this.isEmpty()&&ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(){return!this.isEmpty()&&"function"==typeof v&&v.isBuffer(this.value)}isDataView(){return!this.isEmpty()&&this.value instanceof DataView}isDate(){return!this.isEmpty()&&this.value instanceof Date}isPromise(){return!this.isEmpty()&&this.value instanceof Promise}isBoolean(){return!this.isEmpty()&&"boolean"==typeof this.value}isUndefined(){return!this.isEmpty()&&void 0===this.value}isSymbol(){return!this.isEmpty()&&"symbol"==typeof this.value}isNull(){return!this.isEmpty()&&null===this.value}dispose(){0!==this.id&&(this.id=0,this.value=void 0)}}class g extends y{constructor(e,t){super(e,t)}dispose(){}}function x(){Object.setPrototypeOf(this,null)}x.prototype=null;class b{constructor(){this._values=[void 0,b.UNDEFINED,b.NULL,b.FALSE,b.TRUE,b.GLOBAL],this._next=b.MIN_ID}push(e){let t;const s=this._next,i=this._values;return s<i.length?(t=i[s],t.init(s,e)):(t=new y(s,e),i[s]=t),this._next++,t}erase(e,t){this._next=e;const s=this._values;for(let i=e;i<t;++i)s[i].dispose()}get(e){return this._values[e]}swap(e,t){const s=this._values,i=s[e];s[e]=s[t],s[e].id=Number(e),s[t]=i,i.id=Number(t)}dispose(){this._values.length=b.MIN_ID,this._next=b.MIN_ID}}b.UNDEFINED=new g(1,void 0),b.NULL=new g(2,null),b.FALSE=new g(3,!1),b.TRUE=new g(4,!0),b.GLOBAL=new g(5,n),b.MIN_ID=6;class S{constructor(e,t,s,i,r=i){this.handleStore=e,this.id=t,this.parent=s,this.child=null,null!==s&&(s.child=this),this.start=i,this.end=r,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const s=new x,i=e.ctx.handleStore.push(s);return e.initObjectBinding(s).data=t,this.end++,i}dispose(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class w{constructor(){this._rootScope=new S(null,0,null,1,b.MIN_ID),this.currentScope=this._rootScope}get(e){e=Number(e);let t=this.currentScope;for(;t!==this._rootScope;){if(t.id===e)return t;t=t.parent}}openScope(e){const t=this.currentScope;let s=t.child;return null!==s?(s.start=s.end=t.end,s._escapeCalled=!1):s=new S(e.ctx.handleStore,t.id+1,t,t.end),this.currentScope=s,e.openHandleScopes++,s}closeScope(e){if(0===e.openHandleScopes)return;const t=this.currentScope;this.currentScope=t.parent,t.dispose(),e.openHandleScopes--}dispose(){let e=this.currentScope;for(;null!==e;){e.handleStore=null,e.id=0,e.parent=null,e.start=b.MIN_ID,e.end=b.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class m extends s{constructor(){super(8)}}class k extends s{constructor(){super(8)}}class E{constructor(){this._next=null,this._prev=null}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class z{constructor(e,t=0,s=0,i=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=s,this._finalizeHint=i}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}dispose(){this.envObject=void 0}}class C extends z{constructor(e,t,s,i,r,n){super(e,i,r,n),this._next=null,this._prev=null,this._refcount=t,this._ownership=s,this.link(i?e.finalizing_reflist:e.reflist)}static finalizeAll(e){E.finalizeAll(e)}link(e){E.prototype.link.call(this,e)}unlink(){E.prototype.unlink.call(this)}dispose(){this.unlink(),this.envObject.dequeueFinalizer(this),super.dispose()}data(){return this._finalizeData}ref(){return++this._refcount}unref(){return 0===this._refcount?0:--this._refcount}refCount(){return this._refcount}ownership(){return this._ownership}finalize(){const e=this._ownership,t=this._finalizeCallback,s=this._finalizeData,i=this._finalizeHint;let r;this.resetFinalizer(),this.unlink();let n=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,s,i)}catch(e){n=!0,r=e}}if(0===e&&this.dispose(),n)throw r}}class D{constructor(e,t,s){this.ctx=e,this.makeDynCall_vppp=t,this.makeDynCall_vp=s,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new a,this.refs=1,this.reflist=new E,this.finalizing_reflist=new E,this.destructing=!1,this.finalizationScheduled=!1,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}static create(e,t,s){const i=new D(e,t,s);return e.envStore.add(i),e.addCleanupHook(i,(()=>{i.unref()}),0),i}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return e.errorCode=0,e.engineErrorCode=0,e.engineReserved=0,0}setLastError(e,t=0,s=0){const i=this.lastError;return i.errorCode=e,i.engineErrorCode=t,i.engineReserved=s,e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e){this.clearLastError();const t=e(this);if(this.tryCatch.hasCaught()){throw this.tryCatch.extractException()}return t}callFinalizer(e,t,s){const i=this.makeDynCall_vppp(e),r=this.id,n=this.ctx.openScope(this);try{this.callIntoModule((()=>{i(r,t,s)}))}finally{this.ctx.closeScope(this,n)}}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),d((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}dispose(){0!==this.id&&(this.destructing=!0,this.drainFinalizerQueue(),C.finalizeAll(this.finalizing_reflist),C.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null,data:0};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,s){this.instanceData&&this.instanceData.dispose(),this.instanceData=new C(this,0,0,t,e,s)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class H extends Error{constructor(e){super(e);const t=new.target,s=t.prototype;if(!(this instanceof H)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,s):this.__proto__=s,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class O extends H{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(O.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class F extends H{constructor(e,t){super(`${e}: The current runtime does not support "BigInt".${t?` ${t}`:""}`)}}Object.defineProperty(F.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});class I extends H{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(I.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class N{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class j{constructor(e){this._ref=new N(e)}setWeak(e,t){if(!l||void 0===this._ref||this._ref instanceof WeakRef)return;const s=this._ref.deref();try{j._registry.register(s,this,this);const i=new WeakRef(s);this._ref.dispose(),this._ref=i,this._param=e,this._callback=t}catch(e){}}clearWeak(){if(l&&void 0!==this._ref&&this._ref instanceof WeakRef){try{j._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new N(e)}}reset(){if(l)try{j._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof N&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}function B(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}j._registry=l?new FinalizationRegistry((e=>{e._ref=void 0;const t=e._callback,s=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(s)})):void 0;class R extends C{constructor(e,t,s,i=0,r=0,n=0){super(e,t>>>0,s,i,r,n),this.id=0}static create(e,t,s,i,r=0,n=0,o=0){const a=e.ctx.handleStore.get(t),u=new R(e,s,i,r,n,o);return e.ctx.refStore.add(u),u.persistent=new j(a.value),0===s&&u._setWeak(),u}ref(){if(this.persistent.isEmpty())return 0;const e=super.ref();if(1===e){this.persistent.deref()&&this.persistent.clearWeak()}return e}unref(){if(this.persistent.isEmpty())return 0;const e=this.refCount(),t=super.unref();if(1===e&&0===t){this.persistent.deref()&&this._setWeak()}return t}get(){const e=this.persistent.deref();if(e){return this.envObject.ensureHandle(e).id}return 0}_setWeak(){this.persistent.setWeak(this,B)}finalize(){this.persistent.reset(),super.finalize()}dispose(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.id=0)}}class L{constructor(e,t){this.id=0,this.ctx=e,this.value=t}static create(e,t){const s=new L(e,t);return e.deferredStore.add(s),s}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class W{constructor(e,t,s,i){this.envObject=e,this.fn=t,this.arg=s,this.order=i}}class M{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,s){if(this._cleanupHooks.filter((i=>i.envObject===e&&i.fn===t&&i.arg===s)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new W(e,t,s,this._cleanupHookCounter++))}remove(e,t,s){for(let i=0;i<this._cleanupHooks.length;++i){const r=this._cleanupHooks[i];if(r.envObject===e&&r.fn===t&&r.arg===s)return void this._cleanupHooks.splice(i,1)}}drain(){const e=this._cleanupHooks.slice();e.sort(((e,t)=>t.order-e.order));for(let t=0;t<e.length;++t){const s=e[t];"number"==typeof s.fn?s.envObject.makeDynCall_vp(s.fn)(s.arg):s.fn(s.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(s),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class A{constructor(){this.refHandle=(new MessageChannel).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)}}class T{constructor(){this.envStore=new i,this.scopeStore=new w,this.refStore=new m,this.deferredStore=new k,this.handleStore=new b,this.cbinfoStack=new t,this.feature={supportReflect:c,supportFinalizer:l,supportWeakSymbol:h,supportBigInt:p,supportNewFunction:r,canSetFunctionName:u,setImmediate:d,Buffer:v},this.cleanupQueue=new M,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new A,process.once("beforeExit",(()=>{this.runCleanup()})))}createNotSupportWeakRefError(e,t){return new O(e,t)}createNotSupportBigIntError(e,t){return new F(e,t)}createNotSupportBufferError(e,t){return new I(e,t)}createReference(e,t,s,i,r=0,n=0,o=0){return R.create(e,t,s,i,r,n,o)}createDeferred(e){return L.create(this,e)}createEnv(e,t){return D.create(this,e,t)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){return this.scopeStore.openScope(e)}closeScope(e,t){this.scopeStore.closeScope(e)}ensureHandle(e){switch(e){case void 0:return b.UNDEFINED;case null:return b.NULL;case!0:return b.TRUE;case!1:return b.FALSE;case n:return b.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,s){this.cleanupQueue.add(e,t,s)}removeCleanupHook(e,t,s){this.cleanupQueue.remove(e,t,s)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}dispose(){this.runCleanup()}}let P;function q(){return new T}exports.CallbackInfo=e,exports.CallbackInfoStack=t,exports.ConstHandle=g,exports.Context=T,exports.Deferred=L,exports.DeferredStore=k,exports.EmnapiError=H,exports.Env=D,exports.EnvStore=i,exports.Finalizer=z,exports.Handle=y,exports.HandleScope=S,exports.HandleStore=b,exports.NotSupportBigIntError=F,exports.NotSupportBufferError=I,exports.NotSupportWeakRefError=O,exports.Persistent=j,exports.RefBase=C,exports.RefStore=m,exports.RefTracker=E,exports.Reference=R,exports.ScopeStore=w,exports.Store=s,exports.TryCatch=a,exports.createContext=q,exports.getDefaultContext=function(){return P||(P=q()),P},exports.isReferenceType=f,exports.version="0.38.2";
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});class e{constructor(e,t,s,i,r){this.parent=e,this.thiz=t,this.data=s,this.args=i,this.fn=r}getNewTarget(e){const t=this.thiz;return null==t||null==t.constructor?0:t instanceof this.fn?e.ensureHandleId(t.constructor):0}}class t{constructor(){this.current=null}pop(){const e=this.current;null!==e&&(this.current=e.parent)}push(t,s,i,r){const n=new e(this.current,t,s,i,r);return this.current=n,n}dispose(){this.current=null}}class s{constructor(e){this._values=[void 0],this._values.length=e,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=Math.ceil(1.5*e))}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}class i extends s{constructor(){super(2)}}const r=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),n=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&r)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}(),o=new Error;class a{constructor(){this._exception=o}hasCaught(){return this._exception!==o}exception(){return this._exception}setError(e){this._exception=e}reset(){this._exception=o}extractException(){const e=this._exception;return this.reset(),e}}const u=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),c="object"==typeof Reflect,l="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),p="undefined"!=typeof BigInt;function f(e){return"object"==typeof e&&null!==e||"function"==typeof e}const d=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),_="function"==typeof MessageChannel?MessageChannel:function(){try{return d("worker_threads").MessageChannel}catch(e){}}(),v="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(_){let t=new _;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},y="function"==typeof Buffer?Buffer:function(){try{return d("buffer").Buffer}catch(e){}}();class g{constructor(e,t){this.id=e,this.value=t}init(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isEmpty(){return 0===this.id}isNumber(){return!this.isEmpty()&&"number"==typeof this.value}isBigInt(){return!this.isEmpty()&&"bigint"==typeof this.value}isString(){return!this.isEmpty()&&"string"==typeof this.value}isFunction(){return!this.isEmpty()&&"function"==typeof this.value}isExternal(){return!this.isEmpty()&&f(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return!this.isEmpty()&&"object"==typeof this.value&&null!==this.value}isArray(){return!this.isEmpty()&&Array.isArray(this.value)}isArrayBuffer(){return!this.isEmpty()&&this.value instanceof ArrayBuffer}isTypedArray(){return!this.isEmpty()&&ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(){return!this.isEmpty()&&"function"==typeof y&&y.isBuffer(this.value)}isDataView(){return!this.isEmpty()&&this.value instanceof DataView}isDate(){return!this.isEmpty()&&this.value instanceof Date}isPromise(){return!this.isEmpty()&&this.value instanceof Promise}isBoolean(){return!this.isEmpty()&&"boolean"==typeof this.value}isUndefined(){return!this.isEmpty()&&void 0===this.value}isSymbol(){return!this.isEmpty()&&"symbol"==typeof this.value}isNull(){return!this.isEmpty()&&null===this.value}dispose(){0!==this.id&&(this.id=0,this.value=void 0)}}class x extends g{constructor(e,t){super(e,t)}dispose(){}}function b(){Object.setPrototypeOf(this,null)}b.prototype=null;class S{constructor(){this._values=[void 0,S.UNDEFINED,S.NULL,S.FALSE,S.TRUE,S.GLOBAL],this._next=S.MIN_ID}push(e){let t;const s=this._next,i=this._values;return s<i.length?(t=i[s],t.init(s,e)):(t=new g(s,e),i[s]=t),this._next++,t}erase(e,t){this._next=e;const s=this._values;for(let i=e;i<t;++i)s[i].dispose()}get(e){return this._values[e]}swap(e,t){const s=this._values,i=s[e];s[e]=s[t],s[e].id=Number(e),s[t]=i,i.id=Number(t)}dispose(){this._values.length=S.MIN_ID,this._next=S.MIN_ID}}S.UNDEFINED=new x(1,void 0),S.NULL=new x(2,null),S.FALSE=new x(3,!1),S.TRUE=new x(4,!0),S.GLOBAL=new x(5,n),S.MIN_ID=6;class w{constructor(e,t,s,i,r=i){this.handleStore=e,this.id=t,this.parent=s,this.child=null,null!==s&&(s.child=this),this.start=i,this.end=r,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const s=new b,i=e.ctx.handleStore.push(s);return e.initObjectBinding(s).data=t,this.end++,i}dispose(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class m{constructor(){this._rootScope=new w(null,0,null,1,S.MIN_ID),this.currentScope=this._rootScope}get(e){e=Number(e);let t=this.currentScope;for(;t!==this._rootScope;){if(t.id===e)return t;t=t.parent}}openScope(e){const t=this.currentScope;let s=t.child;return null!==s?(s.start=s.end=t.end,s._escapeCalled=!1):s=new w(e.ctx.handleStore,t.id+1,t,t.end),this.currentScope=s,e.openHandleScopes++,s}closeScope(e){if(0===e.openHandleScopes)return;const t=this.currentScope;this.currentScope=t.parent,t.dispose(),e.openHandleScopes--}dispose(){let e=this.currentScope;for(;null!==e;){e.handleStore=null,e.id=0,e.parent=null,e.start=S.MIN_ID,e.end=S.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class k extends s{constructor(){super(8)}}class E extends s{constructor(){super(8)}}class z{constructor(){this._next=null,this._prev=null}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class C{constructor(e,t=0,s=0,i=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=s,this._finalizeHint=i}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}dispose(){this.envObject=void 0}}class D extends C{constructor(e,t,s,i,r,n){super(e,i,r,n),this._next=null,this._prev=null,this._refcount=t,this._ownership=s,this.link(i?e.finalizing_reflist:e.reflist)}static finalizeAll(e){z.finalizeAll(e)}link(e){z.prototype.link.call(this,e)}unlink(){z.prototype.unlink.call(this)}dispose(){this.unlink(),this.envObject.dequeueFinalizer(this),super.dispose()}data(){return this._finalizeData}ref(){return++this._refcount}unref(){return 0===this._refcount?0:--this._refcount}refCount(){return this._refcount}ownership(){return this._ownership}finalize(){const e=this._ownership,t=this._finalizeCallback,s=this._finalizeData,i=this._finalizeHint;let r;this.resetFinalizer(),this.unlink();let n=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,s,i)}catch(e){n=!0,r=e}}if(0===e&&this.dispose(),n)throw r}}class H{constructor(e,t,s){this.ctx=e,this.makeDynCall_vppp=t,this.makeDynCall_vp=s,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new a,this.refs=1,this.reflist=new z,this.finalizing_reflist=new z,this.destructing=!1,this.finalizationScheduled=!1,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}static create(e,t,s){const i=new H(e,t,s);return e.envStore.add(i),e.addCleanupHook(i,(()=>{i.unref()}),0),i}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return e.errorCode=0,e.engineErrorCode=0,e.engineReserved=0,0}setLastError(e,t=0,s=0){const i=this.lastError;return i.errorCode=e,i.engineErrorCode=t,i.engineReserved=s,e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e){this.clearLastError();const t=e(this);if(this.tryCatch.hasCaught()){throw this.tryCatch.extractException()}return t}callFinalizer(e,t,s){const i=this.makeDynCall_vppp(e),r=this.id,n=this.ctx.openScope(this);try{this.callIntoModule((()=>{i(r,t,s)}))}finally{this.ctx.closeScope(this,n)}}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),v((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}dispose(){0!==this.id&&(this.destructing=!0,this.drainFinalizerQueue(),D.finalizeAll(this.finalizing_reflist),D.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null,data:0};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,s){this.instanceData&&this.instanceData.dispose(),this.instanceData=new D(this,0,0,t,e,s)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class O extends Error{constructor(e){super(e);const t=new.target,s=t.prototype;if(!(this instanceof O)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,s):this.__proto__=s,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(O.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class F extends O{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(F.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class I extends O{constructor(e,t){super(`${e}: The current runtime does not support "BigInt".${t?` ${t}`:""}`)}}Object.defineProperty(I.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});class N extends O{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(N.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class j{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class B{constructor(e){this._ref=new j(e)}setWeak(e,t){if(!l||void 0===this._ref||this._ref instanceof WeakRef)return;const s=this._ref.deref();try{B._registry.register(s,this,this);const i=new WeakRef(s);this._ref.dispose(),this._ref=i,this._param=e,this._callback=t}catch(e){}}clearWeak(){if(l&&void 0!==this._ref&&this._ref instanceof WeakRef){try{B._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new j(e)}}reset(){if(l)try{B._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof j&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}function R(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}B._registry=l?new FinalizationRegistry((e=>{e._ref=void 0;const t=e._callback,s=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(s)})):void 0;class L extends D{constructor(e,t,s,i=0,r=0,n=0){super(e,t>>>0,s,i,r,n),this.id=0}static create(e,t,s,i,r=0,n=0,o=0){const a=e.ctx.handleStore.get(t),u=new L(e,s,i,r,n,o);return e.ctx.refStore.add(u),u.persistent=new B(a.value),0===s&&u._setWeak(),u}ref(){if(this.persistent.isEmpty())return 0;const e=super.ref();if(1===e){this.persistent.deref()&&this.persistent.clearWeak()}return e}unref(){if(this.persistent.isEmpty())return 0;const e=this.refCount(),t=super.unref();if(1===e&&0===t){this.persistent.deref()&&this._setWeak()}return t}get(){const e=this.persistent.deref();if(e){return this.envObject.ensureHandle(e).id}return 0}_setWeak(){this.persistent.setWeak(this,R)}finalize(){this.persistent.reset(),super.finalize()}dispose(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.id=0)}}class M{constructor(e,t){this.id=0,this.ctx=e,this.value=t}static create(e,t){const s=new M(e,t);return e.deferredStore.add(s),s}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class T{constructor(e,t,s,i){this.envObject=e,this.fn=t,this.arg=s,this.order=i}}class W{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,s){if(this._cleanupHooks.filter((i=>i.envObject===e&&i.fn===t&&i.arg===s)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new T(e,t,s,this._cleanupHookCounter++))}remove(e,t,s){for(let i=0;i<this._cleanupHooks.length;++i){const r=this._cleanupHooks[i];if(r.envObject===e&&r.fn===t&&r.arg===s)return void this._cleanupHooks.splice(i,1)}}drain(){const e=this._cleanupHooks.slice();e.sort(((e,t)=>t.order-e.order));for(let t=0;t<e.length;++t){const s=e[t];"number"==typeof s.fn?s.envObject.makeDynCall_vp(s.fn)(s.arg):s.fn(s.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(s),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class A{constructor(){this.refHandle=(new _).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)}}class P{constructor(){this.envStore=new i,this.scopeStore=new m,this.refStore=new k,this.deferredStore=new E,this.handleStore=new S,this.cbinfoStack=new t,this.feature={supportReflect:c,supportFinalizer:l,supportWeakSymbol:h,supportBigInt:p,supportNewFunction:r,canSetFunctionName:u,setImmediate:v,Buffer:y,MessageChannel:_},this.cleanupQueue=new W,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new A,process.once("beforeExit",(()=>{this.runCleanup()})))}createNotSupportWeakRefError(e,t){return new F(e,t)}createNotSupportBigIntError(e,t){return new I(e,t)}createNotSupportBufferError(e,t){return new N(e,t)}createReference(e,t,s,i,r=0,n=0,o=0){return L.create(e,t,s,i,r,n,o)}createDeferred(e){return M.create(this,e)}createEnv(e,t){return H.create(this,e,t)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){return this.scopeStore.openScope(e)}closeScope(e,t){this.scopeStore.closeScope(e)}ensureHandle(e){switch(e){case void 0:return S.UNDEFINED;case null:return S.NULL;case!0:return S.TRUE;case!1:return S.FALSE;case n:return S.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,s){this.cleanupQueue.add(e,t,s)}removeCleanupHook(e,t,s){this.cleanupQueue.remove(e,t,s)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}dispose(){this.runCleanup()}}let q;function U(){return new P}exports.CallbackInfo=e,exports.CallbackInfoStack=t,exports.ConstHandle=x,exports.Context=P,exports.Deferred=M,exports.DeferredStore=E,exports.EmnapiError=O,exports.Env=H,exports.EnvStore=i,exports.Finalizer=C,exports.Handle=g,exports.HandleScope=w,exports.HandleStore=S,exports.NotSupportBigIntError=I,exports.NotSupportBufferError=N,exports.NotSupportWeakRefError=F,exports.Persistent=B,exports.RefBase=D,exports.RefStore=k,exports.RefTracker=z,exports.Reference=L,exports.ScopeStore=m,exports.Store=s,exports.TryCatch=a,exports.createContext=U,exports.getDefaultContext=function(){return q||(q=U()),q},exports.isReferenceType=f,exports.version="0.38.3";
|
package/dist/emnapi.d.ts
CHANGED
|
@@ -283,8 +283,12 @@ export declare class Context {
|
|
|
283
283
|
supportBigInt: boolean;
|
|
284
284
|
supportNewFunction: boolean;
|
|
285
285
|
canSetFunctionName: boolean;
|
|
286
|
-
setImmediate: (
|
|
286
|
+
setImmediate: (callback: () => void) => void;
|
|
287
287
|
Buffer: BufferCtor | undefined;
|
|
288
|
+
MessageChannel: {
|
|
289
|
+
new (): MessageChannel;
|
|
290
|
+
prototype: MessageChannel;
|
|
291
|
+
} | undefined;
|
|
288
292
|
};
|
|
289
293
|
constructor();
|
|
290
294
|
createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
|
|
@@ -178,19 +178,6 @@ var supportBigInt = typeof BigInt !== 'undefined';
|
|
|
178
178
|
function isReferenceType(v) {
|
|
179
179
|
return (typeof v === 'object' && v !== null) || typeof v === 'function';
|
|
180
180
|
}
|
|
181
|
-
var _setImmediate = typeof setImmediate === 'function'
|
|
182
|
-
? setImmediate
|
|
183
|
-
: function (f) {
|
|
184
|
-
if (typeof f !== 'function')
|
|
185
|
-
return;
|
|
186
|
-
var channel = new MessageChannel();
|
|
187
|
-
channel.port1.onmessage = function () {
|
|
188
|
-
channel.port1.onmessage = null;
|
|
189
|
-
channel = undefined;
|
|
190
|
-
f();
|
|
191
|
-
};
|
|
192
|
-
channel.port2.postMessage(null);
|
|
193
|
-
};
|
|
194
181
|
var _require = /*#__PURE__*/ (function () {
|
|
195
182
|
var nativeRequire;
|
|
196
183
|
if (typeof __webpack_public_path__ !== 'undefined') {
|
|
@@ -205,15 +192,43 @@ var _require = /*#__PURE__*/ (function () {
|
|
|
205
192
|
}
|
|
206
193
|
return nativeRequire;
|
|
207
194
|
})();
|
|
208
|
-
var
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
})();
|
|
195
|
+
var _MessageChannel = typeof MessageChannel === 'function'
|
|
196
|
+
? MessageChannel
|
|
197
|
+
: /*#__PURE__*/ (function () {
|
|
198
|
+
try {
|
|
199
|
+
return _require('worker_threads').MessageChannel;
|
|
200
|
+
}
|
|
201
|
+
catch (_) { }
|
|
202
|
+
return undefined;
|
|
203
|
+
})();
|
|
204
|
+
var _setImmediate = typeof setImmediate === 'function'
|
|
205
|
+
? setImmediate
|
|
206
|
+
: function (callback) {
|
|
207
|
+
if (typeof callback !== 'function') {
|
|
208
|
+
throw new TypeError('The "callback" argument must be of type function');
|
|
209
|
+
}
|
|
210
|
+
if (_MessageChannel) {
|
|
211
|
+
var channel_1 = new _MessageChannel();
|
|
212
|
+
channel_1.port1.onmessage = function () {
|
|
213
|
+
channel_1.port1.onmessage = null;
|
|
214
|
+
channel_1 = undefined;
|
|
215
|
+
callback();
|
|
216
|
+
};
|
|
217
|
+
channel_1.port2.postMessage(null);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
setTimeout(callback, 0);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var _Buffer = typeof Buffer === 'function'
|
|
224
|
+
? Buffer
|
|
225
|
+
: /*#__PURE__*/ (function () {
|
|
226
|
+
try {
|
|
227
|
+
return _require('buffer').Buffer;
|
|
228
|
+
}
|
|
229
|
+
catch (_) { }
|
|
230
|
+
return undefined;
|
|
231
|
+
})();
|
|
217
232
|
|
|
218
233
|
var Handle = /*#__PURE__*/ (function () {
|
|
219
234
|
function Handle(id, value) {
|
|
@@ -258,7 +273,7 @@ var Handle = /*#__PURE__*/ (function () {
|
|
|
258
273
|
return !this.isEmpty() && (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
|
|
259
274
|
};
|
|
260
275
|
Handle.prototype.isBuffer = function () {
|
|
261
|
-
return !this.isEmpty() && typeof
|
|
276
|
+
return !this.isEmpty() && typeof _Buffer === 'function' && _Buffer.isBuffer(this.value);
|
|
262
277
|
};
|
|
263
278
|
Handle.prototype.isDataView = function () {
|
|
264
279
|
return !this.isEmpty() && (this.value instanceof DataView);
|
|
@@ -1078,7 +1093,7 @@ var CleanupQueue = /*#__PURE__*/ (function () {
|
|
|
1078
1093
|
}());
|
|
1079
1094
|
var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
|
|
1080
1095
|
function NodejsWaitingRequestCounter() {
|
|
1081
|
-
this.refHandle = new
|
|
1096
|
+
this.refHandle = new _MessageChannel().port1;
|
|
1082
1097
|
this.count = 0;
|
|
1083
1098
|
}
|
|
1084
1099
|
NodejsWaitingRequestCounter.prototype.increase = function () {
|
|
@@ -1114,7 +1129,8 @@ var Context = /*#__PURE__*/ (function () {
|
|
|
1114
1129
|
supportNewFunction: supportNewFunction,
|
|
1115
1130
|
canSetFunctionName: canSetFunctionName,
|
|
1116
1131
|
setImmediate: _setImmediate,
|
|
1117
|
-
Buffer:
|
|
1132
|
+
Buffer: _Buffer,
|
|
1133
|
+
MessageChannel: _MessageChannel
|
|
1118
1134
|
};
|
|
1119
1135
|
this.cleanupQueue = new CleanupQueue();
|
|
1120
1136
|
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
@@ -1202,6 +1218,6 @@ function getDefaultContext() {
|
|
|
1202
1218
|
return defaultContext;
|
|
1203
1219
|
}
|
|
1204
1220
|
|
|
1205
|
-
var version = "0.38.
|
|
1221
|
+
var version = "0.38.3";
|
|
1206
1222
|
|
|
1207
1223
|
export { CallbackInfo, CallbackInfoStack, ConstHandle, Context, Deferred, DeferredStore, EmnapiError, Env, EnvStore, Finalizer, Handle, HandleScope, HandleStore, NotSupportBigIntError, NotSupportBufferError, NotSupportWeakRefError, Persistent, RefBase, RefStore, RefTracker, Reference, ScopeStore, Store, TryCatch, createContext, getDefaultContext, isReferenceType, version };
|
package/dist/emnapi.iife.d.ts
CHANGED
|
@@ -40,8 +40,12 @@ export class Context {
|
|
|
40
40
|
supportBigInt: boolean;
|
|
41
41
|
supportNewFunction: boolean;
|
|
42
42
|
canSetFunctionName: boolean;
|
|
43
|
-
setImmediate: (
|
|
43
|
+
setImmediate: (callback: () => void) => void;
|
|
44
44
|
Buffer: BufferCtor | undefined;
|
|
45
|
+
MessageChannel: {
|
|
46
|
+
new (): MessageChannel;
|
|
47
|
+
prototype: MessageChannel;
|
|
48
|
+
} | undefined;
|
|
45
49
|
};
|
|
46
50
|
constructor();
|
|
47
51
|
createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
|
package/dist/emnapi.iife.js
CHANGED
|
@@ -209,19 +209,6 @@ var emnapi = (function (exports) {
|
|
|
209
209
|
function isReferenceType(v) {
|
|
210
210
|
return (typeof v === 'object' && v !== null) || typeof v === 'function';
|
|
211
211
|
}
|
|
212
|
-
var _setImmediate = typeof setImmediate === 'function'
|
|
213
|
-
? setImmediate
|
|
214
|
-
: function (f) {
|
|
215
|
-
if (typeof f !== 'function')
|
|
216
|
-
return;
|
|
217
|
-
var channel = new MessageChannel();
|
|
218
|
-
channel.port1.onmessage = function () {
|
|
219
|
-
channel.port1.onmessage = null;
|
|
220
|
-
channel = undefined;
|
|
221
|
-
f();
|
|
222
|
-
};
|
|
223
|
-
channel.port2.postMessage(null);
|
|
224
|
-
};
|
|
225
212
|
var _require = /*#__PURE__*/ (function () {
|
|
226
213
|
var nativeRequire;
|
|
227
214
|
if (typeof __webpack_public_path__ !== 'undefined') {
|
|
@@ -236,15 +223,43 @@ var emnapi = (function (exports) {
|
|
|
236
223
|
}
|
|
237
224
|
return nativeRequire;
|
|
238
225
|
})();
|
|
239
|
-
var
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
226
|
+
var _MessageChannel = typeof MessageChannel === 'function'
|
|
227
|
+
? MessageChannel
|
|
228
|
+
: /*#__PURE__*/ (function () {
|
|
229
|
+
try {
|
|
230
|
+
return _require('worker_threads').MessageChannel;
|
|
231
|
+
}
|
|
232
|
+
catch (_) { }
|
|
233
|
+
return undefined;
|
|
234
|
+
})();
|
|
235
|
+
var _setImmediate = typeof setImmediate === 'function'
|
|
236
|
+
? setImmediate
|
|
237
|
+
: function (callback) {
|
|
238
|
+
if (typeof callback !== 'function') {
|
|
239
|
+
throw new TypeError('The "callback" argument must be of type function');
|
|
240
|
+
}
|
|
241
|
+
if (_MessageChannel) {
|
|
242
|
+
var channel_1 = new _MessageChannel();
|
|
243
|
+
channel_1.port1.onmessage = function () {
|
|
244
|
+
channel_1.port1.onmessage = null;
|
|
245
|
+
channel_1 = undefined;
|
|
246
|
+
callback();
|
|
247
|
+
};
|
|
248
|
+
channel_1.port2.postMessage(null);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
setTimeout(callback, 0);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
var _Buffer = typeof Buffer === 'function'
|
|
255
|
+
? Buffer
|
|
256
|
+
: /*#__PURE__*/ (function () {
|
|
257
|
+
try {
|
|
258
|
+
return _require('buffer').Buffer;
|
|
259
|
+
}
|
|
260
|
+
catch (_) { }
|
|
261
|
+
return undefined;
|
|
262
|
+
})();
|
|
248
263
|
|
|
249
264
|
var Handle = /*#__PURE__*/ (function () {
|
|
250
265
|
function Handle(id, value) {
|
|
@@ -289,7 +304,7 @@ var emnapi = (function (exports) {
|
|
|
289
304
|
return !this.isEmpty() && (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
|
|
290
305
|
};
|
|
291
306
|
Handle.prototype.isBuffer = function () {
|
|
292
|
-
return !this.isEmpty() && typeof
|
|
307
|
+
return !this.isEmpty() && typeof _Buffer === 'function' && _Buffer.isBuffer(this.value);
|
|
293
308
|
};
|
|
294
309
|
Handle.prototype.isDataView = function () {
|
|
295
310
|
return !this.isEmpty() && (this.value instanceof DataView);
|
|
@@ -1109,7 +1124,7 @@ var emnapi = (function (exports) {
|
|
|
1109
1124
|
}());
|
|
1110
1125
|
var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
|
|
1111
1126
|
function NodejsWaitingRequestCounter() {
|
|
1112
|
-
this.refHandle = new
|
|
1127
|
+
this.refHandle = new _MessageChannel().port1;
|
|
1113
1128
|
this.count = 0;
|
|
1114
1129
|
}
|
|
1115
1130
|
NodejsWaitingRequestCounter.prototype.increase = function () {
|
|
@@ -1145,7 +1160,8 @@ var emnapi = (function (exports) {
|
|
|
1145
1160
|
supportNewFunction: supportNewFunction,
|
|
1146
1161
|
canSetFunctionName: canSetFunctionName,
|
|
1147
1162
|
setImmediate: _setImmediate,
|
|
1148
|
-
Buffer:
|
|
1163
|
+
Buffer: _Buffer,
|
|
1164
|
+
MessageChannel: _MessageChannel
|
|
1149
1165
|
};
|
|
1150
1166
|
this.cleanupQueue = new CleanupQueue();
|
|
1151
1167
|
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
@@ -1233,7 +1249,7 @@ var emnapi = (function (exports) {
|
|
|
1233
1249
|
return defaultContext;
|
|
1234
1250
|
}
|
|
1235
1251
|
|
|
1236
|
-
var version = "0.38.
|
|
1252
|
+
var version = "0.38.3";
|
|
1237
1253
|
|
|
1238
1254
|
exports.CallbackInfo = CallbackInfo;
|
|
1239
1255
|
exports.CallbackInfoStack = CallbackInfoStack;
|
package/dist/emnapi.js
CHANGED
|
@@ -212,19 +212,6 @@
|
|
|
212
212
|
function isReferenceType(v) {
|
|
213
213
|
return (typeof v === 'object' && v !== null) || typeof v === 'function';
|
|
214
214
|
}
|
|
215
|
-
var _setImmediate = typeof setImmediate === 'function'
|
|
216
|
-
? setImmediate
|
|
217
|
-
: function (f) {
|
|
218
|
-
if (typeof f !== 'function')
|
|
219
|
-
return;
|
|
220
|
-
var channel = new MessageChannel();
|
|
221
|
-
channel.port1.onmessage = function () {
|
|
222
|
-
channel.port1.onmessage = null;
|
|
223
|
-
channel = undefined;
|
|
224
|
-
f();
|
|
225
|
-
};
|
|
226
|
-
channel.port2.postMessage(null);
|
|
227
|
-
};
|
|
228
215
|
var _require = /*#__PURE__*/ (function () {
|
|
229
216
|
var nativeRequire;
|
|
230
217
|
if (typeof __webpack_public_path__ !== 'undefined') {
|
|
@@ -239,15 +226,43 @@
|
|
|
239
226
|
}
|
|
240
227
|
return nativeRequire;
|
|
241
228
|
})();
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
229
|
+
var _MessageChannel = typeof MessageChannel === 'function'
|
|
230
|
+
? MessageChannel
|
|
231
|
+
: /*#__PURE__*/ (function () {
|
|
232
|
+
try {
|
|
233
|
+
return _require('worker_threads').MessageChannel;
|
|
234
|
+
}
|
|
235
|
+
catch (_) { }
|
|
236
|
+
return undefined;
|
|
237
|
+
})();
|
|
238
|
+
var _setImmediate = typeof setImmediate === 'function'
|
|
239
|
+
? setImmediate
|
|
240
|
+
: function (callback) {
|
|
241
|
+
if (typeof callback !== 'function') {
|
|
242
|
+
throw new TypeError('The "callback" argument must be of type function');
|
|
243
|
+
}
|
|
244
|
+
if (_MessageChannel) {
|
|
245
|
+
var channel_1 = new _MessageChannel();
|
|
246
|
+
channel_1.port1.onmessage = function () {
|
|
247
|
+
channel_1.port1.onmessage = null;
|
|
248
|
+
channel_1 = undefined;
|
|
249
|
+
callback();
|
|
250
|
+
};
|
|
251
|
+
channel_1.port2.postMessage(null);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
setTimeout(callback, 0);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
var _Buffer = typeof Buffer === 'function'
|
|
258
|
+
? Buffer
|
|
259
|
+
: /*#__PURE__*/ (function () {
|
|
260
|
+
try {
|
|
261
|
+
return _require('buffer').Buffer;
|
|
262
|
+
}
|
|
263
|
+
catch (_) { }
|
|
264
|
+
return undefined;
|
|
265
|
+
})();
|
|
251
266
|
|
|
252
267
|
var Handle = /*#__PURE__*/ (function () {
|
|
253
268
|
function Handle(id, value) {
|
|
@@ -292,7 +307,7 @@
|
|
|
292
307
|
return !this.isEmpty() && (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
|
|
293
308
|
};
|
|
294
309
|
Handle.prototype.isBuffer = function () {
|
|
295
|
-
return !this.isEmpty() && typeof
|
|
310
|
+
return !this.isEmpty() && typeof _Buffer === 'function' && _Buffer.isBuffer(this.value);
|
|
296
311
|
};
|
|
297
312
|
Handle.prototype.isDataView = function () {
|
|
298
313
|
return !this.isEmpty() && (this.value instanceof DataView);
|
|
@@ -1112,7 +1127,7 @@
|
|
|
1112
1127
|
}());
|
|
1113
1128
|
var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
|
|
1114
1129
|
function NodejsWaitingRequestCounter() {
|
|
1115
|
-
this.refHandle = new
|
|
1130
|
+
this.refHandle = new _MessageChannel().port1;
|
|
1116
1131
|
this.count = 0;
|
|
1117
1132
|
}
|
|
1118
1133
|
NodejsWaitingRequestCounter.prototype.increase = function () {
|
|
@@ -1148,7 +1163,8 @@
|
|
|
1148
1163
|
supportNewFunction: supportNewFunction,
|
|
1149
1164
|
canSetFunctionName: canSetFunctionName,
|
|
1150
1165
|
setImmediate: _setImmediate,
|
|
1151
|
-
Buffer:
|
|
1166
|
+
Buffer: _Buffer,
|
|
1167
|
+
MessageChannel: _MessageChannel
|
|
1152
1168
|
};
|
|
1153
1169
|
this.cleanupQueue = new CleanupQueue();
|
|
1154
1170
|
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
@@ -1236,7 +1252,7 @@
|
|
|
1236
1252
|
return defaultContext;
|
|
1237
1253
|
}
|
|
1238
1254
|
|
|
1239
|
-
var version = "0.38.
|
|
1255
|
+
var version = "0.38.3";
|
|
1240
1256
|
|
|
1241
1257
|
exports.CallbackInfo = CallbackInfo;
|
|
1242
1258
|
exports.CallbackInfoStack = CallbackInfoStack;
|
package/dist/emnapi.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).emnapi={})}(this,(function(t){var e=function(){function t(t,e,n,i,r){this.parent=t,this.thiz=e,this.data=n,this.args=i,this.fn=r}return t.prototype.getNewTarget=function(t){var e=this.thiz;return null==e||null==e.constructor?0:e instanceof this.fn?t.ensureHandleId(e.constructor):0},t}(),n=function(){function t(){this.current=null}return t.prototype.pop=function(){var t=this.current;null!==t&&(this.current=t.parent)},t.prototype.push=function(t,n,i,r){var o=new e(this.current,t,n,i,r);return this.current=o,o},t.prototype.dispose=function(){this.current=null},t}(),i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},i(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o=function(){function t(t){this._values=[void 0],this._values.length=t,this._size=1,this._freeList=[]}return t.prototype.add=function(t){var e;if(this._freeList.length)e=this._freeList.shift();else{e=this._size,this._size++;var n=this._values.length;e>=n&&(this._values.length=Math.ceil(1.5*n))}t.id=e,this._values[e]=t},t.prototype.get=function(t){return this._values[t]},t.prototype.has=function(t){return void 0!==this._values[t]},t.prototype.remove=function(t){var e=this._values[t];e&&(e.id=0,this._values[t]=void 0,this._freeList.push(Number(t)))},t.prototype.dispose=function(){for(var t=1;t<this._size;++t){var e=this._values[t];null==e||e.dispose()}this._values=[void 0],this._size=1,this._freeList=[]},t}(),s=function(t){function e(){return t.call(this,2)||this}return r(e,t),e}(o),u=function(){var t;try{t=new Function}catch(t){return!1}return"function"==typeof t}(),a=function(){if("undefined"!=typeof globalThis)return globalThis;var t=function(){return this}();if(!t&&u)try{t=new Function("return this")()}catch(t){}if(!t){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return t}(),p=new Error,c=function(){function t(){this._exception=p}return t.prototype.hasCaught=function(){return this._exception!==p},t.prototype.exception=function(){return this._exception},t.prototype.setError=function(t){this._exception=t},t.prototype.reset=function(){this._exception=p},t.prototype.extractException=function(){var t=this._exception;return this.reset(),t},t}(),f=function(){var t;try{return Boolean(null===(t=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===t?void 0:t.configurable)}catch(t){return!1}}(),h="object"==typeof Reflect,l="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,d=function(){try{var t=Symbol();new WeakRef(t),(new WeakMap).set(t,void 0)}catch(t){return!1}return!0}(),y="undefined"!=typeof BigInt;function v(t){return"object"==typeof t&&null!==t||"function"==typeof t}var _="function"==typeof setImmediate?setImmediate:function(t){if("function"==typeof t){var e=new MessageChannel;e.port1.onmessage=function(){e.port1.onmessage=null,e=void 0,t()},e.port2.postMessage(null)}},g=function(){return"undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0}(),b=function(){if("function"==typeof a.Buffer)return a.Buffer;try{return g("buffer").Buffer}catch(t){}}(),S=function(){function t(t,e){this.id=t,this.value=e}return t.prototype.init=function(t,e){this.id=t,this.value=e},t.prototype.data=function(t){return t.getObjectBinding(this.value).data},t.prototype.isEmpty=function(){return 0===this.id},t.prototype.isNumber=function(){return!this.isEmpty()&&"number"==typeof this.value},t.prototype.isBigInt=function(){return!this.isEmpty()&&"bigint"==typeof this.value},t.prototype.isString=function(){return!this.isEmpty()&&"string"==typeof this.value},t.prototype.isFunction=function(){return!this.isEmpty()&&"function"==typeof this.value},t.prototype.isExternal=function(){return!this.isEmpty()&&v(this.value)&&null===Object.getPrototypeOf(this.value)},t.prototype.isObject=function(){return!this.isEmpty()&&"object"==typeof this.value&&null!==this.value},t.prototype.isArray=function(){return!this.isEmpty()&&Array.isArray(this.value)},t.prototype.isArrayBuffer=function(){return!this.isEmpty()&&this.value instanceof ArrayBuffer},t.prototype.isTypedArray=function(){return!this.isEmpty()&&ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)},t.prototype.isBuffer=function(){return!this.isEmpty()&&"function"==typeof b&&b.isBuffer(this.value)},t.prototype.isDataView=function(){return!this.isEmpty()&&this.value instanceof DataView},t.prototype.isDate=function(){return!this.isEmpty()&&this.value instanceof Date},t.prototype.isPromise=function(){return!this.isEmpty()&&this.value instanceof Promise},t.prototype.isBoolean=function(){return!this.isEmpty()&&"boolean"==typeof this.value},t.prototype.isUndefined=function(){return!this.isEmpty()&&void 0===this.value},t.prototype.isSymbol=function(){return!this.isEmpty()&&"symbol"==typeof this.value},t.prototype.isNull=function(){return!this.isEmpty()&&null===this.value},t.prototype.dispose=function(){0!==this.id&&(this.id=0,this.value=void 0)},t}(),w=function(t){function e(e,n){return t.call(this,e,n)||this}return r(e,t),e.prototype.dispose=function(){},e}(S);function m(){Object.setPrototypeOf(this,null)}m.prototype=null;var k=function(){function t(){this._values=[void 0,t.UNDEFINED,t.NULL,t.FALSE,t.TRUE,t.GLOBAL],this._next=t.MIN_ID}return t.prototype.push=function(t){var e,n=this._next,i=this._values;return n<i.length?(e=i[n]).init(n,t):(e=new S(n,t),i[n]=e),this._next++,e},t.prototype.erase=function(t,e){this._next=t;for(var n=this._values,i=t;i<e;++i)n[i].dispose()},t.prototype.get=function(t){return this._values[t]},t.prototype.swap=function(t,e){var n=this._values,i=n[t];n[t]=n[e],n[t].id=Number(t),n[e]=i,i.id=Number(e)},t.prototype.dispose=function(){this._values.length=t.MIN_ID,this._next=t.MIN_ID},t.UNDEFINED=new w(1,void 0),t.NULL=new w(2,null),t.FALSE=new w(3,!1),t.TRUE=new w(4,!0),t.GLOBAL=new w(5,a),t.MIN_ID=6,t}(),E=function(){function t(t,e,n,i,r){void 0===r&&(r=i),this.handleStore=t,this.id=e,this.parent=n,this.child=null,null!==n&&(n.child=this),this.start=i,this.end=r,this._escapeCalled=!1}return t.prototype.add=function(t){var e=this.handleStore.push(t);return this.end++,e},t.prototype.addExternal=function(t,e){var n=new m,i=t.ctx.handleStore.push(n);return t.initObjectBinding(n).data=e,this.end++,i},t.prototype.dispose=function(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)},t.prototype.escape=function(t){if(this._escapeCalled)return null;if(this._escapeCalled=!0,t<this.start||t>=this.end)return null;this.handleStore.swap(t,this.start);var e=this.handleStore.get(this.start);return this.start++,this.parent.end++,e},t.prototype.escapeCalled=function(){return this._escapeCalled},t}(),z=function(){function t(){this._rootScope=new E(null,0,null,1,k.MIN_ID),this.currentScope=this._rootScope}return t.prototype.get=function(t){t=Number(t);for(var e=this.currentScope;e!==this._rootScope;){if(e.id===t)return e;e=e.parent}},t.prototype.openScope=function(t){var e=this.currentScope,n=e.child;return null!==n?(n.start=n.end=e.end,n._escapeCalled=!1):n=new E(t.ctx.handleStore,e.id+1,e,e.end),this.currentScope=n,t.openHandleScopes++,n},t.prototype.closeScope=function(t){if(0!==t.openHandleScopes){var e=this.currentScope;this.currentScope=e.parent,e.dispose(),t.openHandleScopes--}},t.prototype.dispose=function(){for(var t=this.currentScope;null!==t;){t.handleStore=null,t.id=0,t.parent=null,t.start=k.MIN_ID,t.end=k.MIN_ID,t._escapeCalled=!1;var e=t.child;t.child=null,t=e}this.currentScope=null},t}(),C=function(t){function e(){return t.call(this,8)||this}return r(e,t),e}(o),x=function(t){function e(){return t.call(this,8)||this}return r(e,t),e}(o),O=function(){function t(){this._next=null,this._prev=null}return t.prototype.finalize=function(){},t.prototype.link=function(t){this._prev=t,this._next=t._next,null!==this._next&&(this._next._prev=this),t._next=this},t.prototype.unlink=function(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null},t.finalizeAll=function(t){for(;null!==t._next;)t._next.finalize()},t}(),D=function(){function t(t,e,n,i){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.envObject=t,this._finalizeCallback=e,this._finalizeData=n,this._finalizeHint=i}return t.prototype.callback=function(){return this._finalizeCallback},t.prototype.data=function(){return this._finalizeData},t.prototype.hint=function(){return this._finalizeHint},t.prototype.resetFinalizer=function(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0},t.prototype.dispose=function(){this.envObject=void 0},t}(),H=function(t){function e(e,n,i,r,o,s){var u=t.call(this,e,r,o,s)||this;return u._next=null,u._prev=null,u._refcount=n,u._ownership=i,u.link(r?e.finalizing_reflist:e.reflist),u}return r(e,t),e.finalizeAll=function(t){O.finalizeAll(t)},e.prototype.link=function(t){O.prototype.link.call(this,t)},e.prototype.unlink=function(){O.prototype.unlink.call(this)},e.prototype.dispose=function(){this.unlink(),this.envObject.dequeueFinalizer(this),t.prototype.dispose.call(this)},e.prototype.data=function(){return this._finalizeData},e.prototype.ref=function(){return++this._refcount},e.prototype.unref=function(){return 0===this._refcount?0:--this._refcount},e.prototype.refCount=function(){return this._refcount},e.prototype.ownership=function(){return this._ownership},e.prototype.finalize=function(){var t,e=this._ownership,n=this._finalizeCallback,i=this._finalizeData,r=this._finalizeHint;this.resetFinalizer(),this.unlink();var o=!1;if(n){var s=Number(n);try{this.envObject.callFinalizer(s,i,r)}catch(e){o=!0,t=e}}if(0===e&&this.dispose(),o)throw t},e}(D),j=function(){function t(t,e,n){this.ctx=t,this.makeDynCall_vppp=e,this.makeDynCall_vp=n,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new c,this.refs=1,this.reflist=new O,this.finalizing_reflist=new O,this.destructing=!1,this.finalizationScheduled=!1,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}return t.create=function(e,n,i){var r=new t(e,n,i);return e.envStore.add(r),e.addCleanupHook(r,(function(){r.unref()}),0),r},t.prototype.ref=function(){this.refs++},t.prototype.unref=function(){this.refs--,0===this.refs&&this.dispose()},t.prototype.ensureHandle=function(t){return this.ctx.ensureHandle(t)},t.prototype.ensureHandleId=function(t){return this.ensureHandle(t).id},t.prototype.clearLastError=function(){var t=this.lastError;return t.errorCode=0,t.engineErrorCode=0,t.engineReserved=0,0},t.prototype.setLastError=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=0);var i=this.lastError;return i.errorCode=t,i.engineErrorCode=e,i.engineReserved=n,t},t.prototype.getReturnStatus=function(){return this.tryCatch.hasCaught()?this.setLastError(10):0},t.prototype.callIntoModule=function(t){this.clearLastError();var e=t(this);if(this.tryCatch.hasCaught())throw this.tryCatch.extractException();return e},t.prototype.callFinalizer=function(t,e,n){var i=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callIntoModule((function(){i(r,e,n)}))}finally{this.ctx.closeScope(this,o)}},t.prototype.enqueueFinalizer=function(t){var e=this;-1===this.pendingFinalizers.indexOf(t)&&this.pendingFinalizers.push(t),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),_((function(){e.finalizationScheduled=!1,e.unref(),e.drainFinalizerQueue()})))},t.prototype.dequeueFinalizer=function(t){var e=this.pendingFinalizers.indexOf(t);-1!==e&&this.pendingFinalizers.splice(e,1)},t.prototype.drainFinalizerQueue=function(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}},t.prototype.dispose=function(){0!==this.id&&(this.destructing=!0,this.drainFinalizerQueue(),H.finalizeAll(this.finalizing_reflist),H.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id),this.id=0)},t.prototype.initObjectBinding=function(t){var e={wrapped:0,tag:null,data:0};return this._bindingMap.set(t,e),e},t.prototype.getObjectBinding=function(t){return this._bindingMap.has(t)?this._bindingMap.get(t):this.initObjectBinding(t)},t.prototype.setInstanceData=function(t,e,n){this.instanceData&&this.instanceData.dispose(),this.instanceData=new H(this,0,0,e,t,n)},t.prototype.getInstanceData=function(){return this.instanceData?this.instanceData.data():0},t}(),F=function(t){function e(n){var i=this.constructor,r=t.call(this,n)||this,o=i,s=o.prototype;if(!(r instanceof e)){var u=Object.setPrototypeOf;"function"==typeof u?u.call(Object,r,s):r.__proto__=s,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(r,o)}return r}return r(e,t),e}(Error);Object.defineProperty(F.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});var I=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "FinalizationRegistry" and "WeakRef".').concat(n?" ".concat(n):""))||this}return r(e,t),e}(F);Object.defineProperty(I.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});var N=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "BigInt".').concat(n?" ".concat(n):""))||this}return r(e,t),e}(F);Object.defineProperty(N.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});var B=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "Buffer". Consider using buffer polyfill to make sure `globalThis.Buffer` is defined.').concat(n?" ".concat(n):""))||this}return r(e,t),e}(F);Object.defineProperty(B.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});var R=function(){function t(t){this._value=t}return t.prototype.deref=function(){return this._value},t.prototype.dispose=function(){this._value=void 0},t}(),L=function(){function t(t){this._ref=new R(t)}return t.prototype.setWeak=function(e,n){if(l&&void 0!==this._ref&&!(this._ref instanceof WeakRef)){var i=this._ref.deref();try{t._registry.register(i,this,this);var r=new WeakRef(i);this._ref.dispose(),this._ref=r,this._param=e,this._callback=n}catch(t){}}},t.prototype.clearWeak=function(){if(l&&void 0!==this._ref&&this._ref instanceof WeakRef){try{t._registry.unregister(this)}catch(t){}this._param=void 0,this._callback=void 0;var e=this._ref.deref();this._ref=void 0===e?e:new R(e)}},t.prototype.reset=function(){if(l)try{t._registry.unregister(this)}catch(t){}this._param=void 0,this._callback=void 0,this._ref instanceof R&&this._ref.dispose(),this._ref=void 0},t.prototype.isEmpty=function(){return void 0===this._ref},t.prototype.deref=function(){if(void 0!==this._ref)return this._ref.deref()},t._registry=l?new FinalizationRegistry((function(t){t._ref=void 0;var e=t._callback,n=t._param;t._callback=void 0,t._param=void 0,"function"==typeof e&&e(n)})):void 0,t}();function T(t){t.persistent.reset(),t.envObject.enqueueFinalizer(t)}var W,M=function(t){function e(e,n,i,r,o,s){void 0===r&&(r=0),void 0===o&&(o=0),void 0===s&&(s=0);var u=t.call(this,e,n>>>0,i,r,o,s)||this;return u.id=0,u}return r(e,t),e.create=function(t,n,i,r,o,s,u){void 0===o&&(o=0),void 0===s&&(s=0),void 0===u&&(u=0);var a=t.ctx.handleStore.get(n),p=new e(t,i,r,o,s,u);return t.ctx.refStore.add(p),p.persistent=new L(a.value),0===i&&p._setWeak(),p},e.prototype.ref=function(){if(this.persistent.isEmpty())return 0;var e=t.prototype.ref.call(this);1===e&&(this.persistent.deref()&&this.persistent.clearWeak());return e},e.prototype.unref=function(){if(this.persistent.isEmpty())return 0;var e=this.refCount(),n=t.prototype.unref.call(this);1===e&&0===n&&(this.persistent.deref()&&this._setWeak());return n},e.prototype.get=function(){var t=this.persistent.deref();return t?this.envObject.ensureHandle(t).id:0},e.prototype._setWeak=function(){this.persistent.setWeak(this,T)},e.prototype.finalize=function(){this.persistent.reset(),t.prototype.finalize.call(this)},e.prototype.dispose=function(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),t.prototype.dispose.call(this),this.id=0)},e}(H),A=function(){function t(t,e){this.id=0,this.ctx=t,this.value=e}return t.create=function(e,n){var i=new t(e,n);return e.deferredStore.add(i),i},t.prototype.resolve=function(t){this.value.resolve(t),this.dispose()},t.prototype.reject=function(t){this.value.reject(t),this.dispose()},t.prototype.dispose=function(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null},t}(),P=function(){return function(t,e,n,i){this.envObject=t,this.fn=e,this.arg=n,this.order=i}}(),q=function(){function t(){this._cleanupHooks=[],this._cleanupHookCounter=0}return t.prototype.empty=function(){return 0===this._cleanupHooks.length},t.prototype.add=function(t,e,n){if(this._cleanupHooks.filter((function(i){return i.envObject===t&&i.fn===e&&i.arg===n})).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new P(t,e,n,this._cleanupHookCounter++))},t.prototype.remove=function(t,e,n){for(var i=0;i<this._cleanupHooks.length;++i){var r=this._cleanupHooks[i];if(r.envObject===t&&r.fn===e&&r.arg===n)return void this._cleanupHooks.splice(i,1)}},t.prototype.drain=function(){var t=this._cleanupHooks.slice();t.sort((function(t,e){return e.order-t.order}));for(var e=0;e<t.length;++e){var n=t[e];"number"==typeof n.fn?n.envObject.makeDynCall_vp(n.fn)(n.arg):n.fn(n.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(n),1)}},t.prototype.dispose=function(){this._cleanupHooks.length=0,this._cleanupHookCounter=0},t}(),U=function(){function t(){this.refHandle=(new MessageChannel).port1,this.count=0}return t.prototype.increase=function(){0===this.count&&this.refHandle.ref(),this.count++},t.prototype.decrease=function(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)},t}(),Q=function(){function t(){var t=this;this.envStore=new s,this.scopeStore=new z,this.refStore=new C,this.deferredStore=new x,this.handleStore=new k,this.cbinfoStack=new n,this.feature={supportReflect:h,supportFinalizer:l,supportWeakSymbol:d,supportBigInt:y,supportNewFunction:u,canSetFunctionName:f,setImmediate:_,Buffer:b},this.cleanupQueue=new q,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new U,process.once("beforeExit",(function(){t.runCleanup()})))}return t.prototype.createNotSupportWeakRefError=function(t,e){return new I(t,e)},t.prototype.createNotSupportBigIntError=function(t,e){return new N(t,e)},t.prototype.createNotSupportBufferError=function(t,e){return new B(t,e)},t.prototype.createReference=function(t,e,n,i,r,o,s){return void 0===r&&(r=0),void 0===o&&(o=0),void 0===s&&(s=0),M.create(t,e,n,i,r,o,s)},t.prototype.createDeferred=function(t){return A.create(this,t)},t.prototype.createEnv=function(t,e){return j.create(this,t,e)},t.prototype.getCurrentScope=function(){return this.scopeStore.currentScope},t.prototype.addToCurrentScope=function(t){return this.scopeStore.currentScope.add(t)},t.prototype.openScope=function(t){return this.scopeStore.openScope(t)},t.prototype.closeScope=function(t,e){this.scopeStore.closeScope(t)},t.prototype.ensureHandle=function(t){switch(t){case void 0:return k.UNDEFINED;case null:return k.NULL;case!0:return k.TRUE;case!1:return k.FALSE;case a:return k.GLOBAL}return this.addToCurrentScope(t)},t.prototype.addCleanupHook=function(t,e,n){this.cleanupQueue.add(t,e,n)},t.prototype.removeCleanupHook=function(t,e,n){this.cleanupQueue.remove(t,e,n)},t.prototype.runCleanup=function(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()},t.prototype.increaseWaitingRequestCounter=function(){var t;null===(t=this.refCounter)||void 0===t||t.increase()},t.prototype.decreaseWaitingRequestCounter=function(){var t;null===(t=this.refCounter)||void 0===t||t.decrease()},t.prototype.dispose=function(){this.runCleanup()},t}();function V(){return new Q}t.CallbackInfo=e,t.CallbackInfoStack=n,t.ConstHandle=w,t.Context=Q,t.Deferred=A,t.DeferredStore=x,t.EmnapiError=F,t.Env=j,t.EnvStore=s,t.Finalizer=D,t.Handle=S,t.HandleScope=E,t.HandleStore=k,t.NotSupportBigIntError=N,t.NotSupportBufferError=B,t.NotSupportWeakRefError=I,t.Persistent=L,t.RefBase=H,t.RefStore=C,t.RefTracker=O,t.Reference=M,t.ScopeStore=z,t.Store=o,t.TryCatch=c,t.createContext=V,t.getDefaultContext=function(){return W||(W=V()),W},t.isReferenceType=v,t.version="0.38.2",Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).emnapi={})}(this,(function(t){var e=function(){function t(t,e,n,i,r){this.parent=t,this.thiz=e,this.data=n,this.args=i,this.fn=r}return t.prototype.getNewTarget=function(t){var e=this.thiz;return null==e||null==e.constructor?0:e instanceof this.fn?t.ensureHandleId(e.constructor):0},t}(),n=function(){function t(){this.current=null}return t.prototype.pop=function(){var t=this.current;null!==t&&(this.current=t.parent)},t.prototype.push=function(t,n,i,r){var o=new e(this.current,t,n,i,r);return this.current=o,o},t.prototype.dispose=function(){this.current=null},t}(),i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},i(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o=function(){function t(t){this._values=[void 0],this._values.length=t,this._size=1,this._freeList=[]}return t.prototype.add=function(t){var e;if(this._freeList.length)e=this._freeList.shift();else{e=this._size,this._size++;var n=this._values.length;e>=n&&(this._values.length=Math.ceil(1.5*n))}t.id=e,this._values[e]=t},t.prototype.get=function(t){return this._values[t]},t.prototype.has=function(t){return void 0!==this._values[t]},t.prototype.remove=function(t){var e=this._values[t];e&&(e.id=0,this._values[t]=void 0,this._freeList.push(Number(t)))},t.prototype.dispose=function(){for(var t=1;t<this._size;++t){var e=this._values[t];null==e||e.dispose()}this._values=[void 0],this._size=1,this._freeList=[]},t}(),s=function(t){function e(){return t.call(this,2)||this}return r(e,t),e}(o),u=function(){var t;try{t=new Function}catch(t){return!1}return"function"==typeof t}(),a=function(){if("undefined"!=typeof globalThis)return globalThis;var t=function(){return this}();if(!t&&u)try{t=new Function("return this")()}catch(t){}if(!t){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return t}(),p=new Error,c=function(){function t(){this._exception=p}return t.prototype.hasCaught=function(){return this._exception!==p},t.prototype.exception=function(){return this._exception},t.prototype.setError=function(t){this._exception=t},t.prototype.reset=function(){this._exception=p},t.prototype.extractException=function(){var t=this._exception;return this.reset(),t},t}(),f=function(){var t;try{return Boolean(null===(t=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===t?void 0:t.configurable)}catch(t){return!1}}(),h="object"==typeof Reflect,l="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,d=function(){try{var t=Symbol();new WeakRef(t),(new WeakMap).set(t,void 0)}catch(t){return!1}return!0}(),y="undefined"!=typeof BigInt;function v(t){return"object"==typeof t&&null!==t||"function"==typeof t}var _=function(){return"undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0}(),g="function"==typeof MessageChannel?MessageChannel:function(){try{return _("worker_threads").MessageChannel}catch(t){}}(),b="function"==typeof setImmediate?setImmediate:function(t){if("function"!=typeof t)throw new TypeError('The "callback" argument must be of type function');if(g){var e=new g;e.port1.onmessage=function(){e.port1.onmessage=null,e=void 0,t()},e.port2.postMessage(null)}else setTimeout(t,0)},S="function"==typeof Buffer?Buffer:function(){try{return _("buffer").Buffer}catch(t){}}(),w=function(){function t(t,e){this.id=t,this.value=e}return t.prototype.init=function(t,e){this.id=t,this.value=e},t.prototype.data=function(t){return t.getObjectBinding(this.value).data},t.prototype.isEmpty=function(){return 0===this.id},t.prototype.isNumber=function(){return!this.isEmpty()&&"number"==typeof this.value},t.prototype.isBigInt=function(){return!this.isEmpty()&&"bigint"==typeof this.value},t.prototype.isString=function(){return!this.isEmpty()&&"string"==typeof this.value},t.prototype.isFunction=function(){return!this.isEmpty()&&"function"==typeof this.value},t.prototype.isExternal=function(){return!this.isEmpty()&&v(this.value)&&null===Object.getPrototypeOf(this.value)},t.prototype.isObject=function(){return!this.isEmpty()&&"object"==typeof this.value&&null!==this.value},t.prototype.isArray=function(){return!this.isEmpty()&&Array.isArray(this.value)},t.prototype.isArrayBuffer=function(){return!this.isEmpty()&&this.value instanceof ArrayBuffer},t.prototype.isTypedArray=function(){return!this.isEmpty()&&ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)},t.prototype.isBuffer=function(){return!this.isEmpty()&&"function"==typeof S&&S.isBuffer(this.value)},t.prototype.isDataView=function(){return!this.isEmpty()&&this.value instanceof DataView},t.prototype.isDate=function(){return!this.isEmpty()&&this.value instanceof Date},t.prototype.isPromise=function(){return!this.isEmpty()&&this.value instanceof Promise},t.prototype.isBoolean=function(){return!this.isEmpty()&&"boolean"==typeof this.value},t.prototype.isUndefined=function(){return!this.isEmpty()&&void 0===this.value},t.prototype.isSymbol=function(){return!this.isEmpty()&&"symbol"==typeof this.value},t.prototype.isNull=function(){return!this.isEmpty()&&null===this.value},t.prototype.dispose=function(){0!==this.id&&(this.id=0,this.value=void 0)},t}(),m=function(t){function e(e,n){return t.call(this,e,n)||this}return r(e,t),e.prototype.dispose=function(){},e}(w);function k(){Object.setPrototypeOf(this,null)}k.prototype=null;var E=function(){function t(){this._values=[void 0,t.UNDEFINED,t.NULL,t.FALSE,t.TRUE,t.GLOBAL],this._next=t.MIN_ID}return t.prototype.push=function(t){var e,n=this._next,i=this._values;return n<i.length?(e=i[n]).init(n,t):(e=new w(n,t),i[n]=e),this._next++,e},t.prototype.erase=function(t,e){this._next=t;for(var n=this._values,i=t;i<e;++i)n[i].dispose()},t.prototype.get=function(t){return this._values[t]},t.prototype.swap=function(t,e){var n=this._values,i=n[t];n[t]=n[e],n[t].id=Number(t),n[e]=i,i.id=Number(e)},t.prototype.dispose=function(){this._values.length=t.MIN_ID,this._next=t.MIN_ID},t.UNDEFINED=new m(1,void 0),t.NULL=new m(2,null),t.FALSE=new m(3,!1),t.TRUE=new m(4,!0),t.GLOBAL=new m(5,a),t.MIN_ID=6,t}(),C=function(){function t(t,e,n,i,r){void 0===r&&(r=i),this.handleStore=t,this.id=e,this.parent=n,this.child=null,null!==n&&(n.child=this),this.start=i,this.end=r,this._escapeCalled=!1}return t.prototype.add=function(t){var e=this.handleStore.push(t);return this.end++,e},t.prototype.addExternal=function(t,e){var n=new k,i=t.ctx.handleStore.push(n);return t.initObjectBinding(n).data=e,this.end++,i},t.prototype.dispose=function(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)},t.prototype.escape=function(t){if(this._escapeCalled)return null;if(this._escapeCalled=!0,t<this.start||t>=this.end)return null;this.handleStore.swap(t,this.start);var e=this.handleStore.get(this.start);return this.start++,this.parent.end++,e},t.prototype.escapeCalled=function(){return this._escapeCalled},t}(),z=function(){function t(){this._rootScope=new C(null,0,null,1,E.MIN_ID),this.currentScope=this._rootScope}return t.prototype.get=function(t){t=Number(t);for(var e=this.currentScope;e!==this._rootScope;){if(e.id===t)return e;e=e.parent}},t.prototype.openScope=function(t){var e=this.currentScope,n=e.child;return null!==n?(n.start=n.end=e.end,n._escapeCalled=!1):n=new C(t.ctx.handleStore,e.id+1,e,e.end),this.currentScope=n,t.openHandleScopes++,n},t.prototype.closeScope=function(t){if(0!==t.openHandleScopes){var e=this.currentScope;this.currentScope=e.parent,e.dispose(),t.openHandleScopes--}},t.prototype.dispose=function(){for(var t=this.currentScope;null!==t;){t.handleStore=null,t.id=0,t.parent=null,t.start=E.MIN_ID,t.end=E.MIN_ID,t._escapeCalled=!1;var e=t.child;t.child=null,t=e}this.currentScope=null},t}(),x=function(t){function e(){return t.call(this,8)||this}return r(e,t),e}(o),O=function(t){function e(){return t.call(this,8)||this}return r(e,t),e}(o),D=function(){function t(){this._next=null,this._prev=null}return t.prototype.finalize=function(){},t.prototype.link=function(t){this._prev=t,this._next=t._next,null!==this._next&&(this._next._prev=this),t._next=this},t.prototype.unlink=function(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null},t.finalizeAll=function(t){for(;null!==t._next;)t._next.finalize()},t}(),H=function(){function t(t,e,n,i){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.envObject=t,this._finalizeCallback=e,this._finalizeData=n,this._finalizeHint=i}return t.prototype.callback=function(){return this._finalizeCallback},t.prototype.data=function(){return this._finalizeData},t.prototype.hint=function(){return this._finalizeHint},t.prototype.resetFinalizer=function(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0},t.prototype.dispose=function(){this.envObject=void 0},t}(),j=function(t){function e(e,n,i,r,o,s){var u=t.call(this,e,r,o,s)||this;return u._next=null,u._prev=null,u._refcount=n,u._ownership=i,u.link(r?e.finalizing_reflist:e.reflist),u}return r(e,t),e.finalizeAll=function(t){D.finalizeAll(t)},e.prototype.link=function(t){D.prototype.link.call(this,t)},e.prototype.unlink=function(){D.prototype.unlink.call(this)},e.prototype.dispose=function(){this.unlink(),this.envObject.dequeueFinalizer(this),t.prototype.dispose.call(this)},e.prototype.data=function(){return this._finalizeData},e.prototype.ref=function(){return++this._refcount},e.prototype.unref=function(){return 0===this._refcount?0:--this._refcount},e.prototype.refCount=function(){return this._refcount},e.prototype.ownership=function(){return this._ownership},e.prototype.finalize=function(){var t,e=this._ownership,n=this._finalizeCallback,i=this._finalizeData,r=this._finalizeHint;this.resetFinalizer(),this.unlink();var o=!1;if(n){var s=Number(n);try{this.envObject.callFinalizer(s,i,r)}catch(e){o=!0,t=e}}if(0===e&&this.dispose(),o)throw t},e}(H),F=function(){function t(t,e,n){this.ctx=t,this.makeDynCall_vppp=e,this.makeDynCall_vp=n,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new c,this.refs=1,this.reflist=new D,this.finalizing_reflist=new D,this.destructing=!1,this.finalizationScheduled=!1,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}return t.create=function(e,n,i){var r=new t(e,n,i);return e.envStore.add(r),e.addCleanupHook(r,(function(){r.unref()}),0),r},t.prototype.ref=function(){this.refs++},t.prototype.unref=function(){this.refs--,0===this.refs&&this.dispose()},t.prototype.ensureHandle=function(t){return this.ctx.ensureHandle(t)},t.prototype.ensureHandleId=function(t){return this.ensureHandle(t).id},t.prototype.clearLastError=function(){var t=this.lastError;return t.errorCode=0,t.engineErrorCode=0,t.engineReserved=0,0},t.prototype.setLastError=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=0);var i=this.lastError;return i.errorCode=t,i.engineErrorCode=e,i.engineReserved=n,t},t.prototype.getReturnStatus=function(){return this.tryCatch.hasCaught()?this.setLastError(10):0},t.prototype.callIntoModule=function(t){this.clearLastError();var e=t(this);if(this.tryCatch.hasCaught())throw this.tryCatch.extractException();return e},t.prototype.callFinalizer=function(t,e,n){var i=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callIntoModule((function(){i(r,e,n)}))}finally{this.ctx.closeScope(this,o)}},t.prototype.enqueueFinalizer=function(t){var e=this;-1===this.pendingFinalizers.indexOf(t)&&this.pendingFinalizers.push(t),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),b((function(){e.finalizationScheduled=!1,e.unref(),e.drainFinalizerQueue()})))},t.prototype.dequeueFinalizer=function(t){var e=this.pendingFinalizers.indexOf(t);-1!==e&&this.pendingFinalizers.splice(e,1)},t.prototype.drainFinalizerQueue=function(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}},t.prototype.dispose=function(){0!==this.id&&(this.destructing=!0,this.drainFinalizerQueue(),j.finalizeAll(this.finalizing_reflist),j.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id),this.id=0)},t.prototype.initObjectBinding=function(t){var e={wrapped:0,tag:null,data:0};return this._bindingMap.set(t,e),e},t.prototype.getObjectBinding=function(t){return this._bindingMap.has(t)?this._bindingMap.get(t):this.initObjectBinding(t)},t.prototype.setInstanceData=function(t,e,n){this.instanceData&&this.instanceData.dispose(),this.instanceData=new j(this,0,0,e,t,n)},t.prototype.getInstanceData=function(){return this.instanceData?this.instanceData.data():0},t}(),I=function(t){function e(n){var i=this.constructor,r=t.call(this,n)||this,o=i,s=o.prototype;if(!(r instanceof e)){var u=Object.setPrototypeOf;"function"==typeof u?u.call(Object,r,s):r.__proto__=s,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(r,o)}return r}return r(e,t),e}(Error);Object.defineProperty(I.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});var N=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "FinalizationRegistry" and "WeakRef".').concat(n?" ".concat(n):""))||this}return r(e,t),e}(I);Object.defineProperty(N.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});var B=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "BigInt".').concat(n?" ".concat(n):""))||this}return r(e,t),e}(I);Object.defineProperty(B.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});var R=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "Buffer". Consider using buffer polyfill to make sure `globalThis.Buffer` is defined.').concat(n?" ".concat(n):""))||this}return r(e,t),e}(I);Object.defineProperty(R.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});var L=function(){function t(t){this._value=t}return t.prototype.deref=function(){return this._value},t.prototype.dispose=function(){this._value=void 0},t}(),T=function(){function t(t){this._ref=new L(t)}return t.prototype.setWeak=function(e,n){if(l&&void 0!==this._ref&&!(this._ref instanceof WeakRef)){var i=this._ref.deref();try{t._registry.register(i,this,this);var r=new WeakRef(i);this._ref.dispose(),this._ref=r,this._param=e,this._callback=n}catch(t){}}},t.prototype.clearWeak=function(){if(l&&void 0!==this._ref&&this._ref instanceof WeakRef){try{t._registry.unregister(this)}catch(t){}this._param=void 0,this._callback=void 0;var e=this._ref.deref();this._ref=void 0===e?e:new L(e)}},t.prototype.reset=function(){if(l)try{t._registry.unregister(this)}catch(t){}this._param=void 0,this._callback=void 0,this._ref instanceof L&&this._ref.dispose(),this._ref=void 0},t.prototype.isEmpty=function(){return void 0===this._ref},t.prototype.deref=function(){if(void 0!==this._ref)return this._ref.deref()},t._registry=l?new FinalizationRegistry((function(t){t._ref=void 0;var e=t._callback,n=t._param;t._callback=void 0,t._param=void 0,"function"==typeof e&&e(n)})):void 0,t}();function M(t){t.persistent.reset(),t.envObject.enqueueFinalizer(t)}var W,A=function(t){function e(e,n,i,r,o,s){void 0===r&&(r=0),void 0===o&&(o=0),void 0===s&&(s=0);var u=t.call(this,e,n>>>0,i,r,o,s)||this;return u.id=0,u}return r(e,t),e.create=function(t,n,i,r,o,s,u){void 0===o&&(o=0),void 0===s&&(s=0),void 0===u&&(u=0);var a=t.ctx.handleStore.get(n),p=new e(t,i,r,o,s,u);return t.ctx.refStore.add(p),p.persistent=new T(a.value),0===i&&p._setWeak(),p},e.prototype.ref=function(){if(this.persistent.isEmpty())return 0;var e=t.prototype.ref.call(this);1===e&&(this.persistent.deref()&&this.persistent.clearWeak());return e},e.prototype.unref=function(){if(this.persistent.isEmpty())return 0;var e=this.refCount(),n=t.prototype.unref.call(this);1===e&&0===n&&(this.persistent.deref()&&this._setWeak());return n},e.prototype.get=function(){var t=this.persistent.deref();return t?this.envObject.ensureHandle(t).id:0},e.prototype._setWeak=function(){this.persistent.setWeak(this,M)},e.prototype.finalize=function(){this.persistent.reset(),t.prototype.finalize.call(this)},e.prototype.dispose=function(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),t.prototype.dispose.call(this),this.id=0)},e}(j),P=function(){function t(t,e){this.id=0,this.ctx=t,this.value=e}return t.create=function(e,n){var i=new t(e,n);return e.deferredStore.add(i),i},t.prototype.resolve=function(t){this.value.resolve(t),this.dispose()},t.prototype.reject=function(t){this.value.reject(t),this.dispose()},t.prototype.dispose=function(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null},t}(),q=function(){return function(t,e,n,i){this.envObject=t,this.fn=e,this.arg=n,this.order=i}}(),U=function(){function t(){this._cleanupHooks=[],this._cleanupHookCounter=0}return t.prototype.empty=function(){return 0===this._cleanupHooks.length},t.prototype.add=function(t,e,n){if(this._cleanupHooks.filter((function(i){return i.envObject===t&&i.fn===e&&i.arg===n})).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new q(t,e,n,this._cleanupHookCounter++))},t.prototype.remove=function(t,e,n){for(var i=0;i<this._cleanupHooks.length;++i){var r=this._cleanupHooks[i];if(r.envObject===t&&r.fn===e&&r.arg===n)return void this._cleanupHooks.splice(i,1)}},t.prototype.drain=function(){var t=this._cleanupHooks.slice();t.sort((function(t,e){return e.order-t.order}));for(var e=0;e<t.length;++e){var n=t[e];"number"==typeof n.fn?n.envObject.makeDynCall_vp(n.fn)(n.arg):n.fn(n.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(n),1)}},t.prototype.dispose=function(){this._cleanupHooks.length=0,this._cleanupHookCounter=0},t}(),Q=function(){function t(){this.refHandle=(new g).port1,this.count=0}return t.prototype.increase=function(){0===this.count&&this.refHandle.ref(),this.count++},t.prototype.decrease=function(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)},t}(),V=function(){function t(){var t=this;this.envStore=new s,this.scopeStore=new z,this.refStore=new x,this.deferredStore=new O,this.handleStore=new E,this.cbinfoStack=new n,this.feature={supportReflect:h,supportFinalizer:l,supportWeakSymbol:d,supportBigInt:y,supportNewFunction:u,canSetFunctionName:f,setImmediate:b,Buffer:S,MessageChannel:g},this.cleanupQueue=new U,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new Q,process.once("beforeExit",(function(){t.runCleanup()})))}return t.prototype.createNotSupportWeakRefError=function(t,e){return new N(t,e)},t.prototype.createNotSupportBigIntError=function(t,e){return new B(t,e)},t.prototype.createNotSupportBufferError=function(t,e){return new R(t,e)},t.prototype.createReference=function(t,e,n,i,r,o,s){return void 0===r&&(r=0),void 0===o&&(o=0),void 0===s&&(s=0),A.create(t,e,n,i,r,o,s)},t.prototype.createDeferred=function(t){return P.create(this,t)},t.prototype.createEnv=function(t,e){return F.create(this,t,e)},t.prototype.getCurrentScope=function(){return this.scopeStore.currentScope},t.prototype.addToCurrentScope=function(t){return this.scopeStore.currentScope.add(t)},t.prototype.openScope=function(t){return this.scopeStore.openScope(t)},t.prototype.closeScope=function(t,e){this.scopeStore.closeScope(t)},t.prototype.ensureHandle=function(t){switch(t){case void 0:return E.UNDEFINED;case null:return E.NULL;case!0:return E.TRUE;case!1:return E.FALSE;case a:return E.GLOBAL}return this.addToCurrentScope(t)},t.prototype.addCleanupHook=function(t,e,n){this.cleanupQueue.add(t,e,n)},t.prototype.removeCleanupHook=function(t,e,n){this.cleanupQueue.remove(t,e,n)},t.prototype.runCleanup=function(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()},t.prototype.increaseWaitingRequestCounter=function(){var t;null===(t=this.refCounter)||void 0===t||t.increase()},t.prototype.decreaseWaitingRequestCounter=function(){var t;null===(t=this.refCounter)||void 0===t||t.decrease()},t.prototype.dispose=function(){this.runCleanup()},t}();function G(){return new V}t.CallbackInfo=e,t.CallbackInfoStack=n,t.ConstHandle=m,t.Context=V,t.Deferred=P,t.DeferredStore=O,t.EmnapiError=I,t.Env=F,t.EnvStore=s,t.Finalizer=H,t.Handle=w,t.HandleScope=C,t.HandleStore=E,t.NotSupportBigIntError=B,t.NotSupportBufferError=R,t.NotSupportWeakRefError=N,t.Persistent=T,t.RefBase=j,t.RefStore=x,t.RefTracker=D,t.Reference=A,t.ScopeStore=z,t.Store=o,t.TryCatch=c,t.createContext=G,t.getDefaultContext=function(){return W||(W=G()),W},t.isReferenceType=v,t.version="0.38.3",Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/emnapi.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class e{constructor(e,t,i,s,n){this.parent=e,this.thiz=t,this.data=i,this.args=s,this.fn=n}getNewTarget(e){const t=this.thiz;return null==t||null==t.constructor?0:t instanceof this.fn?e.ensureHandleId(t.constructor):0}}class t{constructor(){this.current=null}pop(){const e=this.current;null!==e&&(this.current=e.parent)}push(t,i,s,n){const r=new e(this.current,t,i,s,n);return this.current=r,r}dispose(){this.current=null}}class i{constructor(e){this._values=[void 0],this._values.length=e,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=Math.ceil(1.5*e))}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}class s extends i{constructor(){super(2)}}const n=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),r=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&n)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}(),o=new Error;class a{constructor(){this._exception=o}hasCaught(){return this._exception!==o}exception(){return this._exception}setError(e){this._exception=e}reset(){this._exception=o}extractException(){const e=this._exception;return this.reset(),e}}const u=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),c="object"==typeof Reflect,l="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),p="undefined"!=typeof BigInt;function f(e){return"object"==typeof e&&null!==e||"function"==typeof e}const d="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)return;let t=new MessageChannel;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)},_=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),v=function(){if("function"==typeof r.Buffer)return r.Buffer;try{return _("buffer").Buffer}catch(e){}}();class y{constructor(e,t){this.id=e,this.value=t}init(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isEmpty(){return 0===this.id}isNumber(){return!this.isEmpty()&&"number"==typeof this.value}isBigInt(){return!this.isEmpty()&&"bigint"==typeof this.value}isString(){return!this.isEmpty()&&"string"==typeof this.value}isFunction(){return!this.isEmpty()&&"function"==typeof this.value}isExternal(){return!this.isEmpty()&&f(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return!this.isEmpty()&&"object"==typeof this.value&&null!==this.value}isArray(){return!this.isEmpty()&&Array.isArray(this.value)}isArrayBuffer(){return!this.isEmpty()&&this.value instanceof ArrayBuffer}isTypedArray(){return!this.isEmpty()&&ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(){return!this.isEmpty()&&"function"==typeof v&&v.isBuffer(this.value)}isDataView(){return!this.isEmpty()&&this.value instanceof DataView}isDate(){return!this.isEmpty()&&this.value instanceof Date}isPromise(){return!this.isEmpty()&&this.value instanceof Promise}isBoolean(){return!this.isEmpty()&&"boolean"==typeof this.value}isUndefined(){return!this.isEmpty()&&void 0===this.value}isSymbol(){return!this.isEmpty()&&"symbol"==typeof this.value}isNull(){return!this.isEmpty()&&null===this.value}dispose(){0!==this.id&&(this.id=0,this.value=void 0)}}class g extends y{constructor(e,t){super(e,t)}dispose(){}}function b(){Object.setPrototypeOf(this,null)}b.prototype=null;class w{constructor(){this._values=[void 0,w.UNDEFINED,w.NULL,w.FALSE,w.TRUE,w.GLOBAL],this._next=w.MIN_ID}push(e){let t;const i=this._next,s=this._values;return i<s.length?(t=s[i],t.init(i,e)):(t=new y(i,e),s[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let s=e;s<t;++s)i[s].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,s=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=s,s.id=Number(t)}dispose(){this._values.length=w.MIN_ID,this._next=w.MIN_ID}}w.UNDEFINED=new g(1,void 0),w.NULL=new g(2,null),w.FALSE=new g(3,!1),w.TRUE=new g(4,!0),w.GLOBAL=new g(5,r),w.MIN_ID=6;class S{constructor(e,t,i,s,n=s){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=s,this.end=n,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const i=new b,s=e.ctx.handleStore.push(i);return e.initObjectBinding(i).data=t,this.end++,s}dispose(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class m{constructor(){this._rootScope=new S(null,0,null,1,w.MIN_ID),this.currentScope=this._rootScope}get(e){e=Number(e);let t=this.currentScope;for(;t!==this._rootScope;){if(t.id===e)return t;t=t.parent}}openScope(e){const t=this.currentScope;let i=t.child;return null!==i?(i.start=i.end=t.end,i._escapeCalled=!1):i=new S(e.ctx.handleStore,t.id+1,t,t.end),this.currentScope=i,e.openHandleScopes++,i}closeScope(e){if(0===e.openHandleScopes)return;const t=this.currentScope;this.currentScope=t.parent,t.dispose(),e.openHandleScopes--}dispose(){let e=this.currentScope;for(;null!==e;){e.handleStore=null,e.id=0,e.parent=null,e.start=w.MIN_ID,e.end=w.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class k extends i{constructor(){super(8)}}class E extends i{constructor(){super(8)}}class x{constructor(){this._next=null,this._prev=null}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class z{constructor(e,t=0,i=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=s}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}dispose(){this.envObject=void 0}}class C extends z{constructor(e,t,i,s,n,r){super(e,s,n,r),this._next=null,this._prev=null,this._refcount=t,this._ownership=i,this.link(s?e.finalizing_reflist:e.reflist)}static finalizeAll(e){x.finalizeAll(e)}link(e){x.prototype.link.call(this,e)}unlink(){x.prototype.unlink.call(this)}dispose(){this.unlink(),this.envObject.dequeueFinalizer(this),super.dispose()}data(){return this._finalizeData}ref(){return++this._refcount}unref(){return 0===this._refcount?0:--this._refcount}refCount(){return this._refcount}ownership(){return this._ownership}finalize(){const e=this._ownership,t=this._finalizeCallback,i=this._finalizeData,s=this._finalizeHint;let n;this.resetFinalizer(),this.unlink();let r=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,i,s)}catch(e){r=!0,n=e}}if(0===e&&this.dispose(),r)throw n}}class D{constructor(e,t,i){this.ctx=e,this.makeDynCall_vppp=t,this.makeDynCall_vp=i,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new a,this.refs=1,this.reflist=new x,this.finalizing_reflist=new x,this.destructing=!1,this.finalizationScheduled=!1,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}static create(e,t,i){const s=new D(e,t,i);return e.envStore.add(s),e.addCleanupHook(s,(()=>{s.unref()}),0),s}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return e.errorCode=0,e.engineErrorCode=0,e.engineReserved=0,0}setLastError(e,t=0,i=0){const s=this.lastError;return s.errorCode=e,s.engineErrorCode=t,s.engineReserved=i,e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e){this.clearLastError();const t=e(this);if(this.tryCatch.hasCaught()){throw this.tryCatch.extractException()}return t}callFinalizer(e,t,i){const s=this.makeDynCall_vppp(e),n=this.id,r=this.ctx.openScope(this);try{this.callIntoModule((()=>{s(n,t,i)}))}finally{this.ctx.closeScope(this,r)}}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),d((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}dispose(){0!==this.id&&(this.destructing=!0,this.drainFinalizerQueue(),C.finalizeAll(this.finalizing_reflist),C.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null,data:0};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,i){this.instanceData&&this.instanceData.dispose(),this.instanceData=new C(this,0,0,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class O extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof O)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,i):this.__proto__=i,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(O.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class H extends O{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class F extends O{constructor(e,t){super(`${e}: The current runtime does not support "BigInt".${t?` ${t}`:""}`)}}Object.defineProperty(F.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});class j extends O{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(j.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class I{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class N{constructor(e){this._ref=new I(e)}setWeak(e,t){if(!l||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{N._registry.register(i,this,this);const s=new WeakRef(i);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){}}clearWeak(){if(l&&void 0!==this._ref&&this._ref instanceof WeakRef){try{N._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new I(e)}}reset(){if(l)try{N._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof I&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}function B(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}N._registry=l?new FinalizationRegistry((e=>{e._ref=void 0;const t=e._callback,i=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(i)})):void 0;class L extends C{constructor(e,t,i,s=0,n=0,r=0){super(e,t>>>0,i,s,n,r),this.id=0}static create(e,t,i,s,n=0,r=0,o=0){const a=e.ctx.handleStore.get(t),u=new L(e,i,s,n,r,o);return e.ctx.refStore.add(u),u.persistent=new N(a.value),0===i&&u._setWeak(),u}ref(){if(this.persistent.isEmpty())return 0;const e=super.ref();if(1===e){this.persistent.deref()&&this.persistent.clearWeak()}return e}unref(){if(this.persistent.isEmpty())return 0;const e=this.refCount(),t=super.unref();if(1===e&&0===t){this.persistent.deref()&&this._setWeak()}return t}get(){const e=this.persistent.deref();if(e){return this.envObject.ensureHandle(e).id}return 0}_setWeak(){this.persistent.setWeak(this,B)}finalize(){this.persistent.reset(),super.finalize()}dispose(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.id=0)}}class R{constructor(e,t){this.id=0,this.ctx=e,this.value=t}static create(e,t){const i=new R(e,t);return e.deferredStore.add(i),i}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class W{constructor(e,t,i,s){this.envObject=e,this.fn=t,this.arg=i,this.order=s}}class M{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter((s=>s.envObject===e&&s.fn===t&&s.arg===i)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new W(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let s=0;s<this._cleanupHooks.length;++s){const n=this._cleanupHooks[s];if(n.envObject===e&&n.fn===t&&n.arg===i)return void this._cleanupHooks.splice(s,1)}}drain(){const e=this._cleanupHooks.slice();e.sort(((e,t)=>t.order-e.order));for(let t=0;t<e.length;++t){const i=e[t];"number"==typeof i.fn?i.envObject.makeDynCall_vp(i.fn)(i.arg):i.fn(i.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(i),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class A{constructor(){this.refHandle=(new MessageChannel).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)}}class T{constructor(){this.envStore=new s,this.scopeStore=new m,this.refStore=new k,this.deferredStore=new E,this.handleStore=new w,this.cbinfoStack=new t,this.feature={supportReflect:c,supportFinalizer:l,supportWeakSymbol:h,supportBigInt:p,supportNewFunction:n,canSetFunctionName:u,setImmediate:d,Buffer:v},this.cleanupQueue=new M,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new A,process.once("beforeExit",(()=>{this.runCleanup()})))}createNotSupportWeakRefError(e,t){return new H(e,t)}createNotSupportBigIntError(e,t){return new F(e,t)}createNotSupportBufferError(e,t){return new j(e,t)}createReference(e,t,i,s,n=0,r=0,o=0){return L.create(e,t,i,s,n,r,o)}createDeferred(e){return R.create(this,e)}createEnv(e,t){return D.create(this,e,t)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){return this.scopeStore.openScope(e)}closeScope(e,t){this.scopeStore.closeScope(e)}ensureHandle(e){switch(e){case void 0:return w.UNDEFINED;case null:return w.NULL;case!0:return w.TRUE;case!1:return w.FALSE;case r:return w.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,i){this.cleanupQueue.add(e,t,i)}removeCleanupHook(e,t,i){this.cleanupQueue.remove(e,t,i)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}dispose(){this.runCleanup()}}let q;function P(){return new T}function U(){return q||(q=P()),q}const $="0.38.2";export{e as CallbackInfo,t as CallbackInfoStack,g as ConstHandle,T as Context,R as Deferred,E as DeferredStore,O as EmnapiError,D as Env,s as EnvStore,z as Finalizer,y as Handle,S as HandleScope,w as HandleStore,F as NotSupportBigIntError,j as NotSupportBufferError,H as NotSupportWeakRefError,N as Persistent,C as RefBase,k as RefStore,x as RefTracker,L as Reference,m as ScopeStore,i as Store,a as TryCatch,P as createContext,U as getDefaultContext,f as isReferenceType,$ as version};
|
|
1
|
+
class e{constructor(e,t,i,s,n){this.parent=e,this.thiz=t,this.data=i,this.args=s,this.fn=n}getNewTarget(e){const t=this.thiz;return null==t||null==t.constructor?0:t instanceof this.fn?e.ensureHandleId(t.constructor):0}}class t{constructor(){this.current=null}pop(){const e=this.current;null!==e&&(this.current=e.parent)}push(t,i,s,n){const r=new e(this.current,t,i,s,n);return this.current=r,r}dispose(){this.current=null}}class i{constructor(e){this._values=[void 0],this._values.length=e,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=Math.ceil(1.5*e))}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}class s extends i{constructor(){super(2)}}const n=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),r=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&n)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}(),o=new Error;class a{constructor(){this._exception=o}hasCaught(){return this._exception!==o}exception(){return this._exception}setError(e){this._exception=e}reset(){this._exception=o}extractException(){const e=this._exception;return this.reset(),e}}const u=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),c="object"==typeof Reflect,l="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),p="undefined"!=typeof BigInt;function f(e){return"object"==typeof e&&null!==e||"function"==typeof e}const d=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),_="function"==typeof MessageChannel?MessageChannel:function(){try{return d("worker_threads").MessageChannel}catch(e){}}(),v="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(_){let t=new _;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},y="function"==typeof Buffer?Buffer:function(){try{return d("buffer").Buffer}catch(e){}}();class g{constructor(e,t){this.id=e,this.value=t}init(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isEmpty(){return 0===this.id}isNumber(){return!this.isEmpty()&&"number"==typeof this.value}isBigInt(){return!this.isEmpty()&&"bigint"==typeof this.value}isString(){return!this.isEmpty()&&"string"==typeof this.value}isFunction(){return!this.isEmpty()&&"function"==typeof this.value}isExternal(){return!this.isEmpty()&&f(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return!this.isEmpty()&&"object"==typeof this.value&&null!==this.value}isArray(){return!this.isEmpty()&&Array.isArray(this.value)}isArrayBuffer(){return!this.isEmpty()&&this.value instanceof ArrayBuffer}isTypedArray(){return!this.isEmpty()&&ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(){return!this.isEmpty()&&"function"==typeof y&&y.isBuffer(this.value)}isDataView(){return!this.isEmpty()&&this.value instanceof DataView}isDate(){return!this.isEmpty()&&this.value instanceof Date}isPromise(){return!this.isEmpty()&&this.value instanceof Promise}isBoolean(){return!this.isEmpty()&&"boolean"==typeof this.value}isUndefined(){return!this.isEmpty()&&void 0===this.value}isSymbol(){return!this.isEmpty()&&"symbol"==typeof this.value}isNull(){return!this.isEmpty()&&null===this.value}dispose(){0!==this.id&&(this.id=0,this.value=void 0)}}class b extends g{constructor(e,t){super(e,t)}dispose(){}}function w(){Object.setPrototypeOf(this,null)}w.prototype=null;class m{constructor(){this._values=[void 0,m.UNDEFINED,m.NULL,m.FALSE,m.TRUE,m.GLOBAL],this._next=m.MIN_ID}push(e){let t;const i=this._next,s=this._values;return i<s.length?(t=s[i],t.init(i,e)):(t=new g(i,e),s[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let s=e;s<t;++s)i[s].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,s=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=s,s.id=Number(t)}dispose(){this._values.length=m.MIN_ID,this._next=m.MIN_ID}}m.UNDEFINED=new b(1,void 0),m.NULL=new b(2,null),m.FALSE=new b(3,!1),m.TRUE=new b(4,!0),m.GLOBAL=new b(5,r),m.MIN_ID=6;class S{constructor(e,t,i,s,n=s){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=s,this.end=n,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const i=new w,s=e.ctx.handleStore.push(i);return e.initObjectBinding(i).data=t,this.end++,s}dispose(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class k{constructor(){this._rootScope=new S(null,0,null,1,m.MIN_ID),this.currentScope=this._rootScope}get(e){e=Number(e);let t=this.currentScope;for(;t!==this._rootScope;){if(t.id===e)return t;t=t.parent}}openScope(e){const t=this.currentScope;let i=t.child;return null!==i?(i.start=i.end=t.end,i._escapeCalled=!1):i=new S(e.ctx.handleStore,t.id+1,t,t.end),this.currentScope=i,e.openHandleScopes++,i}closeScope(e){if(0===e.openHandleScopes)return;const t=this.currentScope;this.currentScope=t.parent,t.dispose(),e.openHandleScopes--}dispose(){let e=this.currentScope;for(;null!==e;){e.handleStore=null,e.id=0,e.parent=null,e.start=m.MIN_ID,e.end=m.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class E extends i{constructor(){super(8)}}class x extends i{constructor(){super(8)}}class z{constructor(){this._next=null,this._prev=null}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class C{constructor(e,t=0,i=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=s}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}dispose(){this.envObject=void 0}}class D extends C{constructor(e,t,i,s,n,r){super(e,s,n,r),this._next=null,this._prev=null,this._refcount=t,this._ownership=i,this.link(s?e.finalizing_reflist:e.reflist)}static finalizeAll(e){z.finalizeAll(e)}link(e){z.prototype.link.call(this,e)}unlink(){z.prototype.unlink.call(this)}dispose(){this.unlink(),this.envObject.dequeueFinalizer(this),super.dispose()}data(){return this._finalizeData}ref(){return++this._refcount}unref(){return 0===this._refcount?0:--this._refcount}refCount(){return this._refcount}ownership(){return this._ownership}finalize(){const e=this._ownership,t=this._finalizeCallback,i=this._finalizeData,s=this._finalizeHint;let n;this.resetFinalizer(),this.unlink();let r=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,i,s)}catch(e){r=!0,n=e}}if(0===e&&this.dispose(),r)throw n}}class O{constructor(e,t,i){this.ctx=e,this.makeDynCall_vppp=t,this.makeDynCall_vp=i,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new a,this.refs=1,this.reflist=new z,this.finalizing_reflist=new z,this.destructing=!1,this.finalizationScheduled=!1,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}static create(e,t,i){const s=new O(e,t,i);return e.envStore.add(s),e.addCleanupHook(s,(()=>{s.unref()}),0),s}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return e.errorCode=0,e.engineErrorCode=0,e.engineReserved=0,0}setLastError(e,t=0,i=0){const s=this.lastError;return s.errorCode=e,s.engineErrorCode=t,s.engineReserved=i,e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e){this.clearLastError();const t=e(this);if(this.tryCatch.hasCaught()){throw this.tryCatch.extractException()}return t}callFinalizer(e,t,i){const s=this.makeDynCall_vppp(e),n=this.id,r=this.ctx.openScope(this);try{this.callIntoModule((()=>{s(n,t,i)}))}finally{this.ctx.closeScope(this,r)}}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),v((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}dispose(){0!==this.id&&(this.destructing=!0,this.drainFinalizerQueue(),D.finalizeAll(this.finalizing_reflist),D.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null,data:0};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,i){this.instanceData&&this.instanceData.dispose(),this.instanceData=new D(this,0,0,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class H extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof H)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,i):this.__proto__=i,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class F extends H{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(F.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class j extends H{constructor(e,t){super(`${e}: The current runtime does not support "BigInt".${t?` ${t}`:""}`)}}Object.defineProperty(j.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});class I extends H{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(I.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class N{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class B{constructor(e){this._ref=new N(e)}setWeak(e,t){if(!l||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{B._registry.register(i,this,this);const s=new WeakRef(i);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){}}clearWeak(){if(l&&void 0!==this._ref&&this._ref instanceof WeakRef){try{B._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new N(e)}}reset(){if(l)try{B._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof N&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}function L(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}B._registry=l?new FinalizationRegistry((e=>{e._ref=void 0;const t=e._callback,i=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(i)})):void 0;class R extends D{constructor(e,t,i,s=0,n=0,r=0){super(e,t>>>0,i,s,n,r),this.id=0}static create(e,t,i,s,n=0,r=0,o=0){const a=e.ctx.handleStore.get(t),u=new R(e,i,s,n,r,o);return e.ctx.refStore.add(u),u.persistent=new B(a.value),0===i&&u._setWeak(),u}ref(){if(this.persistent.isEmpty())return 0;const e=super.ref();if(1===e){this.persistent.deref()&&this.persistent.clearWeak()}return e}unref(){if(this.persistent.isEmpty())return 0;const e=this.refCount(),t=super.unref();if(1===e&&0===t){this.persistent.deref()&&this._setWeak()}return t}get(){const e=this.persistent.deref();if(e){return this.envObject.ensureHandle(e).id}return 0}_setWeak(){this.persistent.setWeak(this,L)}finalize(){this.persistent.reset(),super.finalize()}dispose(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.id=0)}}class M{constructor(e,t){this.id=0,this.ctx=e,this.value=t}static create(e,t){const i=new M(e,t);return e.deferredStore.add(i),i}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class W{constructor(e,t,i,s){this.envObject=e,this.fn=t,this.arg=i,this.order=s}}class A{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter((s=>s.envObject===e&&s.fn===t&&s.arg===i)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new W(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let s=0;s<this._cleanupHooks.length;++s){const n=this._cleanupHooks[s];if(n.envObject===e&&n.fn===t&&n.arg===i)return void this._cleanupHooks.splice(s,1)}}drain(){const e=this._cleanupHooks.slice();e.sort(((e,t)=>t.order-e.order));for(let t=0;t<e.length;++t){const i=e[t];"number"==typeof i.fn?i.envObject.makeDynCall_vp(i.fn)(i.arg):i.fn(i.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(i),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class T{constructor(){this.refHandle=(new _).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)}}class q{constructor(){this.envStore=new s,this.scopeStore=new k,this.refStore=new E,this.deferredStore=new x,this.handleStore=new m,this.cbinfoStack=new t,this.feature={supportReflect:c,supportFinalizer:l,supportWeakSymbol:h,supportBigInt:p,supportNewFunction:n,canSetFunctionName:u,setImmediate:v,Buffer:y,MessageChannel:_},this.cleanupQueue=new A,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new T,process.once("beforeExit",(()=>{this.runCleanup()})))}createNotSupportWeakRefError(e,t){return new F(e,t)}createNotSupportBigIntError(e,t){return new j(e,t)}createNotSupportBufferError(e,t){return new I(e,t)}createReference(e,t,i,s,n=0,r=0,o=0){return R.create(e,t,i,s,n,r,o)}createDeferred(e){return M.create(this,e)}createEnv(e,t){return O.create(this,e,t)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){return this.scopeStore.openScope(e)}closeScope(e,t){this.scopeStore.closeScope(e)}ensureHandle(e){switch(e){case void 0:return m.UNDEFINED;case null:return m.NULL;case!0:return m.TRUE;case!1:return m.FALSE;case r:return m.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,i){this.cleanupQueue.add(e,t,i)}removeCleanupHook(e,t,i){this.cleanupQueue.remove(e,t,i)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}dispose(){this.runCleanup()}}let P;function U(){return new q}function $(){return P||(P=U()),P}const Q="0.38.3";export{e as CallbackInfo,t as CallbackInfoStack,b as ConstHandle,q as Context,M as Deferred,x as DeferredStore,H as EmnapiError,O as Env,s as EnvStore,C as Finalizer,g as Handle,S as HandleScope,m as HandleStore,j as NotSupportBigIntError,I as NotSupportBufferError,F as NotSupportWeakRefError,B as Persistent,D as RefBase,E as RefStore,z as RefTracker,R as Reference,k as ScopeStore,i as Store,a as TryCatch,U as createContext,$ as getDefaultContext,f as isReferenceType,Q as version};
|
package/dist/emnapi.mjs
CHANGED
|
@@ -168,19 +168,6 @@ const supportBigInt = typeof BigInt !== 'undefined';
|
|
|
168
168
|
function isReferenceType(v) {
|
|
169
169
|
return (typeof v === 'object' && v !== null) || typeof v === 'function';
|
|
170
170
|
}
|
|
171
|
-
const _setImmediate = typeof setImmediate === 'function'
|
|
172
|
-
? setImmediate
|
|
173
|
-
: function (f) {
|
|
174
|
-
if (typeof f !== 'function')
|
|
175
|
-
return;
|
|
176
|
-
let channel = new MessageChannel();
|
|
177
|
-
channel.port1.onmessage = function () {
|
|
178
|
-
channel.port1.onmessage = null;
|
|
179
|
-
channel = undefined;
|
|
180
|
-
f();
|
|
181
|
-
};
|
|
182
|
-
channel.port2.postMessage(null);
|
|
183
|
-
};
|
|
184
171
|
const _require = (function () {
|
|
185
172
|
let nativeRequire;
|
|
186
173
|
if (typeof __webpack_public_path__ !== 'undefined') {
|
|
@@ -195,15 +182,43 @@ const _require = (function () {
|
|
|
195
182
|
}
|
|
196
183
|
return nativeRequire;
|
|
197
184
|
})();
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
})();
|
|
185
|
+
const _MessageChannel = typeof MessageChannel === 'function'
|
|
186
|
+
? MessageChannel
|
|
187
|
+
: (function () {
|
|
188
|
+
try {
|
|
189
|
+
return _require('worker_threads').MessageChannel;
|
|
190
|
+
}
|
|
191
|
+
catch (_) { }
|
|
192
|
+
return undefined;
|
|
193
|
+
})();
|
|
194
|
+
const _setImmediate = typeof setImmediate === 'function'
|
|
195
|
+
? setImmediate
|
|
196
|
+
: function (callback) {
|
|
197
|
+
if (typeof callback !== 'function') {
|
|
198
|
+
throw new TypeError('The "callback" argument must be of type function');
|
|
199
|
+
}
|
|
200
|
+
if (_MessageChannel) {
|
|
201
|
+
let channel = new _MessageChannel();
|
|
202
|
+
channel.port1.onmessage = function () {
|
|
203
|
+
channel.port1.onmessage = null;
|
|
204
|
+
channel = undefined;
|
|
205
|
+
callback();
|
|
206
|
+
};
|
|
207
|
+
channel.port2.postMessage(null);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
setTimeout(callback, 0);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const _Buffer = typeof Buffer === 'function'
|
|
214
|
+
? Buffer
|
|
215
|
+
: (function () {
|
|
216
|
+
try {
|
|
217
|
+
return _require('buffer').Buffer;
|
|
218
|
+
}
|
|
219
|
+
catch (_) { }
|
|
220
|
+
return undefined;
|
|
221
|
+
})();
|
|
207
222
|
|
|
208
223
|
class Handle {
|
|
209
224
|
constructor(id, value) {
|
|
@@ -248,7 +263,7 @@ class Handle {
|
|
|
248
263
|
return !this.isEmpty() && (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
|
|
249
264
|
}
|
|
250
265
|
isBuffer() {
|
|
251
|
-
return !this.isEmpty() && typeof
|
|
266
|
+
return !this.isEmpty() && typeof _Buffer === 'function' && _Buffer.isBuffer(this.value);
|
|
252
267
|
}
|
|
253
268
|
isDataView() {
|
|
254
269
|
return !this.isEmpty() && (this.value instanceof DataView);
|
|
@@ -1012,7 +1027,7 @@ class CleanupQueue {
|
|
|
1012
1027
|
}
|
|
1013
1028
|
class NodejsWaitingRequestCounter {
|
|
1014
1029
|
constructor() {
|
|
1015
|
-
this.refHandle = new
|
|
1030
|
+
this.refHandle = new _MessageChannel().port1;
|
|
1016
1031
|
this.count = 0;
|
|
1017
1032
|
}
|
|
1018
1033
|
increase() {
|
|
@@ -1046,7 +1061,8 @@ class Context {
|
|
|
1046
1061
|
supportNewFunction,
|
|
1047
1062
|
canSetFunctionName,
|
|
1048
1063
|
setImmediate: _setImmediate,
|
|
1049
|
-
Buffer
|
|
1064
|
+
Buffer: _Buffer,
|
|
1065
|
+
MessageChannel: _MessageChannel
|
|
1050
1066
|
};
|
|
1051
1067
|
this.cleanupQueue = new CleanupQueue();
|
|
1052
1068
|
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
@@ -1130,6 +1146,6 @@ function getDefaultContext() {
|
|
|
1130
1146
|
return defaultContext;
|
|
1131
1147
|
}
|
|
1132
1148
|
|
|
1133
|
-
const version = "0.38.
|
|
1149
|
+
const version = "0.38.3";
|
|
1134
1150
|
|
|
1135
1151
|
export { CallbackInfo, CallbackInfoStack, ConstHandle, Context, Deferred, DeferredStore, EmnapiError, Env, EnvStore, Finalizer, Handle, HandleScope, HandleStore, NotSupportBigIntError, NotSupportBufferError, NotSupportWeakRefError, Persistent, RefBase, RefStore, RefTracker, Reference, ScopeStore, Store, TryCatch, createContext, getDefaultContext, isReferenceType, version };
|
package/index.js
CHANGED