@emnapi/runtime 0.38.3 → 0.40.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 +288 -181
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.ts +56 -27
- package/dist/emnapi.esm-bundler.js +281 -173
- package/dist/emnapi.iife.d.ts +48 -26
- package/dist/emnapi.iife.js +312 -205
- package/dist/emnapi.js +312 -205
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +285 -177
- package/package.json +5 -5
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(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),_="function"==typeof MessageChannel?MessageChannel:function(){try{return d("worker_threads").MessageChannel}catch(e){}}(),v="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(_){let t=new _;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},y="function"==typeof Buffer?Buffer:function(){try{return d("buffer").Buffer}catch(e){}}();class g{constructor(e,t){this.id=e,this.value=t}init(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isEmpty(){return 0===this.id}isNumber(){return!this.isEmpty()&&"number"==typeof this.value}isBigInt(){return!this.isEmpty()&&"bigint"==typeof this.value}isString(){return!this.isEmpty()&&"string"==typeof this.value}isFunction(){return!this.isEmpty()&&"function"==typeof this.value}isExternal(){return!this.isEmpty()&&f(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return!this.isEmpty()&&"object"==typeof this.value&&null!==this.value}isArray(){return!this.isEmpty()&&Array.isArray(this.value)}isArrayBuffer(){return!this.isEmpty()&&this.value instanceof ArrayBuffer}isTypedArray(){return!this.isEmpty()&&ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(){return!this.isEmpty()&&"function"==typeof y&&y.isBuffer(this.value)}isDataView(){return!this.isEmpty()&&this.value instanceof DataView}isDate(){return!this.isEmpty()&&this.value instanceof Date}isPromise(){return!this.isEmpty()&&this.value instanceof Promise}isBoolean(){return!this.isEmpty()&&"boolean"==typeof this.value}isUndefined(){return!this.isEmpty()&&void 0===this.value}isSymbol(){return!this.isEmpty()&&"symbol"==typeof this.value}isNull(){return!this.isEmpty()&&null===this.value}dispose(){0!==this.id&&(this.id=0,this.value=void 0)}}class x extends g{constructor(e,t){super(e,t)}dispose(){}}function b(){Object.setPrototypeOf(this,null)}b.prototype=null;class S{constructor(){this._values=[void 0,S.UNDEFINED,S.NULL,S.FALSE,S.TRUE,S.GLOBAL],this._next=S.MIN_ID}push(e){let t;const s=this._next,i=this._values;return s<i.length?(t=i[s],t.init(s,e)):(t=new g(s,e),i[s]=t),this._next++,t}erase(e,t){this._next=e;const s=this._values;for(let i=e;i<t;++i)s[i].dispose()}get(e){return this._values[e]}swap(e,t){const s=this._values,i=s[e];s[e]=s[t],s[e].id=Number(e),s[t]=i,i.id=Number(t)}dispose(){this._values.length=S.MIN_ID,this._next=S.MIN_ID}}S.UNDEFINED=new x(1,void 0),S.NULL=new x(2,null),S.FALSE=new x(3,!1),S.TRUE=new x(4,!0),S.GLOBAL=new x(5,n),S.MIN_ID=6;class w{constructor(e,t,s,i,r=i){this.handleStore=e,this.id=t,this.parent=s,this.child=null,null!==s&&(s.child=this),this.start=i,this.end=r,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const s=new b,i=e.ctx.handleStore.push(s);return e.initObjectBinding(s).data=t,this.end++,i}dispose(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class m{constructor(){this._rootScope=new w(null,0,null,1,S.MIN_ID),this.currentScope=this._rootScope}get(e){e=Number(e);let t=this.currentScope;for(;t!==this._rootScope;){if(t.id===e)return t;t=t.parent}}openScope(e){const t=this.currentScope;let s=t.child;return null!==s?(s.start=s.end=t.end,s._escapeCalled=!1):s=new w(e.ctx.handleStore,t.id+1,t,t.end),this.currentScope=s,e.openHandleScopes++,s}closeScope(e){if(0===e.openHandleScopes)return;const t=this.currentScope;this.currentScope=t.parent,t.dispose(),e.openHandleScopes--}dispose(){let e=this.currentScope;for(;null!==e;){e.handleStore=null,e.id=0,e.parent=null,e.start=S.MIN_ID,e.end=S.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class k extends s{constructor(){super(8)}}class E extends s{constructor(){super(8)}}class z{constructor(){this._next=null,this._prev=null}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class C{constructor(e,t=0,s=0,i=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=s,this._finalizeHint=i}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}dispose(){this.envObject=void 0}}class D extends C{constructor(e,t,s,i,r,n){super(e,i,r,n),this._next=null,this._prev=null,this._refcount=t,this._ownership=s,this.link(i?e.finalizing_reflist:e.reflist)}static finalizeAll(e){z.finalizeAll(e)}link(e){z.prototype.link.call(this,e)}unlink(){z.prototype.unlink.call(this)}dispose(){this.unlink(),this.envObject.dequeueFinalizer(this),super.dispose()}data(){return this._finalizeData}ref(){return++this._refcount}unref(){return 0===this._refcount?0:--this._refcount}refCount(){return this._refcount}ownership(){return this._ownership}finalize(){const e=this._ownership,t=this._finalizeCallback,s=this._finalizeData,i=this._finalizeHint;let r;this.resetFinalizer(),this.unlink();let n=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,s,i)}catch(e){n=!0,r=e}}if(0===e&&this.dispose(),n)throw r}}class H{constructor(e,t,s){this.ctx=e,this.makeDynCall_vppp=t,this.makeDynCall_vp=s,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new a,this.refs=1,this.reflist=new z,this.finalizing_reflist=new z,this.destructing=!1,this.finalizationScheduled=!1,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}static create(e,t,s){const i=new H(e,t,s);return e.envStore.add(i),e.addCleanupHook(i,(()=>{i.unref()}),0),i}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return e.errorCode=0,e.engineErrorCode=0,e.engineReserved=0,0}setLastError(e,t=0,s=0){const i=this.lastError;return i.errorCode=e,i.engineErrorCode=t,i.engineReserved=s,e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e){this.clearLastError();const t=e(this);if(this.tryCatch.hasCaught()){throw this.tryCatch.extractException()}return t}callFinalizer(e,t,s){const i=this.makeDynCall_vppp(e),r=this.id,n=this.ctx.openScope(this);try{this.callIntoModule((()=>{i(r,t,s)}))}finally{this.ctx.closeScope(this,n)}}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),v((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}dispose(){0!==this.id&&(this.destructing=!0,this.drainFinalizerQueue(),D.finalizeAll(this.finalizing_reflist),D.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null,data:0};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,s){this.instanceData&&this.instanceData.dispose(),this.instanceData=new D(this,0,0,t,e,s)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class O extends Error{constructor(e){super(e);const t=new.target,s=t.prototype;if(!(this instanceof O)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,s):this.__proto__=s,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(O.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class F extends O{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(F.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class I extends O{constructor(e,t){super(`${e}: The current runtime does not support "BigInt".${t?` ${t}`:""}`)}}Object.defineProperty(I.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});class N extends O{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(N.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class j{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class B{constructor(e){this._ref=new j(e)}setWeak(e,t){if(!l||void 0===this._ref||this._ref instanceof WeakRef)return;const s=this._ref.deref();try{B._registry.register(s,this,this);const i=new WeakRef(s);this._ref.dispose(),this._ref=i,this._param=e,this._callback=t}catch(e){}}clearWeak(){if(l&&void 0!==this._ref&&this._ref instanceof WeakRef){try{B._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new j(e)}}reset(){if(l)try{B._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof j&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}function R(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}B._registry=l?new FinalizationRegistry((e=>{e._ref=void 0;const t=e._callback,s=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(s)})):void 0;class L extends D{constructor(e,t,s,i=0,r=0,n=0){super(e,t>>>0,s,i,r,n),this.id=0}static create(e,t,s,i,r=0,n=0,o=0){const a=e.ctx.handleStore.get(t),u=new L(e,s,i,r,n,o);return e.ctx.refStore.add(u),u.persistent=new B(a.value),0===s&&u._setWeak(),u}ref(){if(this.persistent.isEmpty())return 0;const e=super.ref();if(1===e){this.persistent.deref()&&this.persistent.clearWeak()}return e}unref(){if(this.persistent.isEmpty())return 0;const e=this.refCount(),t=super.unref();if(1===e&&0===t){this.persistent.deref()&&this._setWeak()}return t}get(){const e=this.persistent.deref();if(e){return this.envObject.ensureHandle(e).id}return 0}_setWeak(){this.persistent.setWeak(this,R)}finalize(){this.persistent.reset(),super.finalize()}dispose(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.id=0)}}class M{constructor(e,t){this.id=0,this.ctx=e,this.value=t}static create(e,t){const s=new M(e,t);return e.deferredStore.add(s),s}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class T{constructor(e,t,s,i){this.envObject=e,this.fn=t,this.arg=s,this.order=i}}class W{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,s){if(this._cleanupHooks.filter((i=>i.envObject===e&&i.fn===t&&i.arg===s)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new T(e,t,s,this._cleanupHookCounter++))}remove(e,t,s){for(let i=0;i<this._cleanupHooks.length;++i){const r=this._cleanupHooks[i];if(r.envObject===e&&r.fn===t&&r.arg===s)return void this._cleanupHooks.splice(i,1)}}drain(){const e=this._cleanupHooks.slice();e.sort(((e,t)=>t.order-e.order));for(let t=0;t<e.length;++t){const s=e[t];"number"==typeof s.fn?s.envObject.makeDynCall_vp(s.fn)(s.arg):s.fn(s.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(s),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class A{constructor(){this.refHandle=(new _).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)}}class P{constructor(){this.envStore=new i,this.scopeStore=new m,this.refStore=new k,this.deferredStore=new E,this.handleStore=new S,this.cbinfoStack=new t,this.feature={supportReflect:c,supportFinalizer:l,supportWeakSymbol:h,supportBigInt:p,supportNewFunction:r,canSetFunctionName:u,setImmediate:v,Buffer:y,MessageChannel:_},this.cleanupQueue=new W,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new A,process.once("beforeExit",(()=>{this.runCleanup()})))}createNotSupportWeakRefError(e,t){return new F(e,t)}createNotSupportBigIntError(e,t){return new I(e,t)}createNotSupportBufferError(e,t){return new N(e,t)}createReference(e,t,s,i,r=0,n=0,o=0){return L.create(e,t,s,i,r,n,o)}createDeferred(e){return M.create(this,e)}createEnv(e,t){return H.create(this,e,t)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){return this.scopeStore.openScope(e)}closeScope(e,t){this.scopeStore.closeScope(e)}ensureHandle(e){switch(e){case void 0:return S.UNDEFINED;case null:return S.NULL;case!0:return S.TRUE;case!1:return S.FALSE;case n:return S.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,s){this.cleanupQueue.add(e,t,s)}removeCleanupHook(e,t,s){this.cleanupQueue.remove(e,t,s)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}dispose(){this.runCleanup()}}let q;function U(){return new P}exports.CallbackInfo=e,exports.CallbackInfoStack=t,exports.ConstHandle=x,exports.Context=P,exports.Deferred=M,exports.DeferredStore=E,exports.EmnapiError=O,exports.Env=H,exports.EnvStore=i,exports.Finalizer=C,exports.Handle=g,exports.HandleScope=w,exports.HandleStore=S,exports.NotSupportBigIntError=I,exports.NotSupportBufferError=N,exports.NotSupportWeakRefError=F,exports.Persistent=B,exports.RefBase=D,exports.RefStore=k,exports.RefTracker=z,exports.Reference=L,exports.ScopeStore=m,exports.Store=s,exports.TryCatch=a,exports.createContext=U,exports.getDefaultContext=function(){return q||(q=U()),q},exports.isReferenceType=f,exports.version="0.38.3";
|
|
1
|
+
class e{constructor(e,t,n,s,i){this.parent=e,this.thiz=t,this.data=n,this.args=s,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,n,s,i){const r=new e(this.current,t,n,s,i);return this.current=r,r}dispose(){this.current=null}}const n=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),s=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 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.40.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 n=this._next,s=this._values;return n<s.length?(t=s[n],t.value=e):(t=new y(n,e),s[n]=t),this._next++,t}erase(e,t){this._next=e;const n=this._values;for(let s=e;s<t;++s)n[s].dispose()}get(e){return this._values[e]}swap(e,t){const n=this._values,s=n[e];n[e]=n[t],n[e].id=Number(e),n[t]=s,s.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,s),S.MIN_ID=6;class w{constructor(e,t,n,s,i=s){this.handleStore=e,this.id=t,this.parent=n,this.child=null,null!==n&&(n.child=this),this.start=s,this.end=i,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const n=new b,s=e.ctx.handleStore.push(n);return e.initObjectBinding(n).data=t,this.end++,s}dispose(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class k{constructor(){this._rootScope=new 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 n=t.child;return null!==n?(n.start=n.end=t.end,n._escapeCalled=!1):n=new w(e.ctx.handleStore,t.id+1,t,t.end),this.currentScope=n,e.openHandleScopes++,n}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,n=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=n,this._finalizeHint=s}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}dispose(){this.envObject=void 0}}class m extends C{static finalizeAll(e){E.finalizeAll(e)}link(e){E.prototype.link.call(this,e)}unlink(){E.prototype.unlink.call(this)}constructor(e,t,n,s,i,r){super(e,s,i,r),this._next=null,this._prev=null,this._refcount=t,this._ownership=n,this.link(s?e.finalizing_reflist:e.reflist)}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,n=this._finalizeData,s=this._finalizeHint;let i;this.resetFinalizer(),this.unlink();let r=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,n,s)}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,n,s,r){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=n,this.makeDynCall_vp=s,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,n=0){const s=this.lastError;return s.errorCode!==e&&(s.errorCode=e),s.engineErrorCode!==t&&(s.engineErrorCode=t),s.engineReserved!==n&&(s.engineReserved=n),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=I){const n=this.openHandleScopes;this.clearLastError();const s=e(this);if(n!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return s}callFinalizer(e,t,n){const s=this.makeDynCall_vppp(e),i=this.id,r=this.ctx.openScope(this);try{this.callIntoModule((()=>{s(i,t,n)}))}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,n){this.instanceData&&this.instanceData.dispose(),this.instanceData=new m(this,0,0,t,e,n)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class N extends z{constructor(e,t,n,s,i,r,o){super(e,n,s,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,n)=>{if(t.terminatedOrTerminating())return;const s="object"==typeof process&&null!==process;if(!(!!s&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy")))&&!e){if(!s||"function"!=typeof process.emitWarning)throw n;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(n)}))}callFinalizer(e,t,n){this.callFinalizerInternal(1,e,t,n)}callFinalizerInternal(e,t,n,s){const i=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),(()=>{i(r,n,s)}))}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,n,s,i,r,o){(n="number"!=typeof n?8:n)<8?n=8:n>v&&n!==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,n);const a=new N(e,t,n,s,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,n=t.prototype;if(!(this instanceof D)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,n):this.__proto__=n,"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 n=this._ref.deref();try{j._registry.register(n,this,this);const s=new WeakRef(n);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof n)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,n=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(n)})):void 0;class M extends m{static create(e,t,n,s,i=0,r=0,o=0){const a=e.ctx.handleStore.get(t),l=new M(e,n,s,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===n&&l._setWeak(),l}constructor(e,t,n,s=0,i=0,r=0){super(e,t>>>0,n,s,i,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,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{static create(e,t){const n=new L(e,t);return e.deferredStore.add(n),n}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 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,n,s){this.envObject=e,this.fn=t,this.arg=n,this.order=s}}class P{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,n){if(this._cleanupHooks.filter((s=>s.envObject===e&&s.fn===t&&s.arg===n)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new W(e,t,n,this._cleanupHookCounter++))}remove(e,t,n){for(let s=0;s<this._cleanupHooks.length;++s){const i=this._cleanupHooks[s];if(i.envObject===e&&i.fn===t&&i.arg===n)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 n=e[t];"number"==typeof n.fn?n.envObject.makeDynCall_vp(n.fn)(n.arg):n.fn(n.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(n),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:n,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,n,s,i=0,r=0,o=0){return M.create(e,t,n,s,i,r,o)}createDeferred(e){return L.create(this,e)}createEnv(e,t,n,s,i,r){return O(this,e,t,n,s,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 s:return S.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,n){this.cleanupQueue.add(e,t,n)}removeCleanupHook(e,t,n){this.cleanupQueue.remove(e,t,n)}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?;
|
|
@@ -291,12 +300,18 @@ export declare class Context {
|
|
|
291
300
|
} | undefined;
|
|
292
301
|
};
|
|
293
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
|
+
};
|
|
294
309
|
createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
|
|
295
310
|
createNotSupportBigIntError(api: string, message: string): NotSupportBigIntError;
|
|
296
311
|
createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
|
|
297
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;
|
|
298
313
|
createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
|
|
299
|
-
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;
|
|
300
315
|
getCurrentScope(): HandleScope | null;
|
|
301
316
|
addToCurrentScope<V>(value: V): Handle<V>;
|
|
302
317
|
openScope(envObject: Env): HandleScope;
|
|
@@ -307,7 +322,10 @@ export declare class Context {
|
|
|
307
322
|
runCleanup(): void;
|
|
308
323
|
increaseWaitingRequestCounter(): void;
|
|
309
324
|
decreaseWaitingRequestCounter(): void;
|
|
310
|
-
|
|
325
|
+
setCanCallIntoJs(value: boolean): void;
|
|
326
|
+
setStopping(value: boolean): void;
|
|
327
|
+
canCallIntoJs(): boolean;
|
|
328
|
+
destroy(): void;
|
|
311
329
|
}
|
|
312
330
|
|
|
313
331
|
export declare function createContext(): Context;
|
|
@@ -323,18 +341,16 @@ export declare class Deferred<T = any> implements IStoreValue {
|
|
|
323
341
|
dispose(): void;
|
|
324
342
|
}
|
|
325
343
|
|
|
326
|
-
export declare class DeferredStore extends Store<Deferred> {
|
|
327
|
-
constructor();
|
|
328
|
-
}
|
|
329
|
-
|
|
330
344
|
export declare class EmnapiError extends Error {
|
|
331
345
|
constructor(message?: string);
|
|
332
346
|
}
|
|
333
347
|
|
|
334
348
|
export declare class Env implements IStoreValue {
|
|
335
349
|
readonly ctx: Context;
|
|
350
|
+
moduleApiVersion: number;
|
|
336
351
|
makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
|
|
337
352
|
makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
|
|
353
|
+
abort: (msg?: string) => never;
|
|
338
354
|
id: number;
|
|
339
355
|
openHandleScopes: number;
|
|
340
356
|
instanceData: RefBase | null;
|
|
@@ -342,16 +358,15 @@ export declare class Env implements IStoreValue {
|
|
|
342
358
|
refs: number;
|
|
343
359
|
reflist: RefTracker;
|
|
344
360
|
finalizing_reflist: RefTracker;
|
|
345
|
-
private destructing;
|
|
346
|
-
finalizationScheduled: boolean;
|
|
347
361
|
pendingFinalizers: RefTracker[];
|
|
348
362
|
lastError: {
|
|
349
363
|
errorCode: napi_status;
|
|
350
364
|
engineErrorCode: number;
|
|
351
365
|
engineReserved: Ptr;
|
|
352
366
|
};
|
|
353
|
-
|
|
354
|
-
|
|
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;
|
|
355
370
|
ref(): void;
|
|
356
371
|
unref(): void;
|
|
357
372
|
ensureHandle<S>(value: S): Handle<S>;
|
|
@@ -359,11 +374,11 @@ export declare class Env implements IStoreValue {
|
|
|
359
374
|
clearLastError(): napi_status;
|
|
360
375
|
setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
|
|
361
376
|
getReturnStatus(): napi_status;
|
|
362
|
-
callIntoModule<T>(fn: (env: Env) => T): T;
|
|
377
|
+
callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
|
|
363
378
|
callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
|
|
364
379
|
enqueueFinalizer(finalizer: RefTracker): void;
|
|
365
380
|
dequeueFinalizer(finalizer: RefTracker): void;
|
|
366
|
-
|
|
381
|
+
deleteMe(): void;
|
|
367
382
|
dispose(): void;
|
|
368
383
|
private readonly _bindingMap;
|
|
369
384
|
initObjectBinding<S extends object>(value: S): IReferenceBinding;
|
|
@@ -372,10 +387,6 @@ export declare class Env implements IStoreValue {
|
|
|
372
387
|
getInstanceData(): number;
|
|
373
388
|
}
|
|
374
389
|
|
|
375
|
-
export declare class EnvStore extends Store<Env> {
|
|
376
|
-
constructor();
|
|
377
|
-
}
|
|
378
|
-
|
|
379
390
|
export declare class Finalizer {
|
|
380
391
|
envObject: Env;
|
|
381
392
|
protected _finalizeCallback: napi_finalize;
|
|
@@ -395,9 +406,7 @@ export declare class Handle<S> {
|
|
|
395
406
|
id: number;
|
|
396
407
|
value: S;
|
|
397
408
|
constructor(id: number, value: S);
|
|
398
|
-
init(id: number, value: S): void;
|
|
399
409
|
data(envObject: Env): void_p;
|
|
400
|
-
isEmpty(): boolean;
|
|
401
410
|
isNumber(): boolean;
|
|
402
411
|
isBigInt(): boolean;
|
|
403
412
|
isString(): boolean;
|
|
@@ -469,6 +478,28 @@ export declare interface IStoreValue {
|
|
|
469
478
|
[x: string]: any;
|
|
470
479
|
}
|
|
471
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
|
+
|
|
472
503
|
export declare class NotSupportBigIntError extends EmnapiError {
|
|
473
504
|
constructor(api: string, message: string);
|
|
474
505
|
}
|
|
@@ -515,6 +546,7 @@ export declare class RefBase extends Finalizer {
|
|
|
515
546
|
|
|
516
547
|
export declare class Reference extends RefBase implements IStoreValue {
|
|
517
548
|
id: number;
|
|
549
|
+
private canBeWeak;
|
|
518
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;
|
|
519
551
|
persistent: Persistent<object>;
|
|
520
552
|
private constructor();
|
|
@@ -526,10 +558,6 @@ export declare class Reference extends RefBase implements IStoreValue {
|
|
|
526
558
|
dispose(): void;
|
|
527
559
|
}
|
|
528
560
|
|
|
529
|
-
export declare class RefStore extends Store<Reference> {
|
|
530
|
-
constructor();
|
|
531
|
-
}
|
|
532
|
-
|
|
533
561
|
export declare class RefTracker {
|
|
534
562
|
finalize(): void;
|
|
535
563
|
private _next;
|
|
@@ -553,7 +581,7 @@ export declare class Store<V extends IStoreValue> {
|
|
|
553
581
|
protected _values: Array<V | undefined>;
|
|
554
582
|
private _freeList;
|
|
555
583
|
private _size;
|
|
556
|
-
constructor(
|
|
584
|
+
constructor();
|
|
557
585
|
add(value: V): void;
|
|
558
586
|
get(id: Ptr): V | undefined;
|
|
559
587
|
has(id: Ptr): boolean;
|
|
@@ -563,6 +591,7 @@ export declare class Store<V extends IStoreValue> {
|
|
|
563
591
|
|
|
564
592
|
export declare class TryCatch {
|
|
565
593
|
private _exception;
|
|
594
|
+
private _caught;
|
|
566
595
|
hasCaught(): boolean;
|
|
567
596
|
exception(): any;
|
|
568
597
|
setError(err: any): void;
|