@emnapi/runtime 0.31.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
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}}(),l="object"==typeof Reflect,c="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h="undefined"!=typeof BigInt;function p(e){return"object"==typeof e&&null!==e||"function"==typeof e}const f="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)},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(){if("function"==typeof n.Buffer)return n.Buffer;try{return d("buffer").Buffer}catch(e){}}();class v{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()&&p(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 _&&_.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 y extends v{constructor(e,t){super(e,t)}dispose(){}}function g(){Object.setPrototypeOf(this,null)}g.prototype=null;class x{constructor(){this._values=[void 0,x.UNDEFINED,x.NULL,x.FALSE,x.TRUE,x.GLOBAL],this._next=x.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 v(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=x.MIN_ID,this._next=x.MIN_ID}}x.UNDEFINED=new y(1,void 0),x.NULL=new y(2,null),x.FALSE=new y(3,!1),x.TRUE=new y(4,!0),x.GLOBAL=new y(5,n),x.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 g,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 b{constructor(){this._rootScope=new S(null,0,null,1,x.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=x.MIN_ID,e.end=x.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class w extends s{constructor(){super(8)}}class k extends s{constructor(){super(8)}}class m{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 E{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 z extends E{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){m.finalizeAll(e)}link(e){m.prototype.link.call(this,e)}unlink(){m.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 C{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 m,this.finalizing_reflist=new m,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 C(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(),f((()=>{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(),z.finalizeAll(this.finalizing_reflist),z.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 z(this,0,0,t,e,s)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}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 H extends D{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class I extends D{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 O{constructor(e){this._ref=e}setWeak(e,t){null!==this._ref&&c&&(this._ref instanceof WeakRef||(this._param=e,this._callback=t,O._registry.register(this._ref,this,this),this._ref=new WeakRef(this._ref)))}clearWeak(){if(null!==this._ref&&c&&this._ref instanceof WeakRef){try{O._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref=this._ref.deref()}}reset(e){if(c)try{O._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref=e||null}isEmpty(){return null===this._ref}deref(){var e;return c?null!==this._ref?this._ref instanceof WeakRef?this._ref.deref():this._ref:void 0:null!==(e=this._ref)&&void 0!==e?e:void 0}}function F(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}O._registry=c?new FinalizationRegistry((e=>{e._ref=null;const t=e._callback,s=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(s)})):void 0;class j extends z{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);if(!p(a.value))throw new TypeError("Invalid reference value");const u=new j(e,s,i,r,n,o);return e.ctx.refStore.add(u),u.persistent=new O(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,F)}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 N{constructor(e,t){this.id=0,this.ctx=e,this.value=t}static create(e,t){const s=new N(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 R{constructor(e,t,s,i){this.envObject=e,this.fn=t,this.arg=s,this.order=i}}class B{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 R(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 L{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 M{constructor(){this.envStore=new i,this.scopeStore=new b,this.refStore=new w,this.deferredStore=new k,this.handleStore=new x,this.cbinfoStack=new t,this.feature={supportReflect:l,supportFinalizer:c,supportBigInt:h,supportNewFunction:r,canSetFunctionName:u,setImmediate:f,Buffer:_},this.cleanupQueue=new B,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new L,process.once("beforeExit",(()=>{this.runCleanup()})))}createNotSupportWeakRefError(e,t){return new H(e,t)}createNotSupportBigIntError(e,t){return new I(e,t)}createReference(e,t,s,i,r=0,n=0,o=0){return j.create(e,t,s,i,r,n,o)}createDeferred(e){return N.create(this,e)}createEnv(e,t){return C.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){return this.scopeStore.closeScope(e)}ensureHandle(e){switch(e){case void 0:return x.UNDEFINED;case null:return x.NULL;case!0:return x.TRUE;case!1:return x.FALSE;case n:return x.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 W;function A(){return new M}exports.CallbackInfo=e,exports.CallbackInfoStack=t,exports.ConstHandle=y,exports.Context=M,exports.Deferred=N,exports.DeferredStore=k,exports.EmnapiError=D,exports.Env=C,exports.EnvStore=i,exports.Finalizer=E,exports.Handle=v,exports.HandleScope=S,exports.HandleStore=x,exports.NotSupportBigIntError=I,exports.NotSupportWeakRefError=H,exports.Persistent=O,exports.RefBase=z,exports.RefStore=w,exports.RefTracker=m,exports.Reference=j,exports.ScopeStore=b,exports.Store=s,exports.TryCatch=a,exports.createContext=A,exports.getDefaultContext=function(){return W||(W=A()),W},exports.isReferenceType=p,exports.version="0.31.0";
package/dist/emnapi.d.ts DELETED
@@ -1,557 +0,0 @@
1
- export declare type Ptr = number | bigint
2
-
3
- export declare interface IBuffer extends Uint8Array {}
4
- export declare interface BufferCtor {
5
- readonly prototype: IBuffer
6
- /** @deprecated */
7
- new (...args: any[]): IBuffer
8
- from: {
9
- (buffer: ArrayBufferLike): IBuffer
10
- (buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer
11
- }
12
- alloc: (size: number) => IBuffer
13
- isBuffer: (obj: unknown) => obj is IBuffer
14
- }
15
-
16
- export declare const enum GlobalHandle {
17
- UNDEFINED = 1,
18
- NULL,
19
- FALSE,
20
- TRUE,
21
- GLOBAL
22
- }
23
-
24
- export declare const enum Ownership {
25
- kRuntime,
26
- kUserland
27
- }
28
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- export declare type Pointer<T> = number
30
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
- export declare type PointerPointer<T> = number
32
- export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T>
33
- export declare type Const<T> = T
34
-
35
- export declare type void_p = Pointer<void>
36
- export declare type void_pp = Pointer<void_p>
37
- export declare type bool = number
38
- export declare type char = number
39
- export declare type char_p = Pointer<char>
40
- export declare type unsigned_char = number
41
- export declare type const_char = Const<char>
42
- export declare type const_char_p = Pointer<const_char>
43
- export declare type char16_t_p = number
44
- export declare type const_char16_t_p = number
45
-
46
- export declare type short = number
47
- export declare type unsigned_short = number
48
- export declare type int = number
49
- export declare type unsigned_int = number
50
- export declare type long = number
51
- export declare type unsigned_long = number
52
- export declare type long_long = bigint
53
- export declare type unsigned_long_long = bigint
54
- export declare type float = number
55
- export declare type double = number
56
- export declare type long_double = number
57
- export declare type size_t = number
58
-
59
- export declare type int8_t = number
60
- export declare type uint8_t = number
61
- export declare type int16_t = number
62
- export declare type uint16_t = number
63
- export declare type int32_t = number
64
- export declare type uint32_t = number
65
- export declare type int64_t = bigint
66
- export declare type uint64_t = bigint
67
- export declare type napi_env = Pointer<unknown>
68
-
69
- export declare type napi_value = Pointer<unknown>
70
- export declare type napi_ref = Pointer<unknown>
71
- export declare type napi_deferred = Pointer<unknown>
72
- export declare type napi_handle_scope = Pointer<unknown>
73
- export declare type napi_escapable_handle_scope = Pointer<unknown>
74
-
75
- export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value>
76
-
77
- export declare type napi_callback_info = Pointer<unknown>
78
- export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value>
79
-
80
- export declare interface napi_extended_error_info {
81
- error_message: const_char_p
82
- engine_reserved: void_p
83
- engine_error_code: uint32_t
84
- error_code: napi_status
85
- }
86
-
87
- export declare interface napi_property_descriptor {
88
- // One of utf8name or name should be NULL.
89
- utf8name: const_char_p
90
- name: napi_value
91
-
92
- method: napi_callback
93
- getter: napi_callback
94
- setter: napi_callback
95
- value: napi_value
96
- /* napi_property_attributes */
97
- attributes: number
98
- data: void_p
99
- }
100
-
101
- export declare type napi_finalize = FunctionPointer<(
102
- env: napi_env,
103
- finalize_data: void_p,
104
- finalize_hint: void_p
105
- ) => void>
106
-
107
- export declare interface node_module {
108
- nm_version: int32_t
109
- nm_flags: uint32_t
110
- nm_filename: Pointer<const_char>
111
- nm_register_func: napi_addon_register_func
112
- nm_modname: Pointer<const_char>
113
- nm_priv: Pointer<void>
114
- reserved: PointerPointer<void>
115
- }
116
-
117
- export declare interface napi_node_version {
118
- major: uint32_t
119
- minor: uint32_t
120
- patch: uint32_t
121
- release: const_char_p
122
- }
123
-
124
- export declare interface emnapi_emscripten_version {
125
- major: uint32_t
126
- minor: uint32_t
127
- patch: uint32_t
128
- }
129
-
130
- export declare const enum napi_status {
131
- napi_ok,
132
- napi_invalid_arg,
133
- napi_object_expected,
134
- napi_string_expected,
135
- napi_name_expected,
136
- napi_function_expected,
137
- napi_number_expected,
138
- napi_boolean_expected,
139
- napi_array_expected,
140
- napi_generic_failure,
141
- napi_pending_exception,
142
- napi_cancelled,
143
- napi_escape_called_twice,
144
- napi_handle_scope_mismatch,
145
- napi_callback_scope_mismatch,
146
- napi_queue_full,
147
- napi_closing,
148
- napi_bigint_expected,
149
- napi_date_expected,
150
- napi_arraybuffer_expected,
151
- napi_detachable_arraybuffer_expected,
152
- napi_would_deadlock, // unused
153
- napi_no_external_buffers_allowed
154
- }
155
-
156
- export declare const enum napi_property_attributes {
157
- napi_default = 0,
158
- napi_writable = 1 << 0,
159
- napi_enumerable = 1 << 1,
160
- napi_configurable = 1 << 2,
161
-
162
- // Used with napi_define_class to distinguish static properties
163
- // from instance properties. Ignored by napi_define_properties.
164
- napi_static = 1 << 10,
165
-
166
- /// #ifdef NAPI_EXPERIMENTAL
167
- // Default for class methods.
168
- napi_default_method = napi_writable | napi_configurable,
169
-
170
- // Default for object properties, like in JS obj[prop].
171
- napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable
172
- /// #endif // NAPI_EXPERIMENTAL
173
- }
174
-
175
- export declare const enum napi_valuetype {
176
- napi_undefined,
177
- napi_null,
178
- napi_boolean,
179
- napi_number,
180
- napi_string,
181
- napi_symbol,
182
- napi_object,
183
- napi_function,
184
- napi_external,
185
- napi_bigint
186
- }
187
-
188
- export declare const enum napi_typedarray_type {
189
- napi_int8_array,
190
- napi_uint8_array,
191
- napi_uint8_clamped_array,
192
- napi_int16_array,
193
- napi_uint16_array,
194
- napi_int32_array,
195
- napi_uint32_array,
196
- napi_float32_array,
197
- napi_float64_array,
198
- napi_bigint64_array,
199
- napi_biguint64_array
200
- }
201
-
202
- export declare const enum napi_key_collection_mode {
203
- napi_key_include_prototypes,
204
- napi_key_own_only
205
- }
206
-
207
- export declare const enum napi_key_filter {
208
- napi_key_all_properties = 0,
209
- napi_key_writable = 1,
210
- napi_key_enumerable = 1 << 1,
211
- napi_key_configurable = 1 << 2,
212
- napi_key_skip_strings = 1 << 3,
213
- napi_key_skip_symbols = 1 << 4
214
- }
215
-
216
- export declare const enum napi_key_conversion {
217
- napi_key_keep_numbers,
218
- napi_key_numbers_to_strings
219
- }
220
-
221
- export declare const enum emnapi_memory_view_type {
222
- emnapi_int8_array,
223
- emnapi_uint8_array,
224
- emnapi_uint8_clamped_array,
225
- emnapi_int16_array,
226
- emnapi_uint16_array,
227
- emnapi_int32_array,
228
- emnapi_uint32_array,
229
- emnapi_float32_array,
230
- emnapi_float64_array,
231
- emnapi_bigint64_array,
232
- emnapi_biguint64_array,
233
- emnapi_data_view = -1,
234
- emnapi_buffer = -2
235
- }
236
- export declare class CallbackInfo {
237
- parent: CallbackInfo | null;
238
- thiz: any;
239
- data: void_p;
240
- args: ArrayLike<any>;
241
- fn: Function;
242
- constructor(parent: CallbackInfo | null, thiz: any, data: void_p, args: ArrayLike<any>, fn: Function);
243
- getNewTarget(envObject: Env): number;
244
- }
245
-
246
- export declare class CallbackInfoStack {
247
- current: CallbackInfo | null;
248
- pop(): void;
249
- push(thiz: any, data: void_p, args: ArrayLike<any>, fn: Function): CallbackInfo;
250
- dispose(): void;
251
- }
252
-
253
- export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
254
-
255
- export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
256
- constructor(id: number, value: S);
257
- dispose(): void;
258
- }
259
-
260
- export declare class Context {
261
- envStore: EnvStore;
262
- scopeStore: ScopeStore;
263
- refStore: RefStore;
264
- deferredStore: DeferredStore;
265
- handleStore: HandleStore;
266
- cbinfoStack: CallbackInfoStack;
267
- private readonly refCounter?;
268
- private readonly cleanupQueue;
269
- feature: {
270
- supportReflect: boolean;
271
- supportFinalizer: boolean;
272
- supportBigInt: boolean;
273
- supportNewFunction: boolean;
274
- canSetFunctionName: boolean;
275
- setImmediate: (f: () => void) => void;
276
- Buffer: BufferCtor | undefined;
277
- };
278
- constructor();
279
- createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
280
- createNotSupportBigIntError(api: string, message: string): NotSupportBigIntError;
281
- 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;
282
- createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
283
- createEnv(makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void): Env;
284
- getCurrentScope(): HandleScope | null;
285
- addToCurrentScope<V>(value: V): Handle<V>;
286
- openScope(envObject: Env): HandleScope;
287
- closeScope(envObject: Env, _scope?: HandleScope): void;
288
- ensureHandle<S>(value: S): Handle<S>;
289
- addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
290
- removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
291
- runCleanup(): void;
292
- increaseWaitingRequestCounter(): void;
293
- decreaseWaitingRequestCounter(): void;
294
- dispose(): void;
295
- }
296
-
297
- export declare function createContext(): Context;
298
-
299
- export declare class Deferred<T = any> implements IStoreValue {
300
- static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
301
- id: number;
302
- ctx: Context;
303
- value: IDeferrdValue<T>;
304
- constructor(ctx: Context, value: IDeferrdValue<T>);
305
- resolve(value: T): void;
306
- reject(reason?: any): void;
307
- dispose(): void;
308
- }
309
-
310
- export declare class DeferredStore extends Store<Deferred> {
311
- constructor();
312
- }
313
-
314
- export declare class EmnapiError extends Error {
315
- constructor(message?: string);
316
- }
317
-
318
- export declare class Env implements IStoreValue {
319
- readonly ctx: Context;
320
- makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
321
- makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
322
- id: number;
323
- openHandleScopes: number;
324
- instanceData: RefBase | null;
325
- tryCatch: TryCatch;
326
- refs: number;
327
- reflist: RefTracker;
328
- finalizing_reflist: RefTracker;
329
- private destructing;
330
- finalizationScheduled: boolean;
331
- pendingFinalizers: RefTracker[];
332
- lastError: {
333
- errorCode: napi_status;
334
- engineErrorCode: number;
335
- engineReserved: Ptr;
336
- };
337
- static create(ctx: Context, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void): Env;
338
- private constructor();
339
- ref(): void;
340
- unref(): void;
341
- ensureHandle<S>(value: S): Handle<S>;
342
- ensureHandleId(value: any): napi_value;
343
- clearLastError(): napi_status;
344
- setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
345
- getReturnStatus(): napi_status;
346
- callIntoModule<T>(fn: (env: Env) => T): T;
347
- callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
348
- enqueueFinalizer(finalizer: RefTracker): void;
349
- dequeueFinalizer(finalizer: RefTracker): void;
350
- drainFinalizerQueue(): void;
351
- dispose(): void;
352
- private readonly _bindingMap;
353
- initObjectBinding<S extends object>(value: S): IReferenceBinding;
354
- getObjectBinding<S extends object>(value: S): IReferenceBinding;
355
- setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void;
356
- getInstanceData(): number;
357
- }
358
-
359
- export declare class EnvStore extends Store<Env> {
360
- constructor();
361
- }
362
-
363
- export declare class Finalizer {
364
- envObject: Env;
365
- protected _finalizeCallback: napi_finalize;
366
- protected _finalizeData: void_p;
367
- protected _finalizeHint: void_p;
368
- constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
369
- callback(): napi_finalize;
370
- data(): void_p;
371
- hint(): void_p;
372
- resetFinalizer(): void;
373
- dispose(): void;
374
- }
375
-
376
- export declare function getDefaultContext(): Context;
377
-
378
- export declare class Handle<S> {
379
- id: number;
380
- value: S;
381
- constructor(id: number, value: S);
382
- init(id: number, value: S): void;
383
- data(envObject: Env): void_p;
384
- isEmpty(): boolean;
385
- isNumber(): boolean;
386
- isBigInt(): boolean;
387
- isString(): boolean;
388
- isFunction(): boolean;
389
- isExternal(): boolean;
390
- isObject(): boolean;
391
- isArray(): boolean;
392
- isArrayBuffer(): boolean;
393
- isTypedArray(): boolean;
394
- isBuffer(): boolean;
395
- isDataView(): boolean;
396
- isDate(): boolean;
397
- isPromise(): boolean;
398
- isBoolean(): boolean;
399
- isUndefined(): boolean;
400
- isSymbol(): boolean;
401
- isNull(): boolean;
402
- dispose(): void;
403
- }
404
-
405
- export declare class HandleScope {
406
- handleStore: HandleStore;
407
- id: number;
408
- parent: HandleScope | null;
409
- child: HandleScope | null;
410
- start: number;
411
- end: number;
412
- _escapeCalled: boolean;
413
- constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
414
- add<V>(value: V): Handle<V>;
415
- addExternal(envObject: Env, data: void_p): Handle<object>;
416
- dispose(): void;
417
- escape(handle: number): Handle<any> | null;
418
- escapeCalled(): boolean;
419
- }
420
-
421
- export declare class HandleStore {
422
- static UNDEFINED: ConstHandle<undefined>;
423
- static NULL: ConstHandle<null>;
424
- static FALSE: ConstHandle<false>;
425
- static TRUE: ConstHandle<true>;
426
- static GLOBAL: ConstHandle<typeof globalThis>;
427
- static MIN_ID: 6;
428
- private readonly _values;
429
- private _next;
430
- push<S>(value: S): Handle<S>;
431
- erase(start: number, end: number): void;
432
- get(id: Ptr): Handle<any> | undefined;
433
- swap(a: number, b: number): void;
434
- dispose(): void;
435
- }
436
-
437
- export declare interface IDeferrdValue<T = any> {
438
- resolve: (value: T) => void;
439
- reject: (reason?: any) => void;
440
- }
441
-
442
- export declare interface IReferenceBinding {
443
- wrapped: number;
444
- tag: [number, number, number, number] | null;
445
- data: void_p;
446
- }
447
-
448
- export declare function isReferenceType(v: any): v is object;
449
-
450
- export declare interface IStoreValue {
451
- id: number;
452
- dispose(): void;
453
- [x: string]: any;
454
- }
455
-
456
- export declare class NotSupportBigIntError extends EmnapiError {
457
- constructor(api: string, message: string);
458
- }
459
-
460
- export declare class NotSupportWeakRefError extends EmnapiError {
461
- constructor(api: string, message: string);
462
- }
463
-
464
- export declare class Persistent<T extends object> {
465
- private _ref;
466
- private _param;
467
- private _callback;
468
- private static readonly _registry;
469
- constructor(value: T);
470
- setWeak<P>(param: P, callback: (param: P) => void): void;
471
- clearWeak(): void;
472
- reset(other?: T | WeakRef<T>): void;
473
- isEmpty(): boolean;
474
- deref(): T | undefined;
475
- }
476
-
477
- export declare interface RefBase extends Finalizer, RefTracker {
478
- }
479
-
480
- export declare class RefBase extends Finalizer {
481
- static finalizeAll(list: RefTracker): void;
482
- link(list: RefTracker): void;
483
- unlink(): void;
484
- private _refcount;
485
- private readonly _ownership;
486
- constructor(envObject: Env, initial_refcount: uint32_t, ownership: number, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
487
- dispose(): void;
488
- data(): void_p;
489
- ref(): uint32_t;
490
- unref(): uint32_t;
491
- refCount(): uint32_t;
492
- ownership(): number;
493
- finalize(): void;
494
- }
495
-
496
- export declare class Reference extends RefBase implements IStoreValue {
497
- id: number;
498
- 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;
499
- persistent: Persistent<object>;
500
- private constructor();
501
- ref(): number;
502
- unref(): number;
503
- get(): napi_value;
504
- private _setWeak;
505
- finalize(): void;
506
- dispose(): void;
507
- }
508
-
509
- export declare class RefStore extends Store<Reference> {
510
- constructor();
511
- }
512
-
513
- export declare class RefTracker {
514
- finalize(): void;
515
- private _next;
516
- private _prev;
517
- link(list: RefTracker): void;
518
- unlink(): void;
519
- static finalizeAll(list: RefTracker): void;
520
- }
521
-
522
- export declare class ScopeStore {
523
- private readonly _rootScope;
524
- currentScope: HandleScope;
525
- constructor();
526
- get(id: number): HandleScope | undefined;
527
- openScope(envObject: Env): HandleScope;
528
- closeScope(envObject: Env): void;
529
- dispose(): void;
530
- }
531
-
532
- export declare class Store<V extends IStoreValue> {
533
- protected _values: Array<V | undefined>;
534
- private _freeList;
535
- private _size;
536
- constructor(capacity: number);
537
- add(value: V): void;
538
- get(id: Ptr): V | undefined;
539
- has(id: Ptr): boolean;
540
- remove(id: Ptr): void;
541
- dispose(): void;
542
- }
543
-
544
- export declare class TryCatch {
545
- private _exception;
546
- hasCaught(): boolean;
547
- exception(): any;
548
- setError(err: any): void;
549
- reset(): void;
550
- extractException(): any;
551
- }
552
-
553
- export declare const version: string;
554
-
555
- export { }
556
-
557
- export as namespace emnapi;