quickjs-emscripten-core
Advanced tools
Comparing version 0.26.0 to 0.26.1-rc.0
@@ -1,7 +0,7 @@ | ||
"use strict";var ie=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var Re=Object.prototype.hasOwnProperty;var ke=(o,t)=>(t=Symbol[o])?t:Symbol.for("Symbol."+o);var J=(o,t)=>()=>(o&&(t=o(o=0)),t);var W=(o,t)=>{for(var e in t)ie(o,e,{get:t[e],enumerable:!0})},ne=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ae(t))!Re.call(o,n)&&n!==e&&ie(o,n,{get:()=>t[n],enumerable:!(r=Te(t,n))||r.enumerable});return o},S=(o,t,e)=>(ne(o,t,"default"),e&&ne(e,t,"default"));var Ee=o=>ne(ie({},"__esModule",{value:!0}),o);var ve=(o,t,e)=>{if(t!=null){if(typeof t!="object"&&typeof t!="function")throw TypeError("Object expected");var r;if(e&&(r=t[ke("asyncDispose")]),r===void 0&&(r=t[ke("dispose")]),typeof r!="function")throw TypeError("Object not disposable");o.push([e,r,t])}else e&&o.push([e]);return t},be=(o,t,e)=>{var r=typeof SuppressedError=="function"?SuppressedError:function(s,u,a,l){return l=Error(a),l.name="SuppressedError",l.error=s,l.suppressed=u,l},n=s=>t=e?new r(s,t,"An error was suppressed during disposal"):(e=!0,s),i=s=>{for(;s=o.pop();)try{var u=s[1]&&s[1].call(s[2]);if(s[0])return Promise.resolve(u).then(i,a=>(n(a),i()))}catch(a){n(a)}if(e)throw t};return i()};function f(...o){oe&&console.log(...o)}var oe,C=J(()=>{"use strict";oe=!1});var se={};W(se,{QuickJSAsyncifyError:()=>z,QuickJSAsyncifySuspended:()=>j,QuickJSEmscriptenModuleError:()=>V,QuickJSMemoryLeakDetected:()=>T,QuickJSNotImplemented:()=>D,QuickJSUnknownIntrinsic:()=>Y,QuickJSUnwrapError:()=>F,QuickJSUseAfterFree:()=>L,QuickJSWrongOwner:()=>N});var F,N,L,D,z,j,T,V,Y,v=J(()=>{"use strict";F=class extends Error{constructor(e,r){super(String(e));this.cause=e;this.context=r;this.name="QuickJSUnwrapError"}},N=class extends Error{constructor(){super(...arguments);this.name="QuickJSWrongOwner"}},L=class extends Error{constructor(){super(...arguments);this.name="QuickJSUseAfterFree"}},D=class extends Error{constructor(){super(...arguments);this.name="QuickJSNotImplemented"}},z=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifyError"}},j=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifySuspended"}},T=class extends Error{constructor(){super(...arguments);this.name="QuickJSMemoryLeakDetected"}},V=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmscriptenModuleError"}},Y=class extends TypeError{constructor(){super(...arguments);this.name="QuickJSUnknownIntrinsic"}}});function*ge(o){return yield o}function Fe(o){return ge(le(o))}function ue(o,t){return(...e)=>{let r=t.call(o,ae,...e);return le(r)}}function Qe(o,t){let e=t.call(o,ae);return le(e)}function le(o){function t(e){return e.done?e.value:e.value instanceof Promise?e.value.then(r=>t(o.next(r)),r=>t(o.throw(r))):t(o.next(e.value))}return t(o.next())}var ae,ce=J(()=>{"use strict";ae=ge;ae.of=Fe});function de(o,t){let e;try{o.dispose()}catch(r){e=r}if(t&&e)throw Object.assign(t,{message:`${t.message} | ||
Then, failed to dispose scope: ${e.message}`,disposeError:e}),t;if(t||e)throw t||e}var w,d,k,O,y,b=J(()=>{"use strict";ce();C();v();w=class{[Symbol.dispose](){return this.dispose()}},d=class o extends w{constructor(e,r,n,i){super();this._value=e;this.copier=r;this.disposer=n;this._owner=i;this._alive=!0;this._constructorStack=oe?new Error("Lifetime constructed").stack:void 0}get alive(){return this._alive}get value(){return this.assertAlive(),this._value}get owner(){return this._owner}get dupable(){return!!this.copier}dup(){if(this.assertAlive(),!this.copier)throw new Error("Non-dupable lifetime");return new o(this.copier(this._value),this.copier,this.disposer,this._owner)}consume(e){this.assertAlive();let r=e(this);return this.dispose(),r}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new L(`Lifetime not alive | ||
"use strict";var ie=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var J=(o,t)=>()=>(o&&(t=o(o=0)),t);var W=(o,t)=>{for(var e in t)ie(o,e,{get:t[e],enumerable:!0})},ne=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Pe(t))!He.call(o,n)&&n!==e&&ie(o,n,{get:()=>t[n],enumerable:!(r=Ce(t,n))||r.enumerable});return o},S=(o,t,e)=>(ne(o,t,"default"),e&&ne(e,t,"default"));var Te=o=>ne(ie({},"__esModule",{value:!0}),o);function p(...o){oe&&console.log(...o)}var oe,M=J(()=>{"use strict";oe=!1});var se={};W(se,{QuickJSAsyncifyError:()=>z,QuickJSAsyncifySuspended:()=>j,QuickJSEmscriptenModuleError:()=>V,QuickJSMemoryLeakDetected:()=>H,QuickJSNotImplemented:()=>D,QuickJSUnknownIntrinsic:()=>Y,QuickJSUnwrapError:()=>F,QuickJSUseAfterFree:()=>L,QuickJSWrongOwner:()=>N});var F,N,L,D,z,j,H,V,Y,v=J(()=>{"use strict";F=class extends Error{constructor(e,r){super(String(e));this.cause=e;this.context=r;this.name="QuickJSUnwrapError"}},N=class extends Error{constructor(){super(...arguments);this.name="QuickJSWrongOwner"}},L=class extends Error{constructor(){super(...arguments);this.name="QuickJSUseAfterFree"}},D=class extends Error{constructor(){super(...arguments);this.name="QuickJSNotImplemented"}},z=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifyError"}},j=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifySuspended"}},H=class extends Error{constructor(){super(...arguments);this.name="QuickJSMemoryLeakDetected"}},V=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmscriptenModuleError"}},Y=class extends TypeError{constructor(){super(...arguments);this.name="QuickJSUnknownIntrinsic"}}});function*ke(o){return yield o}function Ae(o){return ke(le(o))}function ue(o,t){return(...e)=>{let r=t.call(o,ae,...e);return le(r)}}function ve(o,t){let e=t.call(o,ae);return le(e)}function le(o){function t(e){return e.done?e.value:e.value instanceof Promise?e.value.then(r=>t(o.next(r)),r=>t(o.throw(r))):t(o.next(e.value))}return t(o.next())}var ae,ce=J(()=>{"use strict";ae=ke;ae.of=Ae});function de(o,t){let e;try{o.dispose()}catch(r){e=r}if(t&&e)throw Object.assign(t,{message:`${t.message} | ||
Then, failed to dispose scope: ${e.message}`,disposeError:e}),t;if(t||e)throw t||e}var w,d,k,O,y,b=J(()=>{"use strict";ce();M();v();w=class{[Symbol.dispose](){return this.dispose()}},d=class o extends w{constructor(e,r,n,i){super();this._value=e;this.copier=r;this.disposer=n;this._owner=i;this._alive=!0;this._constructorStack=oe?new Error("Lifetime constructed").stack:void 0}get alive(){return this._alive}get value(){return this.assertAlive(),this._value}get owner(){return this._owner}get dupable(){return!!this.copier}dup(){if(this.assertAlive(),!this.copier)throw new Error("Non-dupable lifetime");return new o(this.copier(this._value),this.copier,this.disposer,this._owner)}consume(e){this.assertAlive();let r=e(this);return this.dispose(),r}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new L(`Lifetime not alive | ||
${this._constructorStack} | ||
Lifetime used`):new L("Lifetime not alive")}},k=class extends d{constructor(t,e){super(t,void 0,void 0,e)}get dupable(){return!0}dup(){return this}dispose(){}},O=class extends d{constructor(t,e,r,n){super(t,e,r,n)}dispose(){this._alive=!1}};y=class o extends w{constructor(){super(...arguments);this._disposables=new d(new Set)}static withScope(e){let r=new o,n;try{return e(r)}catch(i){throw n=i,i}finally{de(r,n)}}static withScopeMaybeAsync(e,r){return Qe(void 0,function*(n){let i=new o,s;try{return yield*n.of(r.call(e,n,i))}catch(u){throw s=u,u}finally{de(i,s)}})}static async withScopeAsync(e){let r=new o,n;try{return await e(r)}catch(i){throw n=i,i}finally{de(r,n)}}manage(e){return this._disposables.value.add(e),e}get alive(){return this._disposables.alive}dispose(){let e=Array.from(this._disposables.value.values()).reverse();for(let r of e)r.alive&&r.dispose();this._disposables.dispose()}}});var U,me=J(()=>{"use strict";b();U=class extends w{constructor(e){super();this.resolve=e=>{this.resolveHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.resolveHandle,this.context.undefined,e||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())};this.reject=e=>{this.rejectHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.rejectHandle,this.context.undefined,e||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())};this.dispose=()=>{this.handle.alive&&this.handle.dispose(),this.disposeResolvers()};this.context=e.context,this.owner=e.context.runtime,this.handle=e.promiseHandle,this.settled=new Promise(r=>{this.onSettled=r}),this.resolveHandle=e.resolveHandle,this.rejectHandle=e.rejectHandle}get alive(){return this.handle.alive||this.resolveHandle.alive||this.rejectHandle.alive}disposeResolvers(){this.resolveHandle.alive&&this.resolveHandle.dispose(),this.rejectHandle.alive&&this.rejectHandle.dispose()}}});var _,pe=J(()=>{"use strict";b();_=class{constructor(t){this.module=t}toPointerArray(t){let e=new Int32Array(t.map(s=>s.value)),r=e.length*e.BYTES_PER_ELEMENT,n=this.module._malloc(r);return new Uint8Array(this.module.HEAPU8.buffer,n,r).set(new Uint8Array(e.buffer)),new d(n,void 0,s=>this.module._free(s))}newMutablePointerArray(t){let e=new Int32Array(new Array(t).fill(0)),r=e.length*e.BYTES_PER_ELEMENT,n=this.module._malloc(r),i=new Int32Array(this.module.HEAPU8.buffer,n,t);return i.set(e),new d({typedArray:i,ptr:n},void 0,s=>this.module._free(s.ptr))}newHeapCharPointer(t){let e=this.module.lengthBytesUTF8(t)+1,r=this.module._malloc(e);return this.module.stringToUTF8(t,r,e),new d(r,void 0,n=>this.module._free(n))}newHeapBufferPointer(t){let e=t.byteLength,r=this.module._malloc(e);return this.module.HEAPU8.set(t,r),new d({pointer:r,numBytes:e},void 0,n=>this.module._free(n.pointer))}consumeHeapCharPointer(t){let e=this.module.UTF8ToString(t);return this.module._free(t),e}}});function $(o){if(!o)return 0;let t=0;for(let[e,r]of Object.entries(o)){if(!(e in g.IntrinsicsFlags))throw new Y(e);r&&(t|=g.IntrinsicsFlags[e])}return t}function K(o){if(typeof o=="number")return o;if(o===void 0)return 0;let{type:t,strict:e,strip:r,compileOnly:n,backtraceBarrier:i}=o,s=0;return t==="global"&&(s|=g.EvalFlags.JS_EVAL_TYPE_GLOBAL),t==="module"&&(s|=g.EvalFlags.JS_EVAL_TYPE_MODULE),e&&(s|=g.EvalFlags.JS_EVAL_FLAG_STRICT),r&&(s|=g.EvalFlags.JS_EVAL_FLAG_STRIP),n&&(s|=g.EvalFlags.JS_EVAL_FLAG_COMPILE_ONLY),i&&(s|=g.EvalFlags.JS_EVAL_FLAG_BACKTRACE_BARRIER),s}function Ce(...o){let t=[];for(let e of o)e!==void 0&&(t=t.concat(e));return t}var g,tt,Me,A=J(()=>{"use strict";g=require("@jitl/quickjs-ffi-types");v();tt=Symbol("Unstable"),Me=Object.freeze({BaseObjects:!0,Date:!0,Eval:!0,StringNormalize:!0,RegExp:!0,JSON:!0,Proxy:!0,MapSet:!0,TypedArrays:!0,Promise:!0})});var fe,P,q=J(()=>{"use strict";C();me();v();b();pe();A();fe=class extends _{constructor(e){super(e.module);this.scope=new y;this.copyJSValue=e=>this.ffi.QTS_DupValuePointer(this.ctx.value,e);this.freeJSValue=e=>{this.ffi.QTS_FreeValuePointer(this.ctx.value,e)};e.ownedLifetimes?.forEach(r=>this.scope.manage(r)),this.owner=e.owner,this.module=e.module,this.ffi=e.ffi,this.rt=e.rt,this.ctx=this.scope.manage(e.ctx)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}[Symbol.dispose](){return this.dispose()}manage(e){return this.scope.manage(e)}consumeJSCharPointer(e){let r=this.module.UTF8ToString(e);return this.ffi.QTS_FreeCString(this.ctx.value,e),r}heapValueHandle(e){return new d(e,this.copyJSValue,this.freeJSValue,this.owner)}},P=class extends w{constructor(e){super();this._undefined=void 0;this._null=void 0;this._false=void 0;this._true=void 0;this._global=void 0;this._BigInt=void 0;this.fnNextId=-32768;this.fnMaps=new Map;this.cToHostCallbacks={callFunction:(e,r,n,i,s)=>{if(e!==this.ctx.value)throw new Error("QuickJSContext instance received C -> JS call with mismatched ctx");let u=this.getFunction(s);if(!u)throw new Error(`QuickJSContext had no callback with id ${s}`);return y.withScopeMaybeAsync(this,function*(a,l){let p=l.manage(new O(r,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime)),M=new Array(n);for(let m=0;m<n;m++){let c=this.ffi.QTS_ArgvGetJSValueConstPointer(i,m);M[m]=l.manage(new O(c,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime))}try{let m=yield*a(u.apply(p,M));if(m){if("error"in m&&m.error)throw f("throw error",m.error),m.error;let c=l.manage(m instanceof d?m:m.value);return this.ffi.QTS_DupValuePointer(this.ctx.value,c.value)}return 0}catch(m){return this.errorToHandle(m).consume(c=>this.ffi.QTS_Throw(this.ctx.value,c.value))}})}};this.runtime=e.runtime,this.module=e.module,this.ffi=e.ffi,this.rt=e.rt,this.ctx=e.ctx,this.memory=new fe({...e,owner:this.runtime}),e.callbacks.setContextCallbacks(this.ctx.value,this.cToHostCallbacks),this.dump=this.dump.bind(this),this.getString=this.getString.bind(this),this.getNumber=this.getNumber.bind(this),this.resolvePromise=this.resolvePromise.bind(this)}get alive(){return this.memory.alive}dispose(){this.memory.dispose()}get undefined(){if(this._undefined)return this._undefined;let e=this.ffi.QTS_GetUndefined();return this._undefined=new k(e)}get null(){if(this._null)return this._null;let e=this.ffi.QTS_GetNull();return this._null=new k(e)}get true(){if(this._true)return this._true;let e=this.ffi.QTS_GetTrue();return this._true=new k(e)}get false(){if(this._false)return this._false;let e=this.ffi.QTS_GetFalse();return this._false=new k(e)}get global(){if(this._global)return this._global;let e=this.ffi.QTS_GetGlobalObject(this.ctx.value);return this.memory.manage(this.memory.heapValueHandle(e)),this._global=new k(e,this.runtime),this._global}newNumber(e){return this.memory.heapValueHandle(this.ffi.QTS_NewFloat64(this.ctx.value,e))}newString(e){let r=this.memory.newHeapCharPointer(e).consume(n=>this.ffi.QTS_NewString(this.ctx.value,n.value));return this.memory.heapValueHandle(r)}newUniqueSymbol(e){let r=(typeof e=="symbol"?e.description:e)??"",n=this.memory.newHeapCharPointer(r).consume(i=>this.ffi.QTS_NewSymbol(this.ctx.value,i.value,0));return this.memory.heapValueHandle(n)}newSymbolFor(e){let r=(typeof e=="symbol"?e.description:e)??"",n=this.memory.newHeapCharPointer(r).consume(i=>this.ffi.QTS_NewSymbol(this.ctx.value,i.value,1));return this.memory.heapValueHandle(n)}newBigInt(e){if(!this._BigInt){let i=this.getProp(this.global,"BigInt");this.memory.manage(i),this._BigInt=new k(i.value,this.runtime)}let r=this._BigInt,n=String(e);return this.newString(n).consume(i=>this.unwrapResult(this.callFunction(r,this.undefined,i)))}newObject(e){e&&this.runtime.assertOwned(e);let r=e?this.ffi.QTS_NewObjectProto(this.ctx.value,e.value):this.ffi.QTS_NewObject(this.ctx.value);return this.memory.heapValueHandle(r)}newArray(){let e=this.ffi.QTS_NewArray(this.ctx.value);return this.memory.heapValueHandle(e)}newArrayBuffer(e){let r=new Uint8Array(e),n=this.memory.newHeapBufferPointer(r),i=this.ffi.QTS_NewArrayBuffer(this.ctx.value,n.value.pointer,r.length);return this.memory.heapValueHandle(i)}newPromise(e){let r=y.withScope(n=>{let i=n.manage(this.memory.newMutablePointerArray(2)),s=this.ffi.QTS_NewPromiseCapability(this.ctx.value,i.value.ptr),u=this.memory.heapValueHandle(s),[a,l]=Array.from(i.value.typedArray).map(p=>this.memory.heapValueHandle(p));return new U({context:this,promiseHandle:u,resolveHandle:a,rejectHandle:l})});return e&&typeof e=="function"&&(e=new Promise(e)),e&&Promise.resolve(e).then(r.resolve,n=>n instanceof d?r.reject(n):this.newError(n).consume(r.reject)),r}newFunction(e,r){let n=++this.fnNextId;return this.setFunction(n,r),this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value,n,e))}newError(e){let r=this.memory.heapValueHandle(this.ffi.QTS_NewError(this.ctx.value));return e&&typeof e=="object"?(e.name!==void 0&&this.newString(e.name).consume(n=>this.setProp(r,"name",n)),e.message!==void 0&&this.newString(e.message).consume(n=>this.setProp(r,"message",n))):typeof e=="string"?this.newString(e).consume(n=>this.setProp(r,"message",n)):e!==void 0&&this.newString(String(e)).consume(n=>this.setProp(r,"message",n)),r}typeof(e){return this.runtime.assertOwned(e),this.memory.consumeHeapCharPointer(this.ffi.QTS_Typeof(this.ctx.value,e.value))}getNumber(e){return this.runtime.assertOwned(e),this.ffi.QTS_GetFloat64(this.ctx.value,e.value)}getString(e){return this.runtime.assertOwned(e),this.memory.consumeJSCharPointer(this.ffi.QTS_GetString(this.ctx.value,e.value))}getSymbol(e){this.runtime.assertOwned(e);let r=this.memory.consumeJSCharPointer(this.ffi.QTS_GetSymbolDescriptionOrKey(this.ctx.value,e.value));return this.ffi.QTS_IsGlobalSymbol(this.ctx.value,e.value)?Symbol.for(r):Symbol(r)}getBigInt(e){this.runtime.assertOwned(e);let r=this.getString(e);return BigInt(r)}getArrayBuffer(e){this.runtime.assertOwned(e);let r=this.ffi.QTS_GetArrayBufferLength(this.ctx.value,e.value),n=this.ffi.QTS_GetArrayBuffer(this.ctx.value,e.value);if(!n)throw new Error("Couldn't allocate memory to get ArrayBuffer");return new d(this.module.HEAPU8.subarray(n,n+r),void 0,()=>this.module._free(n))}resolvePromise(e){this.runtime.assertOwned(e);let r=y.withScope(n=>{let i=n.manage(this.getProp(this.global,"Promise")),s=n.manage(this.getProp(i,"resolve"));return this.callFunction(s,i,e)});return r.error?Promise.resolve(r):new Promise(n=>{y.withScope(i=>{let s=i.manage(this.newFunction("resolve",p=>{n({value:p&&p.dup()})})),u=i.manage(this.newFunction("reject",p=>{n({error:p&&p.dup()})})),a=i.manage(r.value),l=i.manage(this.getProp(a,"then"));this.unwrapResult(this.callFunction(l,a,s,u)).dispose()})})}getProp(e,r){this.runtime.assertOwned(e);let n=this.borrowPropertyKey(r).consume(s=>this.ffi.QTS_GetProp(this.ctx.value,e.value,s.value));return this.memory.heapValueHandle(n)}setProp(e,r,n){this.runtime.assertOwned(e),this.borrowPropertyKey(r).consume(i=>this.ffi.QTS_SetProp(this.ctx.value,e.value,i.value,n.value))}defineProp(e,r,n){this.runtime.assertOwned(e),y.withScope(i=>{let s=i.manage(this.borrowPropertyKey(r)),u=n.value||this.undefined,a=!!n.configurable,l=!!n.enumerable,p=!!n.value,M=n.get?i.manage(this.newFunction(n.get.name,n.get)):this.undefined,m=n.set?i.manage(this.newFunction(n.set.name,n.set)):this.undefined;this.ffi.QTS_DefineProp(this.ctx.value,e.value,s.value,u.value,M.value,m.value,a,l,p)})}callFunction(e,r,...n){this.runtime.assertOwned(e);let i=this.memory.toPointerArray(n).consume(u=>this.ffi.QTS_Call(this.ctx.value,e.value,r.value,n.length,u.value)),s=this.ffi.QTS_ResolveException(this.ctx.value,i);return s?(this.ffi.QTS_FreeValuePointer(this.ctx.value,i),{error:this.memory.heapValueHandle(s)}):{value:this.memory.heapValueHandle(i)}}evalCode(e,r="eval.js",n){let i=n===void 0?1:0,s=K(n),u=this.memory.newHeapCharPointer(e).consume(l=>this.ffi.QTS_Eval(this.ctx.value,l.value,r,i,s)),a=this.ffi.QTS_ResolveException(this.ctx.value,u);return a?(this.ffi.QTS_FreeValuePointer(this.ctx.value,u),{error:this.memory.heapValueHandle(a)}):{value:this.memory.heapValueHandle(u)}}throw(e){return this.errorToHandle(e).consume(r=>this.ffi.QTS_Throw(this.ctx.value,r.value))}borrowPropertyKey(e){return typeof e=="number"?this.newNumber(e):typeof e=="string"?this.newString(e):new k(e.value,this.runtime)}getMemory(e){if(e===this.rt.value)return this.memory;throw new Error("Private API. Cannot get memory from a different runtime")}dump(e){this.runtime.assertOwned(e);let r=this.typeof(e);if(r==="string")return this.getString(e);if(r==="number")return this.getNumber(e);if(r==="bigint")return this.getBigInt(e);if(r==="undefined")return;if(r==="symbol")return this.getSymbol(e);let n=this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value,e.value));try{return JSON.parse(n)}catch{return n}}unwrapResult(e){if(e.error){let r="context"in e.error?e.error.context:this,n=e.error.consume(i=>this.dump(i));if(n&&typeof n=="object"&&typeof n.message=="string"){let{message:i,name:s,stack:u}=n,a=new F(""),l=a.stack;throw typeof s=="string"&&(a.name=n.name),typeof u=="string"&&(a.stack=`${s}: ${i} | ||
${n.stack}Host: ${l}`),Object.assign(a,{cause:n,context:r,message:i}),a}throw new F(n,r)}return e.value}getFunction(e){let r=e>>8,n=this.fnMaps.get(r);if(n)return n.get(e)}setFunction(e,r){let n=e>>8,i=this.fnMaps.get(n);return i||(i=new Map,this.fnMaps.set(n,i)),i.set(e,r)}errorToHandle(e){return e instanceof d?e:this.newError(e)}encodeBinaryJSON(e){let r=this.ffi.QTS_bjson_encode(this.ctx.value,e.value);return this.memory.heapValueHandle(r)}decodeBinaryJSON(e){let r=this.ffi.QTS_bjson_decode(this.ctx.value,e.value);return this.memory.heapValueHandle(r)}}});var H,X=J(()=>{"use strict";ce();q();C();v();b();pe();A();H=class extends w{constructor(e){super();this.scope=new y;this.contextMap=new Map;this.cToHostCallbacks={shouldInterrupt:e=>{if(e!==this.rt.value)throw new Error("QuickJSContext instance received C -> JS interrupt with mismatched rt");let r=this.interruptHandler;if(!r)throw new Error("QuickJSContext had no interrupt handler");return r(this)?1:0},loadModuleSource:ue(this,function*(e,r,n,i){let s=this.moduleLoader;if(!s)throw new Error("Runtime has no module loader");if(r!==this.rt.value)throw new Error("Runtime pointer mismatch");let u=this.contextMap.get(n)??this.newContext({contextPointer:n});try{let a=yield*e(s(i,u));if(typeof a=="object"&&"error"in a&&a.error)throw f("cToHostLoadModule: loader returned error",a.error),a.error;let l=typeof a=="string"?a:"value"in a?a.value:a;return this.memory.newHeapCharPointer(l).value}catch(a){return f("cToHostLoadModule: caught error",a),u.throw(a),0}}),normalizeModule:ue(this,function*(e,r,n,i,s){let u=this.moduleNormalizer;if(!u)throw new Error("Runtime has no module normalizer");if(r!==this.rt.value)throw new Error("Runtime pointer mismatch");let a=this.contextMap.get(n)??this.newContext({contextPointer:n});try{let l=yield*e(u(i,s,a));if(typeof l=="object"&&"error"in l&&l.error)throw f("cToHostNormalizeModule: normalizer returned error",l.error),l.error;let p=typeof l=="string"?l:l.value;return a.getMemory(this.rt.value).newHeapCharPointer(p).value}catch(l){return f("normalizeModule: caught error",l),a.throw(l),0}})};e.ownedLifetimes?.forEach(r=>this.scope.manage(r)),this.module=e.module,this.memory=new _(this.module),this.ffi=e.ffi,this.rt=e.rt,this.callbacks=e.callbacks,this.scope.manage(this.rt),this.callbacks.setRuntimeCallbacks(this.rt.value,this.cToHostCallbacks),this.executePendingJobs=this.executePendingJobs.bind(this)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}newContext(e={}){let r=$(e.intrinsics),n=new d(e.contextPointer||this.ffi.QTS_NewContext(this.rt.value,r),void 0,s=>{this.contextMap.delete(s),this.callbacks.deleteContext(s),this.ffi.QTS_FreeContext(s)}),i=new P({module:this.module,ctx:n,ffi:this.ffi,rt:this.rt,ownedLifetimes:e.ownedLifetimes,runtime:this,callbacks:this.callbacks});return this.contextMap.set(n.value,i),i}setModuleLoader(e,r){this.moduleLoader=e,this.moduleNormalizer=r,this.ffi.QTS_RuntimeEnableModuleLoader(this.rt.value,this.moduleNormalizer?1:0)}removeModuleLoader(){this.moduleLoader=void 0,this.ffi.QTS_RuntimeDisableModuleLoader(this.rt.value)}hasPendingJob(){return!!this.ffi.QTS_IsJobPending(this.rt.value)}setInterruptHandler(e){let r=this.interruptHandler;this.interruptHandler=e,r||this.ffi.QTS_RuntimeEnableInterruptHandler(this.rt.value)}removeInterruptHandler(){this.interruptHandler&&(this.ffi.QTS_RuntimeDisableInterruptHandler(this.rt.value),this.interruptHandler=void 0)}executePendingJobs(e=-1){var l=[];try{let r=ve(l,this.memory.newMutablePointerArray(1));let n=this.ffi.QTS_ExecutePendingJob(this.rt.value,e??-1,r.value.ptr);let i=r.value.typedArray[0];if(i===0)return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value,n),{value:0};let s=this.contextMap.get(i)??this.newContext({contextPointer:i});let u=s.getMemory(this.rt.value).heapValueHandle(n);let a=s.typeof(u);if(a==="number"){let c=s.getNumber(u);return u.dispose(),{value:c}}else return{error:Object.assign(u,{context:s})}}catch(p){var M=p,m=!0}finally{be(l,M,m)}}setMemoryLimit(e){if(e<0&&e!==-1)throw new Error("Cannot set memory limit to negative number. To unset, pass -1");this.ffi.QTS_RuntimeSetMemoryLimit(this.rt.value,e)}computeMemoryUsage(){let e=this.getSystemContext().getMemory(this.rt.value);return e.heapValueHandle(this.ffi.QTS_RuntimeComputeMemoryUsage(this.rt.value,e.ctx.value))}dumpMemoryUsage(){return this.memory.consumeHeapCharPointer(this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value))}setMaxStackSize(e){if(e<0)throw new Error("Cannot set memory limit to negative number. To unset, pass 0.");this.ffi.QTS_RuntimeSetMaxStackSize(this.rt.value,e)}assertOwned(e){if(e.owner&&e.owner.rt!==this.rt)throw new N(`Handle is not owned by this runtime: ${e.owner.rt.value} != ${this.rt.value}`)}getSystemContext(){return this.context||(this.context=this.scope.manage(this.newContext())),this.context}}});var Pe={};W(Pe,{QuickJSModuleCallbacks:()=>Z,QuickJSWASMModule:()=>R,applyBaseRuntimeOptions:()=>ee,applyModuleEvalRuntimeOptions:()=>te});function ee(o,t){t.interruptHandler&&o.setInterruptHandler(t.interruptHandler),t.maxStackSizeBytes!==void 0&&o.setMaxStackSize(t.maxStackSizeBytes),t.memoryLimitBytes!==void 0&&o.setMemoryLimit(t.memoryLimitBytes)}function te(o,t){t.moduleLoader&&o.setModuleLoader(t.moduleLoader),t.shouldInterrupt&&o.setInterruptHandler(t.shouldInterrupt),t.memoryLimitBytes!==void 0&&o.setMemoryLimit(t.memoryLimitBytes),t.maxStackSizeBytes!==void 0&&o.setMaxStackSize(t.maxStackSizeBytes)}var he,Z,R,re=J(()=>{"use strict";C();v();b();X();A();he=class{constructor(t){this.callFunction=t.callFunction,this.shouldInterrupt=t.shouldInterrupt,this.loadModuleSource=t.loadModuleSource,this.normalizeModule=t.normalizeModule}},Z=class{constructor(t){this.contextCallbacks=new Map;this.runtimeCallbacks=new Map;this.suspendedCount=0;this.cToHostCallbacks=new he({callFunction:(t,e,r,n,i,s)=>this.handleAsyncify(t,()=>{try{let u=this.contextCallbacks.get(e);if(!u)throw new Error(`QuickJSContext(ctx = ${e}) not found for C function call "${s}"`);return u.callFunction(e,r,n,i,s)}catch(u){return console.error("[C to host error: returning null]",u),0}}),shouldInterrupt:(t,e)=>this.handleAsyncify(t,()=>{try{let r=this.runtimeCallbacks.get(e);if(!r)throw new Error(`QuickJSRuntime(rt = ${e}) not found for C interrupt`);return r.shouldInterrupt(e)}catch(r){return console.error("[C to host interrupt: returning error]",r),1}}),loadModuleSource:(t,e,r,n)=>this.handleAsyncify(t,()=>{try{let i=this.runtimeCallbacks.get(e);if(!i)throw new Error(`QuickJSRuntime(rt = ${e}) not found for C module loader`);let s=i.loadModuleSource;if(!s)throw new Error(`QuickJSRuntime(rt = ${e}) does not support module loading`);return s(e,r,n)}catch(i){return console.error("[C to host module loader error: returning null]",i),0}}),normalizeModule:(t,e,r,n,i)=>this.handleAsyncify(t,()=>{try{let s=this.runtimeCallbacks.get(e);if(!s)throw new Error(`QuickJSRuntime(rt = ${e}) not found for C module loader`);let u=s.normalizeModule;if(!u)throw new Error(`QuickJSRuntime(rt = ${e}) does not support module loading`);return u(e,r,n,i)}catch(s){return console.error("[C to host module loader error: returning null]",s),0}})});this.module=t,this.module.callbacks=this.cToHostCallbacks}setRuntimeCallbacks(t,e){this.runtimeCallbacks.set(t,e)}deleteRuntime(t){this.runtimeCallbacks.delete(t)}setContextCallbacks(t,e){this.contextCallbacks.set(t,e)}deleteContext(t){this.contextCallbacks.delete(t)}handleAsyncify(t,e){if(t)return t.handleSleep(n=>{try{let i=e();if(!(i instanceof Promise)){f("asyncify.handleSleep: not suspending:",i),n(i);return}if(this.suspended)throw new z(`Already suspended at: ${this.suspended.stack} | ||
Attempted to suspend at:`);this.suspended=new j(`(${this.suspendedCount++})`),f("asyncify.handleSleep: suspending:",this.suspended),i.then(s=>{this.suspended=void 0,f("asyncify.handleSleep: resolved:",s),n(s)},s=>{f("asyncify.handleSleep: rejected:",s),console.error("QuickJS: cannot handle error in suspended function",s),this.suspended=void 0})}catch(i){throw f("asyncify.handleSleep: error:",i),this.suspended=void 0,i}});let r=e();if(r instanceof Promise)throw new Error("Promise return value not supported in non-asyncify context.");return r}};R=class{constructor(t,e){this.module=t,this.ffi=e,this.callbacks=new Z(t)}newRuntime(t={}){let e=new d(this.ffi.QTS_NewRuntime(),void 0,n=>{this.callbacks.deleteRuntime(n),this.ffi.QTS_FreeRuntime(n)}),r=new H({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:e});return ee(r,t),t.moduleLoader&&r.setModuleLoader(t.moduleLoader),r}newContext(t={}){let e=this.newRuntime(),r=e.newContext({...t,ownedLifetimes:Ce(e,t.ownedLifetimes)});return e.context=r,r}evalCode(t,e={}){return y.withScope(r=>{let n=r.manage(this.newContext());te(n.runtime,e);let i=n.evalCode(t,"eval.js");if(e.memoryLimitBytes!==void 0&&n.runtime.setMemoryLimit(-1),i.error)throw n.dump(r.manage(i.error));return n.dump(r.manage(i.value))})}getFFI(){return this.ffi}}});var I,Se=J(()=>{"use strict";q();C();A();I=class extends P{async evalCodeAsync(t,e="eval.js",r){let n=r===void 0?1:0,i=K(r),s=0;try{s=await this.memory.newHeapCharPointer(t).consume(a=>this.ffi.QTS_Eval_MaybeAsync(this.ctx.value,a.value,e,n,i))}catch(a){throw f("QTS_Eval_MaybeAsync threw",a),a}let u=this.ffi.QTS_ResolveException(this.ctx.value,s);return u?(this.ffi.QTS_FreeValuePointer(this.ctx.value,s),{error:this.memory.heapValueHandle(u)}):{value:this.memory.heapValueHandle(s)}}newAsyncifiedFunction(t,e){return this.newFunction(t,e)}}});var B,ye=J(()=>{"use strict";Se();X();A();b();B=class extends H{constructor(t){super(t)}newContext(t={}){let e=$(t.intrinsics),r=new d(this.ffi.QTS_NewContext(this.rt.value,e),void 0,i=>{this.contextMap.delete(i),this.callbacks.deleteContext(i),this.ffi.QTS_FreeContext(i)}),n=new I({module:this.module,ctx:r,ffi:this.ffi,rt:this.rt,ownedLifetimes:[],runtime:this,callbacks:this.callbacks});return this.contextMap.set(r.value,n),n}setModuleLoader(t,e){super.setModuleLoader(t,e)}setMaxStackSize(t){return super.setMaxStackSize(t)}}});var He={};W(He,{QuickJSAsyncWASMModule:()=>G});var G,Je=J(()=>{"use strict";v();b();re();ye();G=class extends R{constructor(e,r){super(e,r);this.ffi=r,this.module=e}newRuntime(e={}){let r=new d(this.ffi.QTS_NewRuntime(),void 0,i=>{this.callbacks.deleteRuntime(i),this.ffi.QTS_FreeRuntime(i)}),n=new B({module:this.module,ffi:this.ffi,rt:r,callbacks:this.callbacks});return ee(n,e),e.moduleLoader&&n.setModuleLoader(e.moduleLoader),n}newContext(e={}){let r=this.newRuntime(),n=e.ownedLifetimes?e.ownedLifetimes.concat([r]):[r],i=r.newContext({...e,ownedLifetimes:n});return r.context=i,i}evalCode(){throw new D("QuickJSWASMModuleAsyncify.evalCode: use evalCodeAsync instead")}evalCodeAsync(e,r){return y.withScopeAsync(async n=>{let i=n.manage(this.newContext());te(i.runtime,r);let s=await i.evalCodeAsync(e,"eval.js");if(r.memoryLimitBytes!==void 0&&i.runtime.setMemoryLimit(-1),s.error)throw i.dump(n.manage(s.error));return i.dump(n.manage(s.value))})}}});var h={};W(h,{DefaultIntrinsics:()=>Me,Lifetime:()=>d,QuickJSAsyncContext:()=>I,QuickJSAsyncRuntime:()=>B,QuickJSAsyncWASMModule:()=>G,QuickJSContext:()=>P,QuickJSDeferredPromise:()=>U,QuickJSRuntime:()=>H,QuickJSWASMModule:()=>R,Scope:()=>y,StaticLifetime:()=>k,TestQuickJSWASMModule:()=>xe,UsingDisposable:()=>w,WeakLifetime:()=>O,debugLog:()=>f,errors:()=>se,isFail:()=>Ne,isSuccess:()=>Be,memoizePromiseFactory:()=>Oe,newQuickJSAsyncWASMModuleFromVariant:()=>Ve,newQuickJSWASMModuleFromVariant:()=>Le,newVariant:()=>_e,shouldInterruptAfterDeadline:()=>De});module.exports=Ee(h);S(h,require("@jitl/quickjs-ffi-types"),module.exports);re();q();X();Je();ye();Se();v();C();async function Le(o){let t=E(await o),[e,r,{QuickJSWASMModule:n}]=await Promise.all([t.importModuleLoader().then(E),t.importFFI(),Promise.resolve().then(()=>(re(),Pe)).then(E)]),i=await e();i.type="sync";let s=new r(i);return new n(i,s)}async function Ve(o){let t=E(await o),[e,r,{QuickJSAsyncWASMModule:n}]=await Promise.all([t.importModuleLoader().then(E),t.importFFI(),Promise.resolve().then(()=>(Je(),He)).then(E)]),i=await e();i.type="async";let s=new r(i);return new n(i,s)}function Oe(o){let t;return()=>t??(t=o())}function E(o){return o&&"default"in o&&o.default?o.default&&"default"in o.default&&o.default.default?o.default.default:o.default:o}function _e(o,t){return{...o,async importModuleLoader(){let r=E(await o.importModuleLoader());return async function(){let i=t.emscriptenModule?{...t.emscriptenModule}:{},s=t.log??((...c)=>f("newVariant moduleLoader:",...c)),u=(c,x)=>(s(...c,x),x),a=c=>typeof c=="function"?c():c;(t.wasmLocation||t.wasmSourceMapLocation||t.locateFile)&&(i.locateFile=(c,x)=>{let Q={fileName:c,relativeTo:x};if(c.endsWith(".wasm")&&t.wasmLocation!==void 0)return u(["locateFile .wasm: provide wasmLocation",Q],t.wasmLocation);if(c.endsWith(".map")){if(t.wasmSourceMapLocation!==void 0)return u(["locateFile .map: provide wasmSourceMapLocation",Q],t.wasmSourceMapLocation);if(t.wasmLocation&&!t.locateFile)return u(["locateFile .map: infer from wasmLocation",Q],t.wasmLocation+".map")}return t.locateFile?u(["locateFile: use provided fn",Q],t.locateFile(c,x)):u(["locateFile: unhandled, passthrough",Q],c)}),t.wasmBinary&&(i.wasmBinary=await a(t.wasmBinary));let l=t.wasmModule,p;l&&(i.instantiateWasm=async(c,x)=>{p??(p=Promise.resolve(a(l)));let Q=await p;if(!Q)throw new V(`options.wasmModule returned ${String(Q)}`);let we=await WebAssembly.instantiate(Q,c);return x(we),we.exports}),i.monitorRunDependencies=c=>{s("monitorRunDependencies:",c)},i.quickjsEmscriptenInit=()=>Ie(s);let M=r(i),m=i.quickjsEmscriptenInit?.(s);if(l&&m?.receiveWasmOffsetConverter&&!m.existingWasmOffsetConverter){let c=await a(t.wasmBinary)??new ArrayBuffer(0);p??(p=Promise.resolve(a(l)));let x=await p;if(!x)throw new V(`options.wasmModule returned ${String(x)}`);m.receiveWasmOffsetConverter(c,x)}if(m?.receiveSourceMapJSON){let c=await a(t.wasmSourceMapData);typeof c=="string"?m.receiveSourceMapJSON(JSON.parse(c)):c?m.receiveSourceMapJSON(c):m.receiveSourceMapJSON({version:3,names:[],sources:[],mappings:""})}return M}}}}function Ie(o){let t="mock called, emscripten module may not be initialized yet";return{mock:!0,removeRunDependency(e){o(`${t}: removeRunDependency called:`,e)},receiveSourceMapJSON(e){o(`${t}: receiveSourceMapJSON called:`,e)},WasmOffsetConverter:void 0,receiveWasmOffsetConverter(e,r){o(`${t}: receiveWasmOffsetConverter called:`,e,r)}}}function Be(o){return!("error"in o)}function Ne(o){return"error"in o}b();function De(o){let t=typeof o=="number"?o:o.getTime();return function(){return Date.now()>t}}v();me();v();b();var xe=class{constructor(t){this.parent=t;this.contexts=new Set;this.runtimes=new Set}newRuntime(t){let e=this.parent.newRuntime({...t,ownedLifetimes:[new d(void 0,void 0,()=>this.runtimes.delete(e)),...t?.ownedLifetimes??[]]});return this.runtimes.add(e),e}newContext(t){let e=this.parent.newContext({...t,ownedLifetimes:[new d(void 0,void 0,()=>this.contexts.delete(e)),...t?.ownedLifetimes??[]]});return this.contexts.add(e),e}evalCode(t,e){return this.parent.evalCode(t,e)}disposeAll(){let t=[...this.contexts,...this.runtimes];this.runtimes.clear(),this.contexts.clear(),t.forEach(e=>{e.alive&&e.dispose()})}assertNoMemoryAllocated(){if(this.getFFI().QTS_RecoverableLeakCheck())throw new T("Leak sanitizer detected un-freed memory");if(this.contexts.size>0)throw new T(`${this.contexts.size} contexts leaked`);if(this.runtimes.size>0)throw new T(`${this.runtimes.size} runtimes leaked`)}getFFI(){return this.parent.getFFI()}};A();C();0&&(module.exports={DefaultIntrinsics,Lifetime,QuickJSAsyncContext,QuickJSAsyncRuntime,QuickJSAsyncWASMModule,QuickJSContext,QuickJSDeferredPromise,QuickJSRuntime,QuickJSWASMModule,Scope,StaticLifetime,TestQuickJSWASMModule,UsingDisposable,WeakLifetime,debugLog,errors,isFail,isSuccess,memoizePromiseFactory,newQuickJSAsyncWASMModuleFromVariant,newQuickJSWASMModuleFromVariant,newVariant,shouldInterruptAfterDeadline,...require("@jitl/quickjs-ffi-types")}); | ||
Lifetime used`):new L("Lifetime not alive")}},k=class extends d{constructor(t,e){super(t,void 0,void 0,e)}get dupable(){return!0}dup(){return this}dispose(){}},O=class extends d{constructor(t,e,r,n){super(t,e,r,n)}dispose(){this._alive=!1}};y=class o extends w{constructor(){super(...arguments);this._disposables=new d(new Set)}static withScope(e){let r=new o,n;try{return e(r)}catch(i){throw n=i,i}finally{de(r,n)}}static withScopeMaybeAsync(e,r){return ve(void 0,function*(n){let i=new o,s;try{return yield*n.of(r.call(e,n,i))}catch(a){throw s=a,a}finally{de(i,s)}})}static async withScopeAsync(e){let r=new o,n;try{return await e(r)}catch(i){throw n=i,i}finally{de(r,n)}}manage(e){return this._disposables.value.add(e),e}get alive(){return this._disposables.alive}dispose(){let e=Array.from(this._disposables.value.values()).reverse();for(let r of e)r.alive&&r.dispose();this._disposables.dispose()}}});var U,me=J(()=>{"use strict";b();U=class extends w{constructor(e){super();this.resolve=e=>{this.resolveHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.resolveHandle,this.context.undefined,e||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())};this.reject=e=>{this.rejectHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.rejectHandle,this.context.undefined,e||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())};this.dispose=()=>{this.handle.alive&&this.handle.dispose(),this.disposeResolvers()};this.context=e.context,this.owner=e.context.runtime,this.handle=e.promiseHandle,this.settled=new Promise(r=>{this.onSettled=r}),this.resolveHandle=e.resolveHandle,this.rejectHandle=e.rejectHandle}get alive(){return this.handle.alive||this.resolveHandle.alive||this.rejectHandle.alive}disposeResolvers(){this.resolveHandle.alive&&this.resolveHandle.dispose(),this.rejectHandle.alive&&this.rejectHandle.dispose()}}});var _,pe=J(()=>{"use strict";b();_=class{constructor(t){this.module=t}toPointerArray(t){let e=new Int32Array(t.map(s=>s.value)),r=e.length*e.BYTES_PER_ELEMENT,n=this.module._malloc(r);return new Uint8Array(this.module.HEAPU8.buffer,n,r).set(new Uint8Array(e.buffer)),new d(n,void 0,s=>this.module._free(s))}newMutablePointerArray(t){let e=new Int32Array(new Array(t).fill(0)),r=e.length*e.BYTES_PER_ELEMENT,n=this.module._malloc(r),i=new Int32Array(this.module.HEAPU8.buffer,n,t);return i.set(e),new d({typedArray:i,ptr:n},void 0,s=>this.module._free(s.ptr))}newHeapCharPointer(t){let e=this.module.lengthBytesUTF8(t)+1,r=this.module._malloc(e);return this.module.stringToUTF8(t,r,e),new d(r,void 0,n=>this.module._free(n))}newHeapBufferPointer(t){let e=t.byteLength,r=this.module._malloc(e);return this.module.HEAPU8.set(t,r),new d({pointer:r,numBytes:e},void 0,n=>this.module._free(n.pointer))}consumeHeapCharPointer(t){let e=this.module.UTF8ToString(t);return this.module._free(t),e}}});function $(o){if(!o)return 0;let t=0;for(let[e,r]of Object.entries(o)){if(!(e in g.IntrinsicsFlags))throw new Y(e);r&&(t|=g.IntrinsicsFlags[e])}return t}function K(o){if(typeof o=="number")return o;if(o===void 0)return 0;let{type:t,strict:e,strip:r,compileOnly:n,backtraceBarrier:i}=o,s=0;return t==="global"&&(s|=g.EvalFlags.JS_EVAL_TYPE_GLOBAL),t==="module"&&(s|=g.EvalFlags.JS_EVAL_TYPE_MODULE),e&&(s|=g.EvalFlags.JS_EVAL_FLAG_STRICT),r&&(s|=g.EvalFlags.JS_EVAL_FLAG_STRIP),n&&(s|=g.EvalFlags.JS_EVAL_FLAG_COMPILE_ONLY),i&&(s|=g.EvalFlags.JS_EVAL_FLAG_BACKTRACE_BARRIER),s}function ge(...o){let t=[];for(let e of o)e!==void 0&&(t=t.concat(e));return t}var g,Xe,be,T=J(()=>{"use strict";g=require("@jitl/quickjs-ffi-types");v();Xe=Symbol("Unstable"),be=Object.freeze({BaseObjects:!0,Date:!0,Eval:!0,StringNormalize:!0,RegExp:!0,JSON:!0,Proxy:!0,MapSet:!0,TypedArrays:!0,Promise:!0})});var fe,C,q=J(()=>{"use strict";M();me();v();b();pe();T();fe=class extends _{constructor(e){super(e.module);this.scope=new y;this.copyJSValue=e=>this.ffi.QTS_DupValuePointer(this.ctx.value,e);this.freeJSValue=e=>{this.ffi.QTS_FreeValuePointer(this.ctx.value,e)};e.ownedLifetimes?.forEach(r=>this.scope.manage(r)),this.owner=e.owner,this.module=e.module,this.ffi=e.ffi,this.rt=e.rt,this.ctx=this.scope.manage(e.ctx)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}[Symbol.dispose](){return this.dispose()}manage(e){return this.scope.manage(e)}consumeJSCharPointer(e){let r=this.module.UTF8ToString(e);return this.ffi.QTS_FreeCString(this.ctx.value,e),r}heapValueHandle(e){return new d(e,this.copyJSValue,this.freeJSValue,this.owner)}},C=class extends w{constructor(e){super();this._undefined=void 0;this._null=void 0;this._false=void 0;this._true=void 0;this._global=void 0;this._BigInt=void 0;this.fnNextId=-32768;this.fnMaps=new Map;this.cToHostCallbacks={callFunction:(e,r,n,i,s)=>{if(e!==this.ctx.value)throw new Error("QuickJSContext instance received C -> JS call with mismatched ctx");let a=this.getFunction(s);if(!a)throw new Error(`QuickJSContext had no callback with id ${s}`);return y.withScopeMaybeAsync(this,function*(u,l){let h=l.manage(new O(r,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime)),E=new Array(n);for(let m=0;m<n;m++){let c=this.ffi.QTS_ArgvGetJSValueConstPointer(i,m);E[m]=l.manage(new O(c,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime))}try{let m=yield*u(a.apply(h,E));if(m){if("error"in m&&m.error)throw p("throw error",m.error),m.error;let c=l.manage(m instanceof d?m:m.value);return this.ffi.QTS_DupValuePointer(this.ctx.value,c.value)}return 0}catch(m){return this.errorToHandle(m).consume(c=>this.ffi.QTS_Throw(this.ctx.value,c.value))}})}};this.runtime=e.runtime,this.module=e.module,this.ffi=e.ffi,this.rt=e.rt,this.ctx=e.ctx,this.memory=new fe({...e,owner:this.runtime}),e.callbacks.setContextCallbacks(this.ctx.value,this.cToHostCallbacks),this.dump=this.dump.bind(this),this.getString=this.getString.bind(this),this.getNumber=this.getNumber.bind(this),this.resolvePromise=this.resolvePromise.bind(this)}get alive(){return this.memory.alive}dispose(){this.memory.dispose()}get undefined(){if(this._undefined)return this._undefined;let e=this.ffi.QTS_GetUndefined();return this._undefined=new k(e)}get null(){if(this._null)return this._null;let e=this.ffi.QTS_GetNull();return this._null=new k(e)}get true(){if(this._true)return this._true;let e=this.ffi.QTS_GetTrue();return this._true=new k(e)}get false(){if(this._false)return this._false;let e=this.ffi.QTS_GetFalse();return this._false=new k(e)}get global(){if(this._global)return this._global;let e=this.ffi.QTS_GetGlobalObject(this.ctx.value);return this.memory.manage(this.memory.heapValueHandle(e)),this._global=new k(e,this.runtime),this._global}newNumber(e){return this.memory.heapValueHandle(this.ffi.QTS_NewFloat64(this.ctx.value,e))}newString(e){let r=this.memory.newHeapCharPointer(e).consume(n=>this.ffi.QTS_NewString(this.ctx.value,n.value));return this.memory.heapValueHandle(r)}newUniqueSymbol(e){let r=(typeof e=="symbol"?e.description:e)??"",n=this.memory.newHeapCharPointer(r).consume(i=>this.ffi.QTS_NewSymbol(this.ctx.value,i.value,0));return this.memory.heapValueHandle(n)}newSymbolFor(e){let r=(typeof e=="symbol"?e.description:e)??"",n=this.memory.newHeapCharPointer(r).consume(i=>this.ffi.QTS_NewSymbol(this.ctx.value,i.value,1));return this.memory.heapValueHandle(n)}newBigInt(e){if(!this._BigInt){let i=this.getProp(this.global,"BigInt");this.memory.manage(i),this._BigInt=new k(i.value,this.runtime)}let r=this._BigInt,n=String(e);return this.newString(n).consume(i=>this.unwrapResult(this.callFunction(r,this.undefined,i)))}newObject(e){e&&this.runtime.assertOwned(e);let r=e?this.ffi.QTS_NewObjectProto(this.ctx.value,e.value):this.ffi.QTS_NewObject(this.ctx.value);return this.memory.heapValueHandle(r)}newArray(){let e=this.ffi.QTS_NewArray(this.ctx.value);return this.memory.heapValueHandle(e)}newArrayBuffer(e){let r=new Uint8Array(e),n=this.memory.newHeapBufferPointer(r),i=this.ffi.QTS_NewArrayBuffer(this.ctx.value,n.value.pointer,r.length);return this.memory.heapValueHandle(i)}newPromise(e){let r=y.withScope(n=>{let i=n.manage(this.memory.newMutablePointerArray(2)),s=this.ffi.QTS_NewPromiseCapability(this.ctx.value,i.value.ptr),a=this.memory.heapValueHandle(s),[u,l]=Array.from(i.value.typedArray).map(h=>this.memory.heapValueHandle(h));return new U({context:this,promiseHandle:a,resolveHandle:u,rejectHandle:l})});return e&&typeof e=="function"&&(e=new Promise(e)),e&&Promise.resolve(e).then(r.resolve,n=>n instanceof d?r.reject(n):this.newError(n).consume(r.reject)),r}newFunction(e,r){let n=++this.fnNextId;return this.setFunction(n,r),this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value,n,e))}newError(e){let r=this.memory.heapValueHandle(this.ffi.QTS_NewError(this.ctx.value));return e&&typeof e=="object"?(e.name!==void 0&&this.newString(e.name).consume(n=>this.setProp(r,"name",n)),e.message!==void 0&&this.newString(e.message).consume(n=>this.setProp(r,"message",n))):typeof e=="string"?this.newString(e).consume(n=>this.setProp(r,"message",n)):e!==void 0&&this.newString(String(e)).consume(n=>this.setProp(r,"message",n)),r}typeof(e){return this.runtime.assertOwned(e),this.memory.consumeHeapCharPointer(this.ffi.QTS_Typeof(this.ctx.value,e.value))}getNumber(e){return this.runtime.assertOwned(e),this.ffi.QTS_GetFloat64(this.ctx.value,e.value)}getString(e){return this.runtime.assertOwned(e),this.memory.consumeJSCharPointer(this.ffi.QTS_GetString(this.ctx.value,e.value))}getSymbol(e){this.runtime.assertOwned(e);let r=this.memory.consumeJSCharPointer(this.ffi.QTS_GetSymbolDescriptionOrKey(this.ctx.value,e.value));return this.ffi.QTS_IsGlobalSymbol(this.ctx.value,e.value)?Symbol.for(r):Symbol(r)}getBigInt(e){this.runtime.assertOwned(e);let r=this.getString(e);return BigInt(r)}getArrayBuffer(e){this.runtime.assertOwned(e);let r=this.ffi.QTS_GetArrayBufferLength(this.ctx.value,e.value),n=this.ffi.QTS_GetArrayBuffer(this.ctx.value,e.value);if(!n)throw new Error("Couldn't allocate memory to get ArrayBuffer");return new d(this.module.HEAPU8.subarray(n,n+r),void 0,()=>this.module._free(n))}resolvePromise(e){this.runtime.assertOwned(e);let r=y.withScope(n=>{let i=n.manage(this.getProp(this.global,"Promise")),s=n.manage(this.getProp(i,"resolve"));return this.callFunction(s,i,e)});return r.error?Promise.resolve(r):new Promise(n=>{y.withScope(i=>{let s=i.manage(this.newFunction("resolve",h=>{n({value:h&&h.dup()})})),a=i.manage(this.newFunction("reject",h=>{n({error:h&&h.dup()})})),u=i.manage(r.value),l=i.manage(this.getProp(u,"then"));this.unwrapResult(this.callFunction(l,u,s,a)).dispose()})})}getProp(e,r){this.runtime.assertOwned(e);let n=this.borrowPropertyKey(r).consume(s=>this.ffi.QTS_GetProp(this.ctx.value,e.value,s.value));return this.memory.heapValueHandle(n)}setProp(e,r,n){this.runtime.assertOwned(e),this.borrowPropertyKey(r).consume(i=>this.ffi.QTS_SetProp(this.ctx.value,e.value,i.value,n.value))}defineProp(e,r,n){this.runtime.assertOwned(e),y.withScope(i=>{let s=i.manage(this.borrowPropertyKey(r)),a=n.value||this.undefined,u=!!n.configurable,l=!!n.enumerable,h=!!n.value,E=n.get?i.manage(this.newFunction(n.get.name,n.get)):this.undefined,m=n.set?i.manage(this.newFunction(n.set.name,n.set)):this.undefined;this.ffi.QTS_DefineProp(this.ctx.value,e.value,s.value,a.value,E.value,m.value,u,l,h)})}callFunction(e,r,...n){this.runtime.assertOwned(e);let i=this.memory.toPointerArray(n).consume(a=>this.ffi.QTS_Call(this.ctx.value,e.value,r.value,n.length,a.value)),s=this.ffi.QTS_ResolveException(this.ctx.value,i);return s?(this.ffi.QTS_FreeValuePointer(this.ctx.value,i),{error:this.memory.heapValueHandle(s)}):{value:this.memory.heapValueHandle(i)}}evalCode(e,r="eval.js",n){let i=n===void 0?1:0,s=K(n),a=this.memory.newHeapCharPointer(e).consume(l=>this.ffi.QTS_Eval(this.ctx.value,l.value,r,i,s)),u=this.ffi.QTS_ResolveException(this.ctx.value,a);return u?(this.ffi.QTS_FreeValuePointer(this.ctx.value,a),{error:this.memory.heapValueHandle(u)}):{value:this.memory.heapValueHandle(a)}}throw(e){return this.errorToHandle(e).consume(r=>this.ffi.QTS_Throw(this.ctx.value,r.value))}borrowPropertyKey(e){return typeof e=="number"?this.newNumber(e):typeof e=="string"?this.newString(e):new k(e.value,this.runtime)}getMemory(e){if(e===this.rt.value)return this.memory;throw new Error("Private API. Cannot get memory from a different runtime")}dump(e){this.runtime.assertOwned(e);let r=this.typeof(e);if(r==="string")return this.getString(e);if(r==="number")return this.getNumber(e);if(r==="bigint")return this.getBigInt(e);if(r==="undefined")return;if(r==="symbol")return this.getSymbol(e);let n=this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value,e.value));try{return JSON.parse(n)}catch{return n}}unwrapResult(e){if(e.error){let r="context"in e.error?e.error.context:this,n=e.error.consume(i=>this.dump(i));if(n&&typeof n=="object"&&typeof n.message=="string"){let{message:i,name:s,stack:a}=n,u=new F(""),l=u.stack;throw typeof s=="string"&&(u.name=n.name),typeof a=="string"&&(u.stack=`${s}: ${i} | ||
${n.stack}Host: ${l}`),Object.assign(u,{cause:n,context:r,message:i}),u}throw new F(n,r)}return e.value}getFunction(e){let r=e>>8,n=this.fnMaps.get(r);if(n)return n.get(e)}setFunction(e,r){let n=e>>8,i=this.fnMaps.get(n);return i||(i=new Map,this.fnMaps.set(n,i)),i.set(e,r)}errorToHandle(e){return e instanceof d?e:this.newError(e)}encodeBinaryJSON(e){let r=this.ffi.QTS_bjson_encode(this.ctx.value,e.value);return this.memory.heapValueHandle(r)}decodeBinaryJSON(e){let r=this.ffi.QTS_bjson_decode(this.ctx.value,e.value);return this.memory.heapValueHandle(r)}}});var P,X=J(()=>{"use strict";ce();q();M();v();b();pe();T();P=class extends w{constructor(e){super();this.scope=new y;this.contextMap=new Map;this.cToHostCallbacks={shouldInterrupt:e=>{if(e!==this.rt.value)throw new Error("QuickJSContext instance received C -> JS interrupt with mismatched rt");let r=this.interruptHandler;if(!r)throw new Error("QuickJSContext had no interrupt handler");return r(this)?1:0},loadModuleSource:ue(this,function*(e,r,n,i){let s=this.moduleLoader;if(!s)throw new Error("Runtime has no module loader");if(r!==this.rt.value)throw new Error("Runtime pointer mismatch");let a=this.contextMap.get(n)??this.newContext({contextPointer:n});try{let u=yield*e(s(i,a));if(typeof u=="object"&&"error"in u&&u.error)throw p("cToHostLoadModule: loader returned error",u.error),u.error;let l=typeof u=="string"?u:"value"in u?u.value:u;return this.memory.newHeapCharPointer(l).value}catch(u){return p("cToHostLoadModule: caught error",u),a.throw(u),0}}),normalizeModule:ue(this,function*(e,r,n,i,s){let a=this.moduleNormalizer;if(!a)throw new Error("Runtime has no module normalizer");if(r!==this.rt.value)throw new Error("Runtime pointer mismatch");let u=this.contextMap.get(n)??this.newContext({contextPointer:n});try{let l=yield*e(a(i,s,u));if(typeof l=="object"&&"error"in l&&l.error)throw p("cToHostNormalizeModule: normalizer returned error",l.error),l.error;let h=typeof l=="string"?l:l.value;return u.getMemory(this.rt.value).newHeapCharPointer(h).value}catch(l){return p("normalizeModule: caught error",l),u.throw(l),0}})};e.ownedLifetimes?.forEach(r=>this.scope.manage(r)),this.module=e.module,this.memory=new _(this.module),this.ffi=e.ffi,this.rt=e.rt,this.callbacks=e.callbacks,this.scope.manage(this.rt),this.callbacks.setRuntimeCallbacks(this.rt.value,this.cToHostCallbacks),this.executePendingJobs=this.executePendingJobs.bind(this)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}newContext(e={}){let r=$(e.intrinsics),n=new d(e.contextPointer||this.ffi.QTS_NewContext(this.rt.value,r),void 0,s=>{this.contextMap.delete(s),this.callbacks.deleteContext(s),this.ffi.QTS_FreeContext(s)}),i=new C({module:this.module,ctx:n,ffi:this.ffi,rt:this.rt,ownedLifetimes:e.ownedLifetimes,runtime:this,callbacks:this.callbacks});return this.contextMap.set(n.value,i),i}setModuleLoader(e,r){this.moduleLoader=e,this.moduleNormalizer=r,this.ffi.QTS_RuntimeEnableModuleLoader(this.rt.value,this.moduleNormalizer?1:0)}removeModuleLoader(){this.moduleLoader=void 0,this.ffi.QTS_RuntimeDisableModuleLoader(this.rt.value)}hasPendingJob(){return!!this.ffi.QTS_IsJobPending(this.rt.value)}setInterruptHandler(e){let r=this.interruptHandler;this.interruptHandler=e,r||this.ffi.QTS_RuntimeEnableInterruptHandler(this.rt.value)}removeInterruptHandler(){this.interruptHandler&&(this.ffi.QTS_RuntimeDisableInterruptHandler(this.rt.value),this.interruptHandler=void 0)}executePendingJobs(e=-1){let r=this.memory.newMutablePointerArray(1),n=this.ffi.QTS_ExecutePendingJob(this.rt.value,e??-1,r.value.ptr),i=r.consume(l=>l.value.typedArray[0]);if(i===0)return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value,n),{value:0};let s=this.contextMap.get(i)??this.newContext({contextPointer:i}),a=s.getMemory(this.rt.value).heapValueHandle(n);if(s.typeof(a)==="number"){let l=s.getNumber(a);return a.dispose(),{value:l}}else return{error:Object.assign(a,{context:s})}}setMemoryLimit(e){if(e<0&&e!==-1)throw new Error("Cannot set memory limit to negative number. To unset, pass -1");this.ffi.QTS_RuntimeSetMemoryLimit(this.rt.value,e)}computeMemoryUsage(){let e=this.getSystemContext().getMemory(this.rt.value);return e.heapValueHandle(this.ffi.QTS_RuntimeComputeMemoryUsage(this.rt.value,e.ctx.value))}dumpMemoryUsage(){return this.memory.consumeHeapCharPointer(this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value))}setMaxStackSize(e){if(e<0)throw new Error("Cannot set memory limit to negative number. To unset, pass 0.");this.ffi.QTS_RuntimeSetMaxStackSize(this.rt.value,e)}assertOwned(e){if(e.owner&&e.owner.rt!==this.rt)throw new N(`Handle is not owned by this runtime: ${e.owner.rt.value} != ${this.rt.value}`)}getSystemContext(){return this.context||(this.context=this.scope.manage(this.newContext())),this.context}}});var Qe={};W(Qe,{QuickJSModuleCallbacks:()=>Z,QuickJSWASMModule:()=>A,applyBaseRuntimeOptions:()=>ee,applyModuleEvalRuntimeOptions:()=>te});function ee(o,t){t.interruptHandler&&o.setInterruptHandler(t.interruptHandler),t.maxStackSizeBytes!==void 0&&o.setMaxStackSize(t.maxStackSizeBytes),t.memoryLimitBytes!==void 0&&o.setMemoryLimit(t.memoryLimitBytes)}function te(o,t){t.moduleLoader&&o.setModuleLoader(t.moduleLoader),t.shouldInterrupt&&o.setInterruptHandler(t.shouldInterrupt),t.memoryLimitBytes!==void 0&&o.setMemoryLimit(t.memoryLimitBytes),t.maxStackSizeBytes!==void 0&&o.setMaxStackSize(t.maxStackSizeBytes)}var he,Z,A,re=J(()=>{"use strict";M();v();b();X();T();he=class{constructor(t){this.callFunction=t.callFunction,this.shouldInterrupt=t.shouldInterrupt,this.loadModuleSource=t.loadModuleSource,this.normalizeModule=t.normalizeModule}},Z=class{constructor(t){this.contextCallbacks=new Map;this.runtimeCallbacks=new Map;this.suspendedCount=0;this.cToHostCallbacks=new he({callFunction:(t,e,r,n,i,s)=>this.handleAsyncify(t,()=>{try{let a=this.contextCallbacks.get(e);if(!a)throw new Error(`QuickJSContext(ctx = ${e}) not found for C function call "${s}"`);return a.callFunction(e,r,n,i,s)}catch(a){return console.error("[C to host error: returning null]",a),0}}),shouldInterrupt:(t,e)=>this.handleAsyncify(t,()=>{try{let r=this.runtimeCallbacks.get(e);if(!r)throw new Error(`QuickJSRuntime(rt = ${e}) not found for C interrupt`);return r.shouldInterrupt(e)}catch(r){return console.error("[C to host interrupt: returning error]",r),1}}),loadModuleSource:(t,e,r,n)=>this.handleAsyncify(t,()=>{try{let i=this.runtimeCallbacks.get(e);if(!i)throw new Error(`QuickJSRuntime(rt = ${e}) not found for C module loader`);let s=i.loadModuleSource;if(!s)throw new Error(`QuickJSRuntime(rt = ${e}) does not support module loading`);return s(e,r,n)}catch(i){return console.error("[C to host module loader error: returning null]",i),0}}),normalizeModule:(t,e,r,n,i)=>this.handleAsyncify(t,()=>{try{let s=this.runtimeCallbacks.get(e);if(!s)throw new Error(`QuickJSRuntime(rt = ${e}) not found for C module loader`);let a=s.normalizeModule;if(!a)throw new Error(`QuickJSRuntime(rt = ${e}) does not support module loading`);return a(e,r,n,i)}catch(s){return console.error("[C to host module loader error: returning null]",s),0}})});this.module=t,this.module.callbacks=this.cToHostCallbacks}setRuntimeCallbacks(t,e){this.runtimeCallbacks.set(t,e)}deleteRuntime(t){this.runtimeCallbacks.delete(t)}setContextCallbacks(t,e){this.contextCallbacks.set(t,e)}deleteContext(t){this.contextCallbacks.delete(t)}handleAsyncify(t,e){if(t)return t.handleSleep(n=>{try{let i=e();if(!(i instanceof Promise)){p("asyncify.handleSleep: not suspending:",i),n(i);return}if(this.suspended)throw new z(`Already suspended at: ${this.suspended.stack} | ||
Attempted to suspend at:`);this.suspended=new j(`(${this.suspendedCount++})`),p("asyncify.handleSleep: suspending:",this.suspended),i.then(s=>{this.suspended=void 0,p("asyncify.handleSleep: resolved:",s),n(s)},s=>{p("asyncify.handleSleep: rejected:",s),console.error("QuickJS: cannot handle error in suspended function",s),this.suspended=void 0})}catch(i){throw p("asyncify.handleSleep: error:",i),this.suspended=void 0,i}});let r=e();if(r instanceof Promise)throw new Error("Promise return value not supported in non-asyncify context.");return r}};A=class{constructor(t,e){this.module=t,this.ffi=e,this.callbacks=new Z(t)}newRuntime(t={}){let e=new d(this.ffi.QTS_NewRuntime(),void 0,n=>{this.callbacks.deleteRuntime(n),this.ffi.QTS_FreeRuntime(n)}),r=new P({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:e});return ee(r,t),t.moduleLoader&&r.setModuleLoader(t.moduleLoader),r}newContext(t={}){let e=this.newRuntime(),r=e.newContext({...t,ownedLifetimes:ge(e,t.ownedLifetimes)});return e.context=r,r}evalCode(t,e={}){return y.withScope(r=>{let n=r.manage(this.newContext());te(n.runtime,e);let i=n.evalCode(t,"eval.js");if(e.memoryLimitBytes!==void 0&&n.runtime.setMemoryLimit(-1),i.error)throw n.dump(r.manage(i.error));return n.dump(r.manage(i.value))})}getFFI(){return this.ffi}}});var I,Se=J(()=>{"use strict";q();M();T();I=class extends C{async evalCodeAsync(t,e="eval.js",r){let n=r===void 0?1:0,i=K(r),s=0;try{s=await this.memory.newHeapCharPointer(t).consume(u=>this.ffi.QTS_Eval_MaybeAsync(this.ctx.value,u.value,e,n,i))}catch(u){throw p("QTS_Eval_MaybeAsync threw",u),u}let a=this.ffi.QTS_ResolveException(this.ctx.value,s);return a?(this.ffi.QTS_FreeValuePointer(this.ctx.value,s),{error:this.memory.heapValueHandle(a)}):{value:this.memory.heapValueHandle(s)}}newAsyncifiedFunction(t,e){return this.newFunction(t,e)}}});var B,ye=J(()=>{"use strict";Se();X();T();b();B=class extends P{constructor(t){super(t)}newContext(t={}){let e=$(t.intrinsics),r=new d(this.ffi.QTS_NewContext(this.rt.value,e),void 0,i=>{this.contextMap.delete(i),this.callbacks.deleteContext(i),this.ffi.QTS_FreeContext(i)}),n=new I({module:this.module,ctx:r,ffi:this.ffi,rt:this.rt,ownedLifetimes:[],runtime:this,callbacks:this.callbacks});return this.contextMap.set(r.value,n),n}setModuleLoader(t,e){super.setModuleLoader(t,e)}setMaxStackSize(t){return super.setMaxStackSize(t)}}});var Me={};W(Me,{QuickJSAsyncWASMModule:()=>G});var G,Je=J(()=>{"use strict";v();b();re();ye();G=class extends A{constructor(e,r){super(e,r);this.ffi=r,this.module=e}newRuntime(e={}){let r=new d(this.ffi.QTS_NewRuntime(),void 0,i=>{this.callbacks.deleteRuntime(i),this.ffi.QTS_FreeRuntime(i)}),n=new B({module:this.module,ffi:this.ffi,rt:r,callbacks:this.callbacks});return ee(n,e),e.moduleLoader&&n.setModuleLoader(e.moduleLoader),n}newContext(e={}){let r=this.newRuntime(),n=e.ownedLifetimes?e.ownedLifetimes.concat([r]):[r],i=r.newContext({...e,ownedLifetimes:n});return r.context=i,i}evalCode(){throw new D("QuickJSWASMModuleAsyncify.evalCode: use evalCodeAsync instead")}evalCodeAsync(e,r){return y.withScopeAsync(async n=>{let i=n.manage(this.newContext());te(i.runtime,r);let s=await i.evalCodeAsync(e,"eval.js");if(r.memoryLimitBytes!==void 0&&i.runtime.setMemoryLimit(-1),s.error)throw i.dump(n.manage(s.error));return i.dump(n.manage(s.value))})}}});var f={};W(f,{DefaultIntrinsics:()=>be,Lifetime:()=>d,QuickJSAsyncContext:()=>I,QuickJSAsyncRuntime:()=>B,QuickJSAsyncWASMModule:()=>G,QuickJSContext:()=>C,QuickJSDeferredPromise:()=>U,QuickJSRuntime:()=>P,QuickJSWASMModule:()=>A,Scope:()=>y,StaticLifetime:()=>k,TestQuickJSWASMModule:()=>xe,UsingDisposable:()=>w,WeakLifetime:()=>O,debugLog:()=>p,errors:()=>se,isFail:()=>_e,isSuccess:()=>Oe,memoizePromiseFactory:()=>Fe,newQuickJSAsyncWASMModuleFromVariant:()=>Ee,newQuickJSWASMModuleFromVariant:()=>Re,newVariant:()=>Le,shouldInterruptAfterDeadline:()=>Ie});module.exports=Te(f);S(f,require("@jitl/quickjs-ffi-types"),module.exports);re();q();X();Je();ye();Se();v();M();async function Re(o){let t=R(await o),[e,r,{QuickJSWASMModule:n}]=await Promise.all([t.importModuleLoader().then(R),t.importFFI(),Promise.resolve().then(()=>(re(),Qe)).then(R)]),i=await e();i.type="sync";let s=new r(i);return new n(i,s)}async function Ee(o){let t=R(await o),[e,r,{QuickJSAsyncWASMModule:n}]=await Promise.all([t.importModuleLoader().then(R),t.importFFI(),Promise.resolve().then(()=>(Je(),Me)).then(R)]),i=await e();i.type="async";let s=new r(i);return new n(i,s)}function Fe(o){let t;return()=>t??(t=o())}function R(o){return o&&"default"in o&&o.default?o.default&&"default"in o.default&&o.default.default?o.default.default:o.default:o}function Le(o,t){return{...o,async importModuleLoader(){let r=R(await o.importModuleLoader());return async function(){let i=t.emscriptenModule?{...t.emscriptenModule}:{},s=t.log??((...c)=>p("newVariant moduleLoader:",...c)),a=(c,x)=>(s(...c,x),x),u=c=>typeof c=="function"?c():c;(t.wasmLocation||t.wasmSourceMapLocation||t.locateFile)&&(i.locateFile=(c,x)=>{let Q={fileName:c,relativeTo:x};if(c.endsWith(".wasm")&&t.wasmLocation!==void 0)return a(["locateFile .wasm: provide wasmLocation",Q],t.wasmLocation);if(c.endsWith(".map")){if(t.wasmSourceMapLocation!==void 0)return a(["locateFile .map: provide wasmSourceMapLocation",Q],t.wasmSourceMapLocation);if(t.wasmLocation&&!t.locateFile)return a(["locateFile .map: infer from wasmLocation",Q],t.wasmLocation+".map")}return t.locateFile?a(["locateFile: use provided fn",Q],t.locateFile(c,x)):a(["locateFile: unhandled, passthrough",Q],c)}),t.wasmBinary&&(i.wasmBinary=await u(t.wasmBinary));let l=t.wasmModule,h;l&&(i.instantiateWasm=async(c,x)=>{h??(h=Promise.resolve(u(l)));let Q=await h;if(!Q)throw new V(`options.wasmModule returned ${String(Q)}`);let we=await WebAssembly.instantiate(Q,c);return x(we),we.exports}),i.monitorRunDependencies=c=>{s("monitorRunDependencies:",c)},i.quickjsEmscriptenInit=()=>Ve(s);let E=r(i),m=i.quickjsEmscriptenInit?.(s);if(l&&m?.receiveWasmOffsetConverter&&!m.existingWasmOffsetConverter){let c=await u(t.wasmBinary)??new ArrayBuffer(0);h??(h=Promise.resolve(u(l)));let x=await h;if(!x)throw new V(`options.wasmModule returned ${String(x)}`);m.receiveWasmOffsetConverter(c,x)}if(m?.receiveSourceMapJSON){let c=await u(t.wasmSourceMapData);typeof c=="string"?m.receiveSourceMapJSON(JSON.parse(c)):c?m.receiveSourceMapJSON(c):m.receiveSourceMapJSON({version:3,names:[],sources:[],mappings:""})}return E}}}}function Ve(o){let t="mock called, emscripten module may not be initialized yet";return{mock:!0,removeRunDependency(e){o(`${t}: removeRunDependency called:`,e)},receiveSourceMapJSON(e){o(`${t}: receiveSourceMapJSON called:`,e)},WasmOffsetConverter:void 0,receiveWasmOffsetConverter(e,r){o(`${t}: receiveWasmOffsetConverter called:`,e,r)}}}function Oe(o){return!("error"in o)}function _e(o){return"error"in o}b();function Ie(o){let t=typeof o=="number"?o:o.getTime();return function(){return Date.now()>t}}v();me();v();b();var xe=class{constructor(t){this.parent=t;this.contexts=new Set;this.runtimes=new Set}newRuntime(t){let e=this.parent.newRuntime({...t,ownedLifetimes:[new d(void 0,void 0,()=>this.runtimes.delete(e)),...t?.ownedLifetimes??[]]});return this.runtimes.add(e),e}newContext(t){let e=this.parent.newContext({...t,ownedLifetimes:[new d(void 0,void 0,()=>this.contexts.delete(e)),...t?.ownedLifetimes??[]]});return this.contexts.add(e),e}evalCode(t,e){return this.parent.evalCode(t,e)}disposeAll(){let t=[...this.contexts,...this.runtimes];this.runtimes.clear(),this.contexts.clear(),t.forEach(e=>{e.alive&&e.dispose()})}assertNoMemoryAllocated(){if(this.getFFI().QTS_RecoverableLeakCheck())throw new H("Leak sanitizer detected un-freed memory");if(this.contexts.size>0)throw new H(`${this.contexts.size} contexts leaked`);if(this.runtimes.size>0)throw new H(`${this.runtimes.size} runtimes leaked`)}getFFI(){return this.parent.getFFI()}};T();M();0&&(module.exports={DefaultIntrinsics,Lifetime,QuickJSAsyncContext,QuickJSAsyncRuntime,QuickJSAsyncWASMModule,QuickJSContext,QuickJSDeferredPromise,QuickJSRuntime,QuickJSWASMModule,Scope,StaticLifetime,TestQuickJSWASMModule,UsingDisposable,WeakLifetime,debugLog,errors,isFail,isSuccess,memoizePromiseFactory,newQuickJSAsyncWASMModuleFromVariant,newQuickJSWASMModuleFromVariant,newVariant,shouldInterruptAfterDeadline,...require("@jitl/quickjs-ffi-types")}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "quickjs-emscripten-core", | ||
"version": "0.26.0", | ||
"version": "0.26.1-rc.0", | ||
"sideEffects": false, | ||
@@ -46,4 +46,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"@jitl/quickjs-ffi-types": "0.26.0" | ||
"@jitl/quickjs-ffi-types": "0.26.1-rc.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
590254
1746
+ Added@jitl/quickjs-ffi-types@0.26.1-rc.0(transitive)
- Removed@jitl/quickjs-ffi-types@0.26.0(transitive)