@emnapi/runtime 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- const e=[];class t{constructor(e,t,i,n,s,r,o){this.id=e,this.parent=t,this.child=i,this.thiz=n,this.data=s,this.args=r,this.fn=o}getNewTarget(e){const t=this.thiz;return null==t||null==t.constructor?0:t instanceof this.fn?e.ensureHandleId(t.constructor):0}dispose(){void 0!==this.thiz&&(this.thiz=void 0),this.args=e,this.fn=null}}const i=new t(0,null,null,null,0,null,null);class n{constructor(){this.current=i}get(e){if(1===e)return i.child;let t=i;for(let i=0;i<e;++i)if(t=t.child,null===t)return null;return t===i?null:t}pop(){const e=this.current;e!==i&&(this.current=e.parent,e.dispose())}push(e,i,n,s){let r=this.current.child;return r?(r.thiz=e,r.data=i,r.args=n,r.fn=s):(r=new t(this.current.id+1,this.current,null,e,i,n,s),this.current.child=r),this.current=r,r.id}dispose(){this.current=null}}const s=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&&s)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}();class o{constructor(){this._exception=void 0,this._caught=!1}isEmpty(){return!this._caught}hasCaught(){return this._caught}exception(){return this._exception}setError(e){this._caught=!0,this._exception=e}reset(){this._caught=!1,this._exception=void 0}extractException(){const e=this._exception;return this.reset(),e}}const a=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),l="object"==typeof Reflect,c="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,u=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),h="undefined"!=typeof BigInt;function p(e){return"object"==typeof e&&null!==e||"function"==typeof e}const f=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}(),d="function"==typeof MessageChannel?MessageChannel:function(){try{return f("worker_threads").MessageChannel}catch(e){}}(),_="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(d){let t=new d;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},v="function"==typeof Buffer?Buffer:function(){try{return f("buffer").Buffer}catch(e){}}(),g="1.2.0",y=9,x=2147483647;class S{constructor(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isNumber(){return"number"==typeof this.value}isBigInt(){return"bigint"==typeof this.value}isString(){return"string"==typeof this.value}isFunction(){return"function"==typeof this.value}isExternal(){return p(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return"object"==typeof this.value&&null!==this.value}isArray(){return Array.isArray(this.value)}isArrayBuffer(){return this.value instanceof ArrayBuffer}isTypedArray(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(e){return null!=e||(e=v),"function"==typeof e&&e.isBuffer(this.value)}isDataView(){return this.value instanceof DataView}isDate(){return this.value instanceof Date}isPromise(){return this.value instanceof Promise}isBoolean(){return"boolean"==typeof this.value}isUndefined(){return void 0===this.value}isSymbol(){return"symbol"==typeof this.value}isNull(){return null===this.value}dispose(){this.value=void 0}}class b extends S{constructor(e,t){super(e,t)}dispose(){}}function k(){Object.setPrototypeOf(this,null)}k.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,n=this._values;return i<n.length?(t=n[i],t.value=e):(t=new S(i,e),n[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let n=e;n<t;++n)i[n].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,n=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=n,n.id=Number(t)}dispose(){this._values.length=w.MIN_ID,this._next=w.MIN_ID}}w.UNDEFINED=new b(1,void 0),w.NULL=new b(2,null),w.FALSE=new b(3,!1),w.TRUE=new b(4,!0),w.GLOBAL=new b(5,r),w.MIN_ID=6;class z{constructor(e,t,i,n,s=n){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=n,this.end=s,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const i=new k,n=e.ctx.handleStore.push(i);return e.initObjectBinding(i).data=t,this.end++,n}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 C{constructor(){this._rootScope=new z(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 z(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 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 m{constructor(e,t=0,i=0,n=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=n}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 I extends m{static finalizeAll(e){E.finalizeAll(e)}link(e){E.prototype.link.call(this,e)}unlink(){E.prototype.unlink.call(this)}static create(e,t,i,n){return new I(e,t,i,n)}constructor(e,t,i,n){super(e,t,i,n),this._next=null,this._prev=null,this.link(t?e.finalizing_reflist:e.reflist)}dispose(){this.unlink(),this.envObject.dequeueFinalizer(this),super.dispose()}finalize(){this.finalizeCore(!0)}finalizeCore(e){const t=this._finalizeCallback,i=this._finalizeData,n=this._finalizeHint;let s;this.resetFinalizer(),this.unlink();let r=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,i,n)}catch(e){r=!0,s=e}}if(e&&this.dispose(),r)throw s}}class F extends I{constructor(e,t,i,n,s,r){super(e,n,s,r),this._refcount=t,this._ownership=i}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(){this.finalizeCore(0===this._ownership)}}function O(e,t){if(!e.terminatedOrTerminating())throw t}class D{constructor(e,t,i,n,s){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=i,this.makeDynCall_vp=n,this.abort=s,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new o,this.refs=1,this.reflist=new E,this.finalizing_reflist=new E,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,this._bindingMap=new WeakMap,this.id=0}canCallIntoJs(){return!0}terminatedOrTerminating(){return!this.canCallIntoJs()}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 0!==e.errorCode&&(e.errorCode=0),0!==e.engineErrorCode&&(e.engineErrorCode=0),0!==e.engineReserved&&(e.engineReserved=0),0}setLastError(e,t=0,i=0){const n=this.lastError;return n.errorCode!==e&&(n.errorCode=e),n.engineErrorCode!==t&&(n.engineErrorCode=t),n.engineReserved!==i&&(n.engineReserved=i),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=O){const i=this.openHandleScopes;this.clearLastError();const n=e(this);if(i!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return n}callFinalizer(e,t,i){const n=this.makeDynCall_vppp(e),s=this.id,r=this.ctx.openScope(this);try{this.callIntoModule((()=>{n(s,t,i)}))}finally{this.ctx.closeScope(this,r)}}invokeFinalizerFromGC(e){if(this.moduleApiVersion!==x)this.enqueueFinalizer(e);else{const t=this.inGcFinalizer;this.inGcFinalizer=!0;try{e.finalize()}finally{this.inGcFinalizer=t}}}checkGCAccess(){this.moduleApiVersion===x&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e)}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}deleteMe(){F.finalizeAll(this.finalizing_reflist),F.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),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 F(this,0,0,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class N extends D{constructor(e,t,i,n,s,r,o){super(e,i,n,s,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return super.canCallIntoJs()&&this.ctx.canCallIntoJs()}triggerFatalException(e){if(this.nodeBinding)this.nodeBinding.napi.fatalException(e);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw e;process._fatalException(e)||(console.error(e),process.exit(1))}}callbackIntoModule(e,t){return this.callIntoModule(t,((t,i)=>{if(t.terminatedOrTerminating())return;const n="object"==typeof process&&null!==process,s=!!n&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(t.moduleApiVersion<x&&!s&&!e){(n&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,i){if(e instanceof Error)console.warn(e.toString());else{const n=i?`[${i}] `:"";console.warn(`${n}${t||"Warning"}: ${e}`)}})("Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168")}else t.triggerFatalException(i)}))}callFinalizer(e,t,i){this.callFinalizerInternal(1,e,t,i)}callFinalizerInternal(e,t,i,n){const s=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),(()=>{s(r,i,n)}))}finally{this.ctx.closeScope(this,o)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),_((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function R(e,t,i,n,s,r,o){(i="number"!=typeof i?8:i)<8?i=8:i>y&&i!==x&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version ${y} add-ons.`)}(t,i);const a=new N(e,t,i,n,s,r,o);return e.envStore.add(a),e.addCleanupHook(a,(()=>{a.unref()}),0),a}class A extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof A)){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(A.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class H extends A{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 B extends A{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(B.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 M{constructor(e){this._ref=new j(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{M._registry.register(i,this,this);const n=new WeakRef(i);this._ref.dispose(),this._ref=n,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof i)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{M._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(c)try{M._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 T(e){e.persistent.reset(),e.envObject.invokeFinalizerFromGC(e)}M._registry=c?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 F{static create(e,t,i,n,s=0,r=0,o=0){const a=e.ctx.handleStore.get(t),l=new L(e,i,n,s,r,o);var c;return e.ctx.refStore.add(l),l.canBeWeak=(c=a).isObject()||c.isFunction()||c.isSymbol(),l.persistent=new M(a.value),0===i&&l._setWeak(),l}constructor(e,t,i,n=0,s=0,r=0){super(e,t>>>0,i,n,s,r),this.id=0}ref(){if(this.persistent.isEmpty())return 0;const e=super.ref();return 1===e&&this.canBeWeak&&this.persistent.clearWeak(),e}unref(){if(this.persistent.isEmpty())return 0;const e=this.refCount(),t=super.unref();return 1===e&&0===t&&this._setWeak(),t}get(){if(this.persistent.isEmpty())return 0;const e=this.persistent.deref();return this.envObject.ensureHandle(e).id}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,T):this.persistent.reset()}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 P{static create(e,t){const i=new P(e,t);return e.deferredStore.add(i),i}constructor(e,t){this.id=0,this.ctx=e,this.value=t}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(){this._values=[void 0],this._values.length=4,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=e+(e>>1)+16)}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 U{constructor(e,t,i,n){this.envObject=e,this.fn=t,this.arg=i,this.order=n}}class V{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter((n=>n.envObject===e&&n.fn===t&&n.arg===i)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new U(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let n=0;n<this._cleanupHooks.length;++n){const s=this._cleanupHooks[n];if(s.envObject===e&&s.fn===t&&s.arg===i)return void this._cleanupHooks.splice(n,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 G{constructor(){this.refHandle=(new d).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._isStopping=!1,this._canCallIntoJs=!0,this.envStore=new W,this.scopeStore=new C,this.refStore=new W,this.deferredStore=new W,this.handleStore=new w,this.cbinfoStack=new n,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:u,supportBigInt:h,supportNewFunction:s,canSetFunctionName:a,setImmediate:_,Buffer:v,MessageChannel:d},this.cleanupQueue=new V,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new G,process.once("beforeExit",(()=>{this.destroy()})))}getRuntimeVersions(){return{version:g,NODE_API_SUPPORTED_VERSION_MAX:y,NAPI_VERSION_EXPERIMENTAL:x,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new H(e,t)}createNotSupportBufferError(e,t){return new B(e,t)}createReference(e,t,i,n,s=0,r=0,o=0){return L.create(e,t,i,n,s,r,o)}createDeferred(e){return P.create(this,e)}createEnv(e,t,i,n,s,r){return R(this,e,t,i,n,s,r)}createTrackedFinalizer(e,t,i,n){return I.create(e,t,i,n)}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()}setCanCallIntoJs(e){this._canCallIntoJs=e}setStopping(e){this._isStopping=e}canCallIntoJs(){return this._canCallIntoJs&&!this._isStopping}destroy(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()}}let $;function J(){return new q}exports.CallbackInfo=t,exports.CallbackInfoStack=n,exports.ConstHandle=b,exports.Context=q,exports.Deferred=P,exports.EmnapiError=A,exports.Env=D,exports.Finalizer=m,exports.Handle=S,exports.HandleScope=z,exports.HandleStore=w,exports.NAPI_VERSION_EXPERIMENTAL=x,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NODE_API_SUPPORTED_VERSION_MAX=y,exports.NODE_API_SUPPORTED_VERSION_MIN=1,exports.NodeEnv=N,exports.NotSupportBufferError=B,exports.NotSupportWeakRefError=H,exports.Persistent=M,exports.RefBase=F,exports.RefTracker=E,exports.Reference=L,exports.ScopeStore=C,exports.Store=W,exports.TrackedFinalizer=I,exports.TryCatch=o,exports.createContext=J,exports.getDefaultContext=function(){return $||($=J()),$},exports.isReferenceType=p,exports.version=g;
1
+ const e=[];class t{constructor(e,t,i,s,n,r,o){this.id=e,this.parent=t,this.child=i,this.thiz=s,this.data=n,this.args=r,this.fn=o}getNewTarget(e){const t=this.thiz;return null==t||null==t.constructor?0:t instanceof this.fn?e.ensureHandleId(t.constructor):0}dispose(){void 0!==this.thiz&&(this.thiz=void 0),this.args=e,this.fn=null}}const i=new t(0,null,null,null,0,null,null);class s{constructor(){this.current=i}get(e){if(1===e)return i.child;let t=i;for(let i=0;i<e;++i)if(t=t.child,null===t)return null;return t===i?null:t}pop(){const e=this.current;e!==i&&(this.current=e.parent,e.dispose())}push(e,i,s,n){let r=this.current.child;return r?(r.thiz=e,r.data=i,r.args=s,r.fn=n):(r=new t(this.current.id+1,this.current,null,e,i,s,n),this.current.child=r),this.current=r,r.id}dispose(){this.current=null}}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}();class o{constructor(){this._exception=void 0,this._caught=!1}isEmpty(){return!this._caught}hasCaught(){return this._caught}exception(){return this._exception}setError(e){this._caught=!0,this._exception=e}reset(){this._caught=!1,this._exception=void 0}extractException(){const e=this._exception;return this.reset(),e}}const a=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),l="object"==typeof Reflect,c="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}(),u="undefined"!=typeof BigInt;function p(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}(),f="function"==typeof MessageChannel?MessageChannel:function(){try{return d("worker_threads").MessageChannel}catch(e){}}(),_="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(f){let t=new f;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},v="function"==typeof Buffer?Buffer:function(){try{return d("buffer").Buffer}catch(e){}}(),g="1.3.0",y=2147483647;class x{constructor(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isNumber(){return"number"==typeof this.value}isBigInt(){return"bigint"==typeof this.value}isString(){return"string"==typeof this.value}isFunction(){return"function"==typeof this.value}isExternal(){return p(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return"object"==typeof this.value&&null!==this.value}isArray(){return Array.isArray(this.value)}isArrayBuffer(){return this.value instanceof ArrayBuffer}isTypedArray(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(e){return null!=e||(e=v),"function"==typeof e&&e.isBuffer(this.value)}isDataView(){return this.value instanceof DataView}isDate(){return this.value instanceof Date}isPromise(){return this.value instanceof Promise}isBoolean(){return"boolean"==typeof this.value}isUndefined(){return void 0===this.value}isSymbol(){return"symbol"==typeof this.value}isNull(){return null===this.value}dispose(){this.value=void 0}}class z extends x{constructor(e,t){super(e,t)}dispose(){}}function b(){Object.setPrototypeOf(this,null)}b.prototype=null;class k{constructor(){this._values=[void 0,k.UNDEFINED,k.NULL,k.FALSE,k.TRUE,k.GLOBAL],this._next=k.MIN_ID}push(e){let t;const i=this._next,s=this._values;return i<s.length?(t=s[i],t.value=e):(t=new x(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=k.MIN_ID,this._next=k.MIN_ID}}k.UNDEFINED=new z(1,void 0),k.NULL=new z(2,null),k.FALSE=new z(3,!1),k.TRUE=new z(4,!0),k.GLOBAL=new z(5,r),k.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 w{constructor(){this._rootScope=new S(null,0,null,1,k.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=k.MIN_ID,e.end=k.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class m{constructor(){this._next=null,this._prev=null}dispose(){}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,this._makeDynCall_vppp=e.makeDynCall_vppp}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetEnv(){this.envObject=void 0}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}callFinalizer(){const e=this._finalizeCallback,t=this._finalizeData,i=this._finalizeHint;if(this.resetFinalizer(),!e)return;const s=Number(e);this.envObject?this.envObject.callFinalizer(s,t,i):this._makeDynCall_vppp(s)(0,t,i)}dispose(){this.envObject=void 0,this._makeDynCall_vppp=void 0}}class E extends m{static create(e,t,i,s){const n=new E(e,t,i,s);return n.link(e.finalizing_reflist),n}constructor(e,t,i,s){super(),this._finalizer=new C(e,t,i,s)}data(){return this._finalizer.data()}dispose(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,super.dispose())}finalize(){let e;this.unlink();let t=!1;try{this._finalizer.callFinalizer()}catch(i){t=!0,e=i}if(this.dispose(),t)throw e}}function F(e,t){if(!e.terminatedOrTerminating())throw t}class I{constructor(e,t,i,s,n){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=i,this.makeDynCall_vp=s,this.abort=n,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new o,this.refs=1,this.reflist=new m,this.finalizing_reflist=new m,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,this._bindingMap=new WeakMap,this.id=0}canCallIntoJs(){return!0}terminatedOrTerminating(){return!this.canCallIntoJs()}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 0!==e.errorCode&&(e.errorCode=0),0!==e.engineErrorCode&&(e.engineErrorCode=0),0!==e.engineReserved&&(e.engineReserved=0),0}setLastError(e,t=0,i=0){const s=this.lastError;return s.errorCode!==e&&(s.errorCode=e),s.engineErrorCode!==t&&(s.engineErrorCode=t),s.engineReserved!==i&&(s.engineReserved=i),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=F){const i=this.openHandleScopes;this.clearLastError();const s=e(this);if(i!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return s}invokeFinalizerFromGC(e){if(this.moduleApiVersion!==y)this.enqueueFinalizer(e);else{const t=this.inGcFinalizer;this.inGcFinalizer=!0;try{e.finalize()}finally{this.inGcFinalizer=t}}}checkGCAccess(){this.moduleApiVersion===y&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e)}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}deleteMe(){m.finalizeAll(this.finalizing_reflist),m.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),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=E.create(this,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class O extends I{constructor(e,t,i,s,n,r,o){super(e,i,s,n,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return super.canCallIntoJs()&&this.ctx.canCallIntoJs()}triggerFatalException(e){if(this.nodeBinding)this.nodeBinding.napi.fatalException(e);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw e;process._fatalException(e)||(console.error(e),process.exit(1))}}callbackIntoModule(e,t){return this.callIntoModule(t,((t,i)=>{if(t.terminatedOrTerminating())return;const s="object"==typeof process&&null!==process,n=!!s&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(t.moduleApiVersion<y&&!n&&!e){(s&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,i){if(e instanceof Error)console.warn(e.toString());else{const s=i?`[${i}] `:"";console.warn(`${s}${t||"Warning"}: ${e}`)}})("Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168")}else t.triggerFatalException(i)}))}callFinalizer(e,t,i){this.callFinalizerInternal(1,e,t,i)}callFinalizerInternal(e,t,i,s){const n=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),(()=>{n(r,i,s)}))}finally{this.ctx.closeScope(this,o)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),_((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function D(e,t,i,s,n,r,o){(i="number"!=typeof i?8:i)<8?i=8:i>9&&i!==y&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version 9 add-ons.`)}(t,i);const a=new O(e,t,i,s,n,r,o);return e.envStore.add(a),e.addCleanupHook(a,(()=>{a.unref()}),0),a}class N extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof N)){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(N.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class R extends N{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(R.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class H extends N{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(H.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 A{constructor(e){this._ref=new j(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{A._registry.register(i,this,this);const s=new WeakRef(i);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof i)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{A._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(c)try{A._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()}}var B;A._registry=c?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,exports.ReferenceOwnership=void 0,(B=exports.ReferenceOwnership||(exports.ReferenceOwnership={}))[B.kRuntime=0]="kRuntime",B[B.kUserland=1]="kUserland";class M extends m{static weakCallback(e){e.persistent.reset(),e.invokeFinalizerFromGC()}static create(e,t,i,s,n,r,o){const a=new M(e,t,i,s);return e.ctx.refStore.add(a),a.link(e.reflist),a}constructor(e,t,i,s){super(),this.envObject=e,this._refcount=i,this._ownership=s;const n=e.ctx.handleStore.get(t);var r;this.canBeWeak=(r=n).isObject()||r.isFunction()||r.isSymbol(),this.persistent=new A(n.value),this.id=0,0===i&&this._setWeak()}ref(){return this.persistent.isEmpty()?0:(1==++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)}unref(){return this.persistent.isEmpty()||0===this._refcount?0:(0==--this._refcount&&this._setWeak(),this._refcount)}get(e=this.envObject){if(this.persistent.isEmpty())return 0;const t=this.persistent.deref();return e.ensureHandle(t).id}resetFinalizer(){}data(){return 0}refcount(){return this._refcount}ownership(){return this._ownership}callUserFinalizer(){}invokeFinalizerFromGC(){this.finalize()}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,M.weakCallback):this.persistent.reset()}finalize(){this.persistent.reset();const e=this._ownership===exports.ReferenceOwnership.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()}dispose(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.envObject=void 0,this.id=0)}}class T extends M{static create(e,t,i,s,n){const r=new T(e,t,i,s,n);return e.ctx.refStore.add(r),r.link(e.reflist),r}constructor(e,t,i,s,n){super(e,t,i,s),this._data=n}data(){return this._data}}class W extends M{static create(e,t,i,s,n,r,o){const a=new W(e,t,i,s,n,r,o);return e.ctx.refStore.add(a),a.link(e.finalizing_reflist),a}constructor(e,t,i,s,n,r,o){super(e,t,i,s),this._finalizer=new C(e,n,r,o)}resetFinalizer(){this._finalizer.resetFinalizer()}data(){return this._finalizer.data()}callUserFinalizer(){this._finalizer.callFinalizer()}invokeFinalizerFromGC(){this._finalizer.envObject.invokeFinalizerFromGC(this)}dispose(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),super.dispose(),this._finalizer=void 0)}}class L{static create(e,t){const i=new L(e,t);return e.deferredStore.add(i),i}constructor(e,t){this.id=0,this.ctx=e,this.value=t}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 P{constructor(){this._values=[void 0],this._values.length=4,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=e+(e>>1)+16)}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 U{constructor(e,t,i,s){this.envObject=e,this.fn=t,this.arg=i,this.order=s}}class G{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 U(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 V{constructor(){this.refHandle=(new f).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._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new P,this.scopeStore=new w,this.refStore=new P,this.deferredStore=new P,this.handleStore=new k,this.cbinfoStack=new s,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:h,supportBigInt:u,supportNewFunction:n,canSetFunctionName:a,setImmediate:_,Buffer:v,MessageChannel:f},this.cleanupQueue=new G,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new V,process.once("beforeExit",(()=>{this._suppressDestroy||this.destroy()})))}suppressDestroy(){this._suppressDestroy=!0}getRuntimeVersions(){return{version:g,NODE_API_SUPPORTED_VERSION_MAX:9,NAPI_VERSION_EXPERIMENTAL:y,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new R(e,t)}createNotSupportBufferError(e,t){return new H(e,t)}createReference(e,t,i,s){return M.create(e,t,i,s)}createReferenceWithData(e,t,i,s,n){return T.create(e,t,i,s,n)}createReferenceWithFinalizer(e,t,i,s,n=0,r=0,o=0){return W.create(e,t,i,s,n,r,o)}createDeferred(e){return L.create(this,e)}createEnv(e,t,i,s,n,r){return D(this,e,t,i,s,n,r)}createTrackedFinalizer(e,t,i,s){return E.create(e,t,i,s)}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 k.UNDEFINED;case null:return k.NULL;case!0:return k.TRUE;case!1:return k.FALSE;case r:return k.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()}setCanCallIntoJs(e){this._canCallIntoJs=e}setStopping(e){this._isStopping=e}canCallIntoJs(){return this._canCallIntoJs&&!this._isStopping}destroy(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()}}let $;function J(){return new q}exports.CallbackInfo=t,exports.CallbackInfoStack=s,exports.ConstHandle=z,exports.Context=q,exports.Deferred=L,exports.EmnapiError=N,exports.Env=I,exports.Finalizer=C,exports.Handle=x,exports.HandleScope=S,exports.HandleStore=k,exports.NAPI_VERSION_EXPERIMENTAL=y,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NODE_API_SUPPORTED_VERSION_MAX=9,exports.NODE_API_SUPPORTED_VERSION_MIN=1,exports.NodeEnv=O,exports.NotSupportBufferError=H,exports.NotSupportWeakRefError=R,exports.Persistent=A,exports.RefTracker=m,exports.Reference=M,exports.ReferenceWithData=T,exports.ReferenceWithFinalizer=W,exports.ScopeStore=w,exports.Store=P,exports.TrackedFinalizer=E,exports.TryCatch=o,exports.createContext=J,exports.getDefaultContext=function(){return $||($=J()),$},exports.isReferenceType=p,exports.version=g;
package/dist/emnapi.d.mts CHANGED
@@ -21,11 +21,6 @@ export declare const enum GlobalHandle {
21
21
  GLOBAL
22
22
  }
23
23
 
24
- export declare const enum Ownership {
25
- kRuntime,
26
- kUserland
27
- }
28
-
29
24
  export declare const enum Version {
30
25
  NODE_API_SUPPORTED_VERSION_MIN = 1,
31
26
  NODE_API_DEFAULT_MODULE_API_VERSION = 8,
@@ -282,6 +277,7 @@ export declare class ConstHandle<S extends undefined | null | boolean | typeof g
282
277
  export declare class Context {
283
278
  private _isStopping;
284
279
  private _canCallIntoJs;
280
+ private _suppressDestroy;
285
281
  envStore: Store<Env>;
286
282
  scopeStore: ScopeStore;
287
283
  refStore: Store<Reference>;
@@ -305,6 +301,15 @@ export declare class Context {
305
301
  } | undefined;
306
302
  };
307
303
  constructor();
304
+ /**
305
+ * Suppress the destroy on `beforeExit` event in Node.js.
306
+ * Call this method if you want to keep the context and
307
+ * all associated {@link Env | Env} alive,
308
+ * this also means that cleanup hooks will not be called.
309
+ * After call this method, you should call
310
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
311
+ */
312
+ suppressDestroy(): void;
308
313
  getRuntimeVersions(): {
309
314
  version: string;
310
315
  NODE_API_SUPPORTED_VERSION_MAX: Version;
@@ -313,7 +318,9 @@ export declare class Context {
313
318
  };
314
319
  createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
315
320
  createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
316
- createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
321
+ createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
322
+ createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
323
+ createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
317
324
  createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
318
325
  createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
319
326
  createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
@@ -330,6 +337,10 @@ export declare class Context {
330
337
  setCanCallIntoJs(value: boolean): void;
331
338
  setStopping(value: boolean): void;
332
339
  canCallIntoJs(): boolean;
340
+ /**
341
+ * Destroy the context and call cleanup hooks.
342
+ * Associated {@link Env | Env} will be destroyed.
343
+ */
333
344
  destroy(): void;
334
345
  }
335
346
 
@@ -350,7 +361,7 @@ export declare class EmnapiError extends Error {
350
361
  constructor(message?: string);
351
362
  }
352
363
 
353
- export declare class Env implements IStoreValue {
364
+ export declare abstract class Env implements IStoreValue {
354
365
  readonly ctx: Context;
355
366
  moduleApiVersion: number;
356
367
  makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
@@ -358,7 +369,7 @@ export declare class Env implements IStoreValue {
358
369
  abort: (msg?: string) => never;
359
370
  id: number;
360
371
  openHandleScopes: number;
361
- instanceData: RefBase | null;
372
+ instanceData: TrackedFinalizer | null;
362
373
  tryCatch: TryCatch;
363
374
  refs: number;
364
375
  reflist: RefTracker;
@@ -383,7 +394,7 @@ export declare class Env implements IStoreValue {
383
394
  getReturnStatus(): napi_status;
384
395
  callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
385
396
  /** @virtual */
386
- callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
397
+ abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
387
398
  invokeFinalizerFromGC(finalizer: RefTracker): void;
388
399
  checkGCAccess(): void;
389
400
  /** @virtual */
@@ -402,14 +413,17 @@ export declare class Env implements IStoreValue {
402
413
 
403
414
  export declare class Finalizer {
404
415
  envObject: Env;
405
- protected _finalizeCallback: napi_finalize;
406
- protected _finalizeData: void_p;
407
- protected _finalizeHint: void_p;
416
+ private _finalizeCallback;
417
+ private _finalizeData;
418
+ private _finalizeHint;
419
+ private _makeDynCall_vppp;
408
420
  constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
409
421
  callback(): napi_finalize;
410
422
  data(): void_p;
411
423
  hint(): void_p;
424
+ resetEnv(): void;
412
425
  resetFinalizer(): void;
426
+ callFinalizer(): void;
413
427
  dispose(): void;
414
428
  }
415
429
 
@@ -536,33 +550,60 @@ export declare class Persistent<T> {
536
550
  deref(): T | undefined;
537
551
  }
538
552
 
539
- export declare class RefBase extends TrackedFinalizer {
553
+ export declare class Reference extends RefTracker implements IStoreValue {
554
+ private static weakCallback;
555
+ id: number;
556
+ envObject: Env;
557
+ private readonly canBeWeak;
540
558
  private _refcount;
541
559
  private readonly _ownership;
542
- constructor(envObject: Env, initial_refcount: uint32_t, ownership: number, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
543
- data(): void_p;
544
- ref(): uint32_t;
545
- unref(): uint32_t;
546
- refCount(): uint32_t;
547
- ownership(): number;
548
- finalize(): void;
549
- }
550
-
551
- export declare class Reference extends RefBase implements IStoreValue {
552
- id: number;
553
- private canBeWeak;
554
- static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
555
560
  persistent: Persistent<object>;
556
- private constructor();
561
+ static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
562
+ protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
557
563
  ref(): number;
558
564
  unref(): number;
559
- get(): napi_value;
565
+ get(envObject?: Env): napi_value;
566
+ /** @virtual */
567
+ resetFinalizer(): void;
568
+ /** @virtual */
569
+ data(): void_p;
570
+ refcount(): number;
571
+ ownership(): ReferenceOwnership;
572
+ /** @virtual */
573
+ protected callUserFinalizer(): void;
574
+ /** @virtual */
575
+ protected invokeFinalizerFromGC(): void;
560
576
  private _setWeak;
561
577
  finalize(): void;
562
578
  dispose(): void;
563
579
  }
564
580
 
581
+ export declare enum ReferenceOwnership {
582
+ kRuntime = 0,
583
+ kUserland = 1
584
+ }
585
+
586
+ export declare class ReferenceWithData extends Reference {
587
+ private readonly _data;
588
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
589
+ private constructor();
590
+ data(): void_p;
591
+ }
592
+
593
+ export declare class ReferenceWithFinalizer extends Reference {
594
+ private _finalizer;
595
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer;
596
+ private constructor();
597
+ resetFinalizer(): void;
598
+ data(): void_p;
599
+ protected callUserFinalizer(): void;
600
+ protected invokeFinalizerFromGC(): void;
601
+ dispose(): void;
602
+ }
603
+
565
604
  export declare class RefTracker {
605
+ /** @virtual */
606
+ dispose(): void;
566
607
  /** @virtual */
567
608
  finalize(): void;
568
609
  private _next;
@@ -594,18 +635,13 @@ export declare class Store<V extends IStoreValue> {
594
635
  dispose(): void;
595
636
  }
596
637
 
597
- export declare interface TrackedFinalizer extends Finalizer, RefTracker {
598
- }
599
-
600
- export declare class TrackedFinalizer extends Finalizer {
601
- static finalizeAll(list: RefTracker): void;
602
- link(list: RefTracker): void;
603
- unlink(): void;
638
+ export declare class TrackedFinalizer extends RefTracker {
639
+ private _finalizer;
604
640
  static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
605
- protected constructor(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
641
+ private constructor();
642
+ data(): void_p;
606
643
  dispose(): void;
607
644
  finalize(): void;
608
- protected finalizeCore(deleteMe: boolean): void;
609
645
  }
610
646
 
611
647
  export declare class TryCatch {
package/dist/emnapi.d.ts CHANGED
@@ -21,11 +21,6 @@ export declare const enum GlobalHandle {
21
21
  GLOBAL
22
22
  }
23
23
 
24
- export declare const enum Ownership {
25
- kRuntime,
26
- kUserland
27
- }
28
-
29
24
  export declare const enum Version {
30
25
  NODE_API_SUPPORTED_VERSION_MIN = 1,
31
26
  NODE_API_DEFAULT_MODULE_API_VERSION = 8,
@@ -282,6 +277,7 @@ export declare class ConstHandle<S extends undefined | null | boolean | typeof g
282
277
  export declare class Context {
283
278
  private _isStopping;
284
279
  private _canCallIntoJs;
280
+ private _suppressDestroy;
285
281
  envStore: Store<Env>;
286
282
  scopeStore: ScopeStore;
287
283
  refStore: Store<Reference>;
@@ -305,6 +301,15 @@ export declare class Context {
305
301
  } | undefined;
306
302
  };
307
303
  constructor();
304
+ /**
305
+ * Suppress the destroy on `beforeExit` event in Node.js.
306
+ * Call this method if you want to keep the context and
307
+ * all associated {@link Env | Env} alive,
308
+ * this also means that cleanup hooks will not be called.
309
+ * After call this method, you should call
310
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
311
+ */
312
+ suppressDestroy(): void;
308
313
  getRuntimeVersions(): {
309
314
  version: string;
310
315
  NODE_API_SUPPORTED_VERSION_MAX: Version;
@@ -313,7 +318,9 @@ export declare class Context {
313
318
  };
314
319
  createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
315
320
  createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
316
- createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
321
+ createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
322
+ createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
323
+ createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
317
324
  createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
318
325
  createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
319
326
  createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
@@ -330,6 +337,10 @@ export declare class Context {
330
337
  setCanCallIntoJs(value: boolean): void;
331
338
  setStopping(value: boolean): void;
332
339
  canCallIntoJs(): boolean;
340
+ /**
341
+ * Destroy the context and call cleanup hooks.
342
+ * Associated {@link Env | Env} will be destroyed.
343
+ */
333
344
  destroy(): void;
334
345
  }
335
346
 
@@ -350,7 +361,7 @@ export declare class EmnapiError extends Error {
350
361
  constructor(message?: string);
351
362
  }
352
363
 
353
- export declare class Env implements IStoreValue {
364
+ export declare abstract class Env implements IStoreValue {
354
365
  readonly ctx: Context;
355
366
  moduleApiVersion: number;
356
367
  makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
@@ -358,7 +369,7 @@ export declare class Env implements IStoreValue {
358
369
  abort: (msg?: string) => never;
359
370
  id: number;
360
371
  openHandleScopes: number;
361
- instanceData: RefBase | null;
372
+ instanceData: TrackedFinalizer | null;
362
373
  tryCatch: TryCatch;
363
374
  refs: number;
364
375
  reflist: RefTracker;
@@ -383,7 +394,7 @@ export declare class Env implements IStoreValue {
383
394
  getReturnStatus(): napi_status;
384
395
  callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
385
396
  /** @virtual */
386
- callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
397
+ abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
387
398
  invokeFinalizerFromGC(finalizer: RefTracker): void;
388
399
  checkGCAccess(): void;
389
400
  /** @virtual */
@@ -402,14 +413,17 @@ export declare class Env implements IStoreValue {
402
413
 
403
414
  export declare class Finalizer {
404
415
  envObject: Env;
405
- protected _finalizeCallback: napi_finalize;
406
- protected _finalizeData: void_p;
407
- protected _finalizeHint: void_p;
416
+ private _finalizeCallback;
417
+ private _finalizeData;
418
+ private _finalizeHint;
419
+ private _makeDynCall_vppp;
408
420
  constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
409
421
  callback(): napi_finalize;
410
422
  data(): void_p;
411
423
  hint(): void_p;
424
+ resetEnv(): void;
412
425
  resetFinalizer(): void;
426
+ callFinalizer(): void;
413
427
  dispose(): void;
414
428
  }
415
429
 
@@ -536,33 +550,60 @@ export declare class Persistent<T> {
536
550
  deref(): T | undefined;
537
551
  }
538
552
 
539
- export declare class RefBase extends TrackedFinalizer {
553
+ export declare class Reference extends RefTracker implements IStoreValue {
554
+ private static weakCallback;
555
+ id: number;
556
+ envObject: Env;
557
+ private readonly canBeWeak;
540
558
  private _refcount;
541
559
  private readonly _ownership;
542
- constructor(envObject: Env, initial_refcount: uint32_t, ownership: number, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
543
- data(): void_p;
544
- ref(): uint32_t;
545
- unref(): uint32_t;
546
- refCount(): uint32_t;
547
- ownership(): number;
548
- finalize(): void;
549
- }
550
-
551
- export declare class Reference extends RefBase implements IStoreValue {
552
- id: number;
553
- private canBeWeak;
554
- static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
555
560
  persistent: Persistent<object>;
556
- private constructor();
561
+ static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
562
+ protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
557
563
  ref(): number;
558
564
  unref(): number;
559
- get(): napi_value;
565
+ get(envObject?: Env): napi_value;
566
+ /** @virtual */
567
+ resetFinalizer(): void;
568
+ /** @virtual */
569
+ data(): void_p;
570
+ refcount(): number;
571
+ ownership(): ReferenceOwnership;
572
+ /** @virtual */
573
+ protected callUserFinalizer(): void;
574
+ /** @virtual */
575
+ protected invokeFinalizerFromGC(): void;
560
576
  private _setWeak;
561
577
  finalize(): void;
562
578
  dispose(): void;
563
579
  }
564
580
 
581
+ export declare enum ReferenceOwnership {
582
+ kRuntime = 0,
583
+ kUserland = 1
584
+ }
585
+
586
+ export declare class ReferenceWithData extends Reference {
587
+ private readonly _data;
588
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
589
+ private constructor();
590
+ data(): void_p;
591
+ }
592
+
593
+ export declare class ReferenceWithFinalizer extends Reference {
594
+ private _finalizer;
595
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer;
596
+ private constructor();
597
+ resetFinalizer(): void;
598
+ data(): void_p;
599
+ protected callUserFinalizer(): void;
600
+ protected invokeFinalizerFromGC(): void;
601
+ dispose(): void;
602
+ }
603
+
565
604
  export declare class RefTracker {
605
+ /** @virtual */
606
+ dispose(): void;
566
607
  /** @virtual */
567
608
  finalize(): void;
568
609
  private _next;
@@ -594,18 +635,13 @@ export declare class Store<V extends IStoreValue> {
594
635
  dispose(): void;
595
636
  }
596
637
 
597
- export declare interface TrackedFinalizer extends Finalizer, RefTracker {
598
- }
599
-
600
- export declare class TrackedFinalizer extends Finalizer {
601
- static finalizeAll(list: RefTracker): void;
602
- link(list: RefTracker): void;
603
- unlink(): void;
638
+ export declare class TrackedFinalizer extends RefTracker {
639
+ private _finalizer;
604
640
  static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
605
- protected constructor(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
641
+ private constructor();
642
+ data(): void_p;
606
643
  dispose(): void;
607
644
  finalize(): void;
608
- protected finalizeCore(deleteMe: boolean): void;
609
645
  }
610
646
 
611
647
  export declare class TryCatch {