@emnapi/runtime 0.38.2 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/emnapi.cjs.js +311 -186
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.ts +61 -28
- package/dist/emnapi.esm-bundler.js +321 -197
- package/dist/emnapi.iife.d.ts +53 -27
- package/dist/emnapi.iife.js +352 -227
- package/dist/emnapi.js +352 -227
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +308 -184
- package/index.js +1 -1
- package/package.json +1 -1
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,n,i){this.parent=e,this.thiz=t,this.data=s,this.args=n,this.fn=i}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,n,i){const r=new e(this.current,t,s,n,i);return this.current=r,r}dispose(){this.current=null}}const s=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&&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 i{constructor(){this._exception=void 0,this._caught=!1}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 r=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),o="object"==typeof Reflect,a="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,l=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),c="undefined"!=typeof BigInt;function u(e){return"object"==typeof e&&null!==e||"function"==typeof e}const h=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}(),p="function"==typeof MessageChannel?MessageChannel:function(){try{return h("worker_threads").MessageChannel}catch(e){}}(),d="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(p){let t=new p;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},f="function"==typeof Buffer?Buffer:function(){try{return h("buffer").Buffer}catch(e){}}(),_="0.39.0",v=9,g=2147483647;class y{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 u(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(){return"function"==typeof f&&f.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 x extends y{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,n=this._values;return s<n.length?(t=n[s],t.value=e):(t=new y(s,e),n[s]=t),this._next++,t}erase(e,t){this._next=e;const s=this._values;for(let n=e;n<t;++n)s[n].dispose()}get(e){return this._values[e]}swap(e,t){const s=this._values,n=s[e];s[e]=s[t],s[e].id=Number(e),s[t]=n,n.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,n,i=n){this.handleStore=e,this.id=t,this.parent=s,this.child=null,null!==s&&(s.child=this),this.start=n,this.end=i,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const s=new b,n=e.ctx.handleStore.push(s);return e.initObjectBinding(s).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 k{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 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 C{constructor(e,t=0,s=0,n=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=s,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 m extends C{constructor(e,t,s,n,i,r){super(e,n,i,r),this._next=null,this._prev=null,this._refcount=t,this._ownership=s,this.link(n?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,n=this._finalizeHint;let i;this.resetFinalizer(),this.unlink();let r=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,s,n)}catch(e){r=!0,i=e}}if(0===e&&this.dispose(),r)throw i}}function I(e,t){if(!e.terminatedOrTerminating())throw t}class z{constructor(e,t,s,n,r){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=s,this.makeDynCall_vp=n,this.abort=r,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new i,this.refs=1,this.reflist=new E,this.finalizing_reflist=new E,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},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,s=0){const n=this.lastError;return n.errorCode!==e&&(n.errorCode=e),n.engineErrorCode!==t&&(n.engineErrorCode=t),n.engineReserved!==s&&(n.engineReserved=s),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=I){const s=this.openHandleScopes;this.clearLastError();const n=e(this);if(s!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return n}callFinalizer(e,t,s){const n=this.makeDynCall_vppp(e),i=this.id,r=this.ctx.openScope(this);try{this.callIntoModule((()=>{n(i,t,s)}))}finally{this.ctx.closeScope(this,r)}}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.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 m(this,0,0,t,e,s)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class N extends z{constructor(e,t,s,n,i,r,o){super(e,s,n,i,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return 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,s)=>{if(t.terminatedOrTerminating())return;const n="object"==typeof process&&null!==process;if(!(!!n&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy")))&&!e){if(!n||"function"!=typeof process.emitWarning)throw s;process.emitWarning("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")}t.triggerFatalException(s)}))}callFinalizer(e,t,s){this.callFinalizerInternal(1,e,t,s)}callFinalizerInternal(e,t,s,n){const i=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),(()=>{i(r,s,n)}))}finally{this.ctx.closeScope(this,o)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),d((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function O(e,t,s,n,i,r,o){(s="number"!=typeof s?8:s)<8?s=8:s>v&&s!==g&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version ${v} add-ons.`)}(t,s);const a=new N(e,t,s,n,i,r,o);return e.envStore.add(a),e.addCleanupHook(a,(()=>{a.unref()}),0),a}class D extends Error{constructor(e){super(e);const t=new.target,s=t.prototype;if(!(this instanceof D)){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(D.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class F extends D{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 H extends D{constructor(e,t){super(`${e}: The current runtime does not support "BigInt".${t?` ${t}`:""}`)}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});class B extends D{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 R{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class j{constructor(e){this._ref=new R(e)}setWeak(e,t){if(!a||void 0===this._ref||this._ref instanceof WeakRef)return;const s=this._ref.deref();try{j._registry.register(s,this,this);const n=new WeakRef(s);this._ref.dispose(),this._ref=n,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof s)throw e}}clearWeak(){if(a&&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 R(e)}}reset(){if(a)try{j._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof R&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}function A(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}j._registry=a?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 M extends m{constructor(e,t,s,n=0,i=0,r=0){super(e,t>>>0,s,n,i,r),this.id=0}static create(e,t,s,n,i=0,r=0,o=0){const a=e.ctx.handleStore.get(t),l=new M(e,s,n,i,r,o);var c;return e.ctx.refStore.add(l),l.canBeWeak=(c=a).isObject()||c.isFunction()||c.isSymbol(),l.persistent=new j(a.value),0===s&&l._setWeak(),l}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,A):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 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 T{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 W{constructor(e,t,s,n){this.envObject=e,this.fn=t,this.arg=s,this.order=n}}class P{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,s){if(this._cleanupHooks.filter((n=>n.envObject===e&&n.fn===t&&n.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 n=0;n<this._cleanupHooks.length;++n){const i=this._cleanupHooks[n];if(i.envObject===e&&i.fn===t&&i.arg===s)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 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 U{constructor(){this.refHandle=(new p).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 T,this.scopeStore=new k,this.refStore=new T,this.deferredStore=new T,this.handleStore=new S,this.cbinfoStack=new t,this.feature={supportReflect:o,supportFinalizer:a,supportWeakSymbol:l,supportBigInt:c,supportNewFunction:s,canSetFunctionName:r,setImmediate:d,Buffer:f,MessageChannel:p},this.cleanupQueue=new P,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new U,process.once("beforeExit",(()=>{this.destroy()})))}getRuntimeVersions(){return{version:_,NAPI_VERSION:v,NAPI_VERSION_EXPERIMENTAL:g,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new F(e,t)}createNotSupportBigIntError(e,t){return new H(e,t)}createNotSupportBufferError(e,t){return new B(e,t)}createReference(e,t,s,n,i=0,r=0,o=0){return M.create(e,t,s,n,i,r,o)}createDeferred(e){return L.create(this,e)}createEnv(e,t,s,n,i,r){return O(this,e,t,s,n,i,r)}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()}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 V;function $(){return new q}exports.CallbackInfo=e,exports.CallbackInfoStack=t,exports.ConstHandle=x,exports.Context=q,exports.Deferred=L,exports.EmnapiError=D,exports.Env=z,exports.Finalizer=C,exports.Handle=y,exports.HandleScope=w,exports.HandleStore=S,exports.NAPI_VERSION=v,exports.NAPI_VERSION_EXPERIMENTAL=g,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NodeEnv=N,exports.NotSupportBigIntError=H,exports.NotSupportBufferError=B,exports.NotSupportWeakRefError=F,exports.Persistent=j,exports.RefBase=m,exports.RefTracker=E,exports.Reference=M,exports.ScopeStore=k,exports.Store=T,exports.TryCatch=i,exports.createContext=$,exports.getDefaultContext=function(){return V||(V=$()),V},exports.isReferenceType=u,exports.version=_;
|
package/dist/emnapi.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ export declare const enum Ownership {
|
|
|
25
25
|
kRuntime,
|
|
26
26
|
kUserland
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export declare const enum Version {
|
|
30
|
+
NODE_API_DEFAULT_MODULE_API_VERSION = 8,
|
|
31
|
+
NAPI_VERSION = 9,
|
|
32
|
+
NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
|
|
33
|
+
}
|
|
28
34
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
35
|
export declare type Pointer<T> = number
|
|
30
36
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -150,7 +156,8 @@ export declare const enum napi_status {
|
|
|
150
156
|
napi_arraybuffer_expected,
|
|
151
157
|
napi_detachable_arraybuffer_expected,
|
|
152
158
|
napi_would_deadlock, // unused
|
|
153
|
-
napi_no_external_buffers_allowed
|
|
159
|
+
napi_no_external_buffers_allowed,
|
|
160
|
+
napi_cannot_run_js
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
export declare const enum napi_property_attributes {
|
|
@@ -268,10 +275,12 @@ export declare class ConstHandle<S extends undefined | null | boolean | typeof g
|
|
|
268
275
|
}
|
|
269
276
|
|
|
270
277
|
export declare class Context {
|
|
271
|
-
|
|
278
|
+
private _isStopping;
|
|
279
|
+
private _canCallIntoJs;
|
|
280
|
+
envStore: Store<Env>;
|
|
272
281
|
scopeStore: ScopeStore;
|
|
273
|
-
refStore:
|
|
274
|
-
deferredStore:
|
|
282
|
+
refStore: Store<Reference>;
|
|
283
|
+
deferredStore: Store<Deferred<any>>;
|
|
275
284
|
handleStore: HandleStore;
|
|
276
285
|
cbinfoStack: CallbackInfoStack;
|
|
277
286
|
private readonly refCounter?;
|
|
@@ -283,16 +292,26 @@ export declare class Context {
|
|
|
283
292
|
supportBigInt: boolean;
|
|
284
293
|
supportNewFunction: boolean;
|
|
285
294
|
canSetFunctionName: boolean;
|
|
286
|
-
setImmediate: (
|
|
295
|
+
setImmediate: (callback: () => void) => void;
|
|
287
296
|
Buffer: BufferCtor | undefined;
|
|
297
|
+
MessageChannel: {
|
|
298
|
+
new (): MessageChannel;
|
|
299
|
+
prototype: MessageChannel;
|
|
300
|
+
} | undefined;
|
|
288
301
|
};
|
|
289
302
|
constructor();
|
|
303
|
+
getRuntimeVersions(): {
|
|
304
|
+
version: string;
|
|
305
|
+
NAPI_VERSION: Version;
|
|
306
|
+
NAPI_VERSION_EXPERIMENTAL: Version;
|
|
307
|
+
NODE_API_DEFAULT_MODULE_API_VERSION: Version;
|
|
308
|
+
};
|
|
290
309
|
createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
|
|
291
310
|
createNotSupportBigIntError(api: string, message: string): NotSupportBigIntError;
|
|
292
311
|
createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
|
|
293
312
|
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;
|
|
294
313
|
createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
|
|
295
|
-
createEnv(makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void): Env;
|
|
314
|
+
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;
|
|
296
315
|
getCurrentScope(): HandleScope | null;
|
|
297
316
|
addToCurrentScope<V>(value: V): Handle<V>;
|
|
298
317
|
openScope(envObject: Env): HandleScope;
|
|
@@ -303,7 +322,10 @@ export declare class Context {
|
|
|
303
322
|
runCleanup(): void;
|
|
304
323
|
increaseWaitingRequestCounter(): void;
|
|
305
324
|
decreaseWaitingRequestCounter(): void;
|
|
306
|
-
|
|
325
|
+
setCanCallIntoJs(value: boolean): void;
|
|
326
|
+
setStopping(value: boolean): void;
|
|
327
|
+
canCallIntoJs(): boolean;
|
|
328
|
+
destroy(): void;
|
|
307
329
|
}
|
|
308
330
|
|
|
309
331
|
export declare function createContext(): Context;
|
|
@@ -319,18 +341,16 @@ export declare class Deferred<T = any> implements IStoreValue {
|
|
|
319
341
|
dispose(): void;
|
|
320
342
|
}
|
|
321
343
|
|
|
322
|
-
export declare class DeferredStore extends Store<Deferred> {
|
|
323
|
-
constructor();
|
|
324
|
-
}
|
|
325
|
-
|
|
326
344
|
export declare class EmnapiError extends Error {
|
|
327
345
|
constructor(message?: string);
|
|
328
346
|
}
|
|
329
347
|
|
|
330
348
|
export declare class Env implements IStoreValue {
|
|
331
349
|
readonly ctx: Context;
|
|
350
|
+
moduleApiVersion: number;
|
|
332
351
|
makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
|
|
333
352
|
makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
|
|
353
|
+
abort: (msg?: string) => never;
|
|
334
354
|
id: number;
|
|
335
355
|
openHandleScopes: number;
|
|
336
356
|
instanceData: RefBase | null;
|
|
@@ -338,16 +358,15 @@ export declare class Env implements IStoreValue {
|
|
|
338
358
|
refs: number;
|
|
339
359
|
reflist: RefTracker;
|
|
340
360
|
finalizing_reflist: RefTracker;
|
|
341
|
-
private destructing;
|
|
342
|
-
finalizationScheduled: boolean;
|
|
343
361
|
pendingFinalizers: RefTracker[];
|
|
344
362
|
lastError: {
|
|
345
363
|
errorCode: napi_status;
|
|
346
364
|
engineErrorCode: number;
|
|
347
365
|
engineReserved: Ptr;
|
|
348
366
|
};
|
|
349
|
-
|
|
350
|
-
|
|
367
|
+
constructor(ctx: Context, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never);
|
|
368
|
+
canCallIntoJs(): boolean;
|
|
369
|
+
terminatedOrTerminating(): boolean;
|
|
351
370
|
ref(): void;
|
|
352
371
|
unref(): void;
|
|
353
372
|
ensureHandle<S>(value: S): Handle<S>;
|
|
@@ -355,11 +374,11 @@ export declare class Env implements IStoreValue {
|
|
|
355
374
|
clearLastError(): napi_status;
|
|
356
375
|
setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
|
|
357
376
|
getReturnStatus(): napi_status;
|
|
358
|
-
callIntoModule<T>(fn: (env: Env) => T): T;
|
|
377
|
+
callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
|
|
359
378
|
callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
|
|
360
379
|
enqueueFinalizer(finalizer: RefTracker): void;
|
|
361
380
|
dequeueFinalizer(finalizer: RefTracker): void;
|
|
362
|
-
|
|
381
|
+
deleteMe(): void;
|
|
363
382
|
dispose(): void;
|
|
364
383
|
private readonly _bindingMap;
|
|
365
384
|
initObjectBinding<S extends object>(value: S): IReferenceBinding;
|
|
@@ -368,10 +387,6 @@ export declare class Env implements IStoreValue {
|
|
|
368
387
|
getInstanceData(): number;
|
|
369
388
|
}
|
|
370
389
|
|
|
371
|
-
export declare class EnvStore extends Store<Env> {
|
|
372
|
-
constructor();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
390
|
export declare class Finalizer {
|
|
376
391
|
envObject: Env;
|
|
377
392
|
protected _finalizeCallback: napi_finalize;
|
|
@@ -391,9 +406,7 @@ export declare class Handle<S> {
|
|
|
391
406
|
id: number;
|
|
392
407
|
value: S;
|
|
393
408
|
constructor(id: number, value: S);
|
|
394
|
-
init(id: number, value: S): void;
|
|
395
409
|
data(envObject: Env): void_p;
|
|
396
|
-
isEmpty(): boolean;
|
|
397
410
|
isNumber(): boolean;
|
|
398
411
|
isBigInt(): boolean;
|
|
399
412
|
isString(): boolean;
|
|
@@ -465,6 +478,28 @@ export declare interface IStoreValue {
|
|
|
465
478
|
[x: string]: any;
|
|
466
479
|
}
|
|
467
480
|
|
|
481
|
+
export declare const NAPI_VERSION = Version.NAPI_VERSION;
|
|
482
|
+
|
|
483
|
+
export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
|
|
484
|
+
|
|
485
|
+
export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
|
|
486
|
+
|
|
487
|
+
export declare class NodeEnv extends Env {
|
|
488
|
+
filename: string;
|
|
489
|
+
private readonly nodeBinding?;
|
|
490
|
+
destructing: boolean;
|
|
491
|
+
finalizationScheduled: boolean;
|
|
492
|
+
constructor(ctx: Context, 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);
|
|
493
|
+
deleteMe(): void;
|
|
494
|
+
canCallIntoJs(): boolean;
|
|
495
|
+
triggerFatalException(err: any): void;
|
|
496
|
+
callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T;
|
|
497
|
+
callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
|
|
498
|
+
callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void;
|
|
499
|
+
enqueueFinalizer(finalizer: RefTracker): void;
|
|
500
|
+
drainFinalizerQueue(): void;
|
|
501
|
+
}
|
|
502
|
+
|
|
468
503
|
export declare class NotSupportBigIntError extends EmnapiError {
|
|
469
504
|
constructor(api: string, message: string);
|
|
470
505
|
}
|
|
@@ -511,6 +546,7 @@ export declare class RefBase extends Finalizer {
|
|
|
511
546
|
|
|
512
547
|
export declare class Reference extends RefBase implements IStoreValue {
|
|
513
548
|
id: number;
|
|
549
|
+
private canBeWeak;
|
|
514
550
|
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;
|
|
515
551
|
persistent: Persistent<object>;
|
|
516
552
|
private constructor();
|
|
@@ -522,10 +558,6 @@ export declare class Reference extends RefBase implements IStoreValue {
|
|
|
522
558
|
dispose(): void;
|
|
523
559
|
}
|
|
524
560
|
|
|
525
|
-
export declare class RefStore extends Store<Reference> {
|
|
526
|
-
constructor();
|
|
527
|
-
}
|
|
528
|
-
|
|
529
561
|
export declare class RefTracker {
|
|
530
562
|
finalize(): void;
|
|
531
563
|
private _next;
|
|
@@ -549,7 +581,7 @@ export declare class Store<V extends IStoreValue> {
|
|
|
549
581
|
protected _values: Array<V | undefined>;
|
|
550
582
|
private _freeList;
|
|
551
583
|
private _size;
|
|
552
|
-
constructor(
|
|
584
|
+
constructor();
|
|
553
585
|
add(value: V): void;
|
|
554
586
|
get(id: Ptr): V | undefined;
|
|
555
587
|
has(id: Ptr): boolean;
|
|
@@ -559,6 +591,7 @@ export declare class Store<V extends IStoreValue> {
|
|
|
559
591
|
|
|
560
592
|
export declare class TryCatch {
|
|
561
593
|
private _exception;
|
|
594
|
+
private _caught;
|
|
562
595
|
hasCaught(): boolean;
|
|
563
596
|
exception(): any;
|
|
564
597
|
setError(err: any): void;
|