1var ue={type:"sync",importFFI:()=>import("./ffi-Boa1QuFa.js").then(e=>e.QuickJSFFI),importModuleLoader:()=>import("./emscripten-module.browser-C0HztL0z.js").then(e=>e.default)},le=ue,he="/assets/emscripten-module-uFzwHH0Y.wasm",g={JS_EVAL_TYPE_GLOBAL:0,JS_EVAL_TYPE_MODULE:1,JS_EVAL_FLAG_STRICT:8,JS_EVAL_FLAG_STRIP:16,JS_EVAL_FLAG_COMPILE_ONLY:32,JS_EVAL_FLAG_BACKTRACE_BARRIER:64},V={BaseObjects:1,Date:2,Eval:4,StringNormalize:8,RegExp:16,RegExpCompiler:32,JSON:64,Proxy:128,MapSet:256,TypedArrays:512,Promise:1024,BigInt:2048,BigFloat:4096,BigDecimal:8192,OperatorOverloading:16384,BignumExt:32768},Q={Pending:0,Fulfilled:1,Rejected:2},_={JS_GPN_STRING_MASK:1,JS_GPN_SYMBOL_MASK:2,JS_GPN_PRIVATE_MASK:4,JS_GPN_ENUM_ONLY:16,QTS_GPN_NUMBER_MASK:64,QTS_STANDARD_COMPLIANT_NUMBER:128},M={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2},ce=Object.defineProperty,me=(e,t)=>{for(var r in t)ce(e,r,{get:t[r],enumerable:!0})};function x(...e){}var de={};me(de,{QuickJSAsyncifyError:()=>q,QuickJSAsyncifySuspended:()=>Y,QuickJSEmptyGetOwnPropertyNames:()=>Z,QuickJSEmscriptenModuleError:()=>I,QuickJSHostRefInvalid:()=>S,QuickJSHostRefRangeExceeded:()=>ee,QuickJSMemoryLeakDetected:()=>fe,QuickJSNotImplemented:()=>z,QuickJSPromisePending:()=>X,QuickJSUnknownIntrinsic:()=>K,QuickJSUnwrapError:()=>H,QuickJSUseAfterFree:()=>R,QuickJSWrongOwner:()=>W});var H=class extends Error{constructor(e,t){let r=typeof e=="object"&&e&&"message"in e?String(e.message):String(e);super(r),this.cause=e,this.context=t,this.name="QuickJSUnwrapError"}},W=class extends Error{constructor(){super(...arguments),this.name="QuickJSWrongOwner"}},R=class extends Error{constructor(){super(...arguments),this.name="QuickJSUseAfterFree"}},z=class extends Error{constructor(){super(...arguments),this.name="QuickJSNotImplemented"}},q=class extends Error{constructor(){super(...arguments),this.name="QuickJSAsyncifyError"}},Y=class extends Error{constructor(){super(...arguments),this.name="QuickJSAsyncifySuspended"}},fe=class extends Error{constructor(){super(...arguments),this.name="QuickJSMemoryLeakDetected"}},I=class extends Error{constructor(){super(...arguments),this.name="QuickJSEmscriptenModuleError"}},K=class extends TypeError{constructor(){super(...arguments),this.name="QuickJSUnknownIntrinsic"}},X=class extends Error{constructor(){super(...arguments),this.name="QuickJSPromisePending"}},Z=class extends Error{constructor(){super(...arguments),this.name="QuickJSEmptyGetOwnPropertyNames"}},ee=class extends Error{constructor(){super(...arguments),this.name="QuickJSHostRefRangeExceeded"}},S=class extends Error{constructor(){super(...arguments),this.name="QuickJSHostRefInvalid"}};function*te(e){return yield e}function pe(e){return te(O(e))}var L=te;L.of=pe;function B(e,t){return(...r)=>{let i=t.call(e,L,...r);return O(i)}}function we(e,t){let r=t.call(e,L);return O(r)}function O(e){function t(r){return r.done?r.value:r.value instanceof Promise?r.value.then(i=>t(e.next(i)),i=>t(e.throw(i))):t(e.next(r.value))}return t(e.next())}var y=class{[Symbol.dispose](){return this.dispose()}},C=Symbol.dispose??Symbol.for("Symbol.dispose"),j=y.prototype;j[C]||(j[C]=function(){return this.dispose()});var d=class re extends y{constructor(t,r,i,s){super(),this._value=t,this.copier=r,this.disposer=i,this._owner=s,this._alive=!0,this._constructorStack=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 re(this.copier(this._value),this.copier,this.disposer,this._owner)}consume(t){this.assertAlive();let r=t(this);return this.dispose(),r}map(t){return this.assertAlive(),t(this)}tap(t){return t(this),this}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new R(`Lifetime not alive 2${this._constructorStack} 3Lifetime used`):new R("Lifetime not alive")}},v=class extends d{constructor(e,t){super(e,void 0,void 0,t)}get dupable(){return!0}dup(){return this}dispose(){}}
3,D=class extends d{constructor(e,t,r,i){super(e,t,r,i)}dispose(){this._alive=!1}};function J(e,t){let r;try{e.dispose()}catch(i){r=i}if(t&&r)throw Object.assign(t,{message:`${t.message} 4 Then, failed to dispose scope: ${r.message}`,disposeError:r}),t;if(t||r)throw t||r}var p=class P extends y{constructor(){super(...arguments),this._disposables=new d(new Set),this.manage=t=>(this._disposables.value.add(t),t)}static withScope(t){let r=new P,i;try{return t(r)}catch(s){throw i=s,s}finally{J(r,i)}}static withScopeMaybeAsync(t,r){return we(void 0,function*(i){let s=new P,n;try{return yield*i.of(r.call(t,i,s))}catch(o){throw n=o,o}finally{J(s,n)}})}static async withScopeAsync(t){let r=new P,i;try{return await t(r)}catch(s){throw i=s,s}finally{J(r,i)}}get alive(){return this._disposables.alive}dispose(){let t=Array.from(this._disposables.value.values()).reverse();for(let r of t)r.alive&&r.dispose();this._disposables.dispose()}};function ye(e){let t=e?Array.from(e):[];function r(){return t.forEach(s=>s.alive?s.dispose():void 0)}function i(){return t.some(s=>s.alive)}return Object.defineProperty(t,C,{configurable:!0,enumerable:!1,value:r}),Object.defineProperty(t,"dispose",{configurable:!0,enumerable:!1,value:r}),Object.defineProperty(t,"alive",{configurable:!0,enumerable:!1,get:i}),t}function T(e){return!!(e&&(typeof e=="object"||typeof e=="function")&&"alive"in e&&typeof e.alive=="boolean"&&"dispose"in e&&typeof e.dispose=="function")}var N=class ie extends y{static success(t){return new Se(t)}static fail(t,r){return new ve(t,r)}static is(t){return t instanceof ie}},Se=class extends N{constructor(e){super(),this.value=e}get alive(){return T(this.value)?this.value.alive:!0}dispose(){T(this.value)&&this.value.dispose()}unwrap(){return this.value}unwrapOr(e){return this.value}},ve=class extends N{constructor(e,t){super(),this.error=e,this.onUnwrap=t}get alive(){return T(this.error)?this.error.alive:!0}dispose(){T(this.error)&&this.error.dispose()}unwrap(){throw this.onUnwrap(this),this.error}unwrapOr(e){return e}},b=N,ge=class extends y{constructor(e){super(),this.resolve=t=>{this.resolveHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.resolveHandle,this.context.undefined,t||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.reject=t=>{this.rejectHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.rejectHandle,this.context.undefined,t||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(t=>{this.onSettled=t}),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()}},se=class{constructor(e){this.module=e}toPointerArray(e){let t=new Int32Array(e.map(s=>s.value)),r=t.length*t.BYTES_PER_ELEMENT,i=this.module._malloc(r);return new Uint8Array(this.module.HEAPU8.buffer,i,r).set(new Uint8Array(t.buffer)),new d(i,void 0,s=>this.module._free(s))}newTypedArray(e,t){let r=new e(new Array(t).fill(0)),i=r.length*r.BYTES_PER_ELEMENT,s=this.module._malloc(i),n=new e(this.module.HEAPU8.buffer,s,t);return n.set(r),new d({typedArray:n,ptr:s},void 0,o=>this.module._free(o.ptr))}newMutablePointerArray(e){return this.newTypedArray(Int32Array,e)}newHeapCharPointer(e){let t=this.module.lengthBytesUTF8(e),r=t+1,i=this.module._malloc(r);return this.module.stringToUTF8(e,i,r),new d({ptr:i,strlen:t},void 0,s=>this.module._free(s.ptr))}newHeapBufferPointer(e){let t=e.byteLength,r=this.module._malloc(t);return this.module.HEAPU8.set(e,r),new d({pointer:r,numBytes:t},void 0,i=>this.module._free(i.pointer))}consumeHeapCharPointer(e){let t=this.module.UTF8ToString(e);return this.module._free(e),t}};function _e(e){if(!e)return 0;let t=0;for(let[r,i]of Object.entries(e)){if(!(r in V))throw new K(r);i&&(t|=V[r])}return t}function be(e){if(typeof e=="number")return e;if(e===void 0)return 0;let{type:t,strict:r,strip:i,compileOnly:s,backtraceBarrier:n}=e,o=0;return t==="global"&&(o|=g.JS_EVAL_TYPE_GLOBAL),t==="module"&&(o|=g.JS_EVAL_TYPE_MODULE),r&&(o|=g.JS_EVAL_FLAG_STRICT),i&&(o|=g.JS_EVAL_FLAG_STRIP),s&&(o|=g.JS_EVAL_FLAG_COMPILE_ONLY),n&&(o|=g.JS_EVAL_FLAG_BACKTRACE_BARRIER),o}function xe(e){if(typeof e=="number")return e;if(e===void 0)return 0;let{strings:t,symbols:r,quickjsPrivate:i,onlyEnumerable:s,numbers:n,numbersAsStrings:o}=e,a=0;return t&&(a|=_.JS_GPN_STRING_MASK),r&&(a|=_.JS_GPN_SYMBOL_MASK),i&&(a|=_.JS_GPN_PRIVATE_MASK),s&&(a|=_.JS_GPN_ENUM_ONLY),n&&(a|=_.QTS_GPN_NUMBER_MASK),o&&(a|=_.QTS_STANDARD_COMPLIANT_NUMBER),a}function Me(...e){let t=[];for(let r of e)r!==void 0&&(t=t.concat(r));return t}var Pe=class extends y{constructor(e,t){super(),this.handle=e,this.context=t,this._isDone=!1,this.owner=t.runtime}[Symbol.iterator](){return this}next(e){if(!this.alive||this._isDone)return{done:!0,value:void 0};let t=this._next??(this._next=this.context.getProp(this.handle,"next"));return this.callIteratorMethod(t,e)}return(e){if(!this.alive)return{done:!0,value:void 0};let t=this.context.getProp(this.handle,"return");if(t===this.context.undefined&&e===void 0)return this.dispose(),{done:!0,value:void 0};let r=this.callIteratorMethod(t,e);return t.dispose(),this.dispose(),r}throw(e){if(!this.alive)return{done:!0,value:void 0};let t=e instanceof d?e:this.context.newError(e),r=this.context.getProp(this.handle,"throw"),i=this.callIteratorMethod(r,e);
4return t.alive&&t.dispose(),r.dispose(),this.dispose(),i}get alive(){return this.handle.alive}dispose(){var e;this._isDone=!0,this.handle.dispose(),(e=this._next)==null||e.dispose()}callIteratorMethod(e,t){let r=t?this.context.callFunction(e,this.handle,t):this.context.callFunction(e,this.handle);if(r.error)return this.dispose(),{value:r};let i=this.context.getProp(r.value,"done").consume(n=>this.context.dump(n)),s=this.context.getProp(r.value,"value");return r.value.dispose(),i&&this.dispose(),{value:b.success(s),done:i}}},G=-2147483648,U=2147483647,E=0;function k(e){return e>>8}var Ee=class{constructor(){this.nextId=G,this.freelist=[],this.groups=new Map}put(e){let t=this.allocateId(),r=k(t),i=this.groups.get(r);return i||(i=new Map,this.groups.set(r,i)),i.set(t,e),t}get(e){if(e===E)throw new S("no host reference id defined");let t=k(e),r=this.groups.get(t);if(!r)throw new S(`host reference id ${e} is not defined`);let i=r.get(e);if(!i)throw new S(`host reference id ${e} is not defined`);return i}delete(e){if(e===E)throw new S("no host reference id defined");let t=k(e),r=this.groups.get(t);if(!r)throw new S(`host reference id ${e} is not defined`);r.delete(e),r.size===0&&this.groups.delete(t),this.freelist.push(e)}allocateId(){if(this.freelist.length>0)return this.freelist.shift();if(this.nextId===E&&this.nextId++,this.nextId>U)throw new ee(`HostRefMap: too many host refs created without disposing. Max simultaneous host refs: ${U-G}`);return this.nextId++}},$=class extends y{constructor(e,t,r){if(r===E)throw new S("cannot create HostRef with undefined id");super(),this.runtime=e,this.handle=t,this.id=r}get alive(){return this.handle.alive}dispose(){this.handle.dispose()}get value(){return this.runtime.hostRefs.get(this.id)}},Ae=class extends se{constructor(e){var t;super(e.module),this.scope=new p,this.copyJSValue=r=>this.ffi.QTS_DupValuePointer(this.ctx.value,r),this.freeJSValue=r=>{this.ffi.QTS_FreeValuePointer(this.ctx.value,r)},(t=e.ownedLifetimes)==null||t.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 t=this.module.UTF8ToString(e);return this.ffi.QTS_FreeCString(this.ctx.value,e),t}heapValueHandle(e,t){let r=t?i=>{t(),this.freeJSValue(i)}:this.freeJSValue;return new d(e,this.copyJSValue,r,this.owner)}staticHeapValueHandle(e){return this.manage(this.heapValueHandle(e)),new v(e,this.owner)}},Te=class extends y{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._Symbol=void 0,this._SymbolIterator=void 0,this._SymbolAsyncIterator=void 0,this.cToHostCallbacks={callFunction:(t,r,i,s,n)=>{if(t!==this.ctx.value)throw new Error("QuickJSContext instance received C -> JS call with mismatched ctx");let o=this.getFunction(n);return p.withScopeMaybeAsync(this,function*(a,u){let h=u.manage(new D(r,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime)),c=new Array(i);for(let m=0;m<i;m++){let l=this.ffi.QTS_ArgvGetJSValueConstPointer(s,m);c[m]=u.manage(new D(l,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime))}try{let m=yield*a(o.apply(h,c));if(m){if("error"in m&&m.error)throw this.runtime.debugLog("throw error",m.error),m.error;let l=u.manage(m instanceof d?m:m.value);return this.ffi.QTS_DupValuePointer(this.ctx.value,l.value)}return 0}catch(m){return this.errorToHandle(m).consume(l=>this.ffi.QTS_Throw(this.ctx.value,l.value))}})}},this.runtime=e.runtime,this.module=e.module,this.ffi=e.ffi,this.rt=e.rt,this.ctx=e.ctx,this.memory=new Ae({...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),this.uint32Out=this.memory.manage(this.memory.newTypedArray(Uint32Array,1))}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 v(e)}get null(){if(this._null)return this._null;let e=this.ffi.QTS_GetNull();return this._null=new v(e)}get true(){if(this._true)return this._true;
4let e=this.ffi.QTS_GetTrue();return this._true=new v(e)}get false(){if(this._false)return this._false;let e=this.ffi.QTS_GetFalse();return this._false=new v(e)}get global(){if(this._global)return this._global;let e=this.ffi.QTS_GetGlobalObject(this.ctx.value);return this._global=this.memory.staticHeapValueHandle(e),this._global}newNumber(e){return this.memory.heapValueHandle(this.ffi.QTS_NewFloat64(this.ctx.value,e))}newString(e){let t=this.memory.newHeapCharPointer(e).consume(r=>this.ffi.QTS_NewString(this.ctx.value,r.value.ptr));return this.memory.heapValueHandle(t)}newUniqueSymbol(e){let t=(typeof e=="symbol"?e.description:e)??"",r=this.memory.newHeapCharPointer(t).consume(i=>this.ffi.QTS_NewSymbol(this.ctx.value,i.value.ptr,0));return this.memory.heapValueHandle(r)}newSymbolFor(e){let t=(typeof e=="symbol"?e.description:e)??"",r=this.memory.newHeapCharPointer(t).consume(i=>this.ffi.QTS_NewSymbol(this.ctx.value,i.value.ptr,1));return this.memory.heapValueHandle(r)}getWellKnownSymbol(e){return this._Symbol??(this._Symbol=this.memory.manage(this.getProp(this.global,"Symbol"))),this.getProp(this._Symbol,e)}newBigInt(e){if(!this._BigInt){let i=this.getProp(this.global,"BigInt");this.memory.manage(i),this._BigInt=new v(i.value,this.runtime)}let t=this._BigInt,r=String(e);return this.newString(r).consume(i=>this.unwrapResult(this.callFunction(t,this.undefined,i)))}newObject(e){e&&this.runtime.assertOwned(e);let t=e?this.ffi.QTS_NewObjectProto(this.ctx.value,e.value):this.ffi.QTS_NewObject(this.ctx.value);return this.memory.heapValueHandle(t)}newArray(){let e=this.ffi.QTS_NewArray(this.ctx.value);return this.memory.heapValueHandle(e)}newArrayBuffer(e){let t=new Uint8Array(e),r=this.memory.newHeapBufferPointer(t),i=this.ffi.QTS_NewArrayBuffer(this.ctx.value,r.value.pointer,t.length);return this.memory.heapValueHandle(i)}
4newPromise(e){let t=p.withScope(r=>{let i=r.manage(this.memory.newMutablePointerArray(2)),s=this.ffi.QTS_NewPromiseCapability(this.ctx.value,i.value.ptr),n=this.memory.heapValueHandle(s),[o,a]=Array.from(i.value.typedArray).map(u=>this.memory.heapValueHandle(u));return new ge({context:this,promiseHandle:n,resolveHandle:o,rejectHandle:a})});return e&&typeof e=="function"&&(e=new Promise(e)),e&&Promise.resolve(e).then(t.resolve,r=>r instanceof d?t.reject(r):this.newError(r).consume(t.reject)),t}newFunction(e,t){let r=typeof e=="function"?e:t;if(!r)throw new TypeError("Expected a function");return this.newFunctionWithOptions({name:typeof e=="string"?e:void 0,length:r.length,isConstructor:!1,fn:r})}newConstructorFunction(e,t){let r=typeof e=="function"?e:t;if(!r)throw new TypeError("Expected a function");return this.newFunctionWithOptions({name:typeof e=="string"?e:void 0,length:r.length,isConstructor:!0,fn:r})}newFunctionWithOptions(e){let{name:t,length:r,isConstructor:i,fn:s}=e,n=this.runtime.hostRefs.put(s);try{return this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value,t??"",r,i,n))}catch(o){throw this.runtime.hostRefs.delete(n),o}}newError(e){let t=this.memory.heapValueHandle(this.ffi.QTS_NewError(this.ctx.value));return e&&typeof e=="object"?(e.name!==void 0&&this.newString(e.name).consume(r=>this.setProp(t,"name",r)),e.message!==void 0&&this.newString(e.message).consume(r=>this.setProp(t,"message",r))):typeof e=="string"?this.newString(e).consume(r=>this.setProp(t,"message",r)):e!==void 0&&this.newString(String(e)).consume(r=>this.setProp(t,"message",r)),t}newHostRef(e){let t=this.runtime.hostRefs.put(e);try{let r=this.memory.heapValueHandle(this.ffi.QTS_NewHostRef(this.ctx.value,t));return new $(this.runtime,r,t)}catch(r){throw this.runtime.hostRefs.delete(t),r}}toHostRef(e){let t=this.ffi.QTS_GetHostRefId(e.value);if(t!==0)return this.runtime.hostRefs.get(t),new $(this.runtime,e.dup(),t)}unwrapHostRef(e){let t=this.ffi.QTS_GetHostRefId(e.value);if(t===0)throw new S("handle is not a HostRef");return this.runtime.hostRefs.get(t)}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 t=this.memory.consumeJSCharPointer(this.ffi.QTS_GetSymbolDescriptionOrKey(this.ctx.value,e.value));return this.ffi.QTS_IsGlobalSymbol(this.ctx.value,e.value)?Symbol.for(t):Symbol(t)}getBigInt(e){this.runtime.assertOwned(e);let t=this.getString(e);return BigInt(t)}getArrayBuffer(e){this.runtime.assertOwned(e);let t=this.ffi.QTS_GetArrayBufferLength(this.ctx.value,e.value),r=this.ffi.QTS_GetArrayBuffer(this.ctx.value,e.value);if(!r)throw new Error("Couldn't allocate memory to get ArrayBuffer");return new d(this.module.HEAPU8.subarray(r,r+t),void 0,()=>this.module._free(r))}getPromiseState(e){this.runtime.assertOwned(e);let t=this.ffi.QTS_PromiseState(this.ctx.value,e.value);if(t<0)return{type:"fulfilled",value:e,notAPromise:!0};if(t===Q.Pending)return{type:"pending",get error(){return new X("Cannot unwrap a pending promise")}};let r=this.ffi.QTS_PromiseResult(this.ctx.value,e.value),i=this.memory.heapValueHandle(r);if(t===Q.Fulfilled)return{type:"fulfilled",value:i};if(t===Q.Rejected)return{type:"rejected",error:i};throw i.dispose(),new Error(`Unknown JSPromiseStateEnum: ${t}`)}resolvePromise(e){this.runtime.assertOwned(e);let t=p.withScope(r=>{let i=r.manage(this.getProp(this.global,"Promise")),s=r.manage(this.getProp(i,"resolve"));return this.callFunction(s,i,e)});return t.error?Promise.resolve(t):new Promise(r=>{p.withScope(i=>{let s=i.manage(this.newFunction("resolve",u=>{r(this.success(u&&u.dup()))})),n=i.manage(this.newFunction("reject",u=>{r(this.fail(u&&u.dup()))})),o=i.manage(t.value),a=i.manage(this.getProp(o,"then"));this.callFunction(a,o,s,n).unwrap().dispose()})})}isEqual(e,t,r=M.IsStrictlyEqual){if(e===t)return!0;this.runtime.assertOwned(e),this.runtime.assertOwned(t);let i=this.ffi.QTS_IsEqual(this.ctx.value,e.value,t.value,r);if(i===-1)throw new z("WASM variant does not expose equality");return!!i}eq(e,t){return this.isEqual(e,t,M.IsStrictlyEqual)}sameValue(e,t){return this.isEqual(e,t,M.IsSameValue)}sameValueZero(e,t){return this.isEqual(e,t,M.IsSameValueZero)}getProp(e,t){this.runtime.assertOwned(e);let r;return typeof t=="number"&&t>=0?r=this.ffi.QTS_GetPropNumber(this.ctx.value,e.value,t):r=this.borrowPropertyKey(t).consume(i=>this.ffi.QTS_GetProp(this.ctx.value,e.value,i.value)),this.memory.heapValueHandle(r)}getLength(e){if(this.runtime.assertOwned(e),!(this.ffi.QTS_GetLength(this.ctx.value,this.uint32Out.value.ptr,e.value)<0))return this.uint32Out.value.typedArray[0]}getOwnPropertyNames(e,t={strings:!0,numbersAsStrings:!0}){this.runtime.assertOwned(e),e.value;let r=xe(t);if(r===0)throw new Z("No options set, will return an empty array");return p.withScope(i=>{let s=i.manage(this.memory.newMutablePointerArray(1)),n=this.ffi.QTS_GetOwnPropertyNames(this.ctx.value,s.value.ptr,this.uint32Out.value.ptr,e.value,r);if(n)return this.fail(this.memory.heapValueHandle(n));let o=this.uint32Out.value.typedArray[0],a=s.value.typedArray[0],u=new Uint32Array(this.module.HEAP8.buffer,a,o),h=Array.from(u).map(c=>this.memory.heapValueHandle(c));return this.ffi.QTS_FreeVoidPointer(this.ctx.value,a),this.success(ye(h))})}getIterator(e){let t=this._SymbolIterator??(this._SymbolIterator=this.memory.manage(this.getWellKnownSymbol("iterator")));return p.withScope(r=>{let i=r.manage(this.getProp(e,t)),s=this.callFunction(i,e);return s.error?s:this.success(new Pe(s.value,this))})}setProp(e,t,r){this.runtime.assertOwned(e),this.borrowPropertyKey(t).consume(i=>this.ffi.QTS_SetProp(this.ctx.value,e.value,i.value,r.value))}defineProp(e,t,r){this.runtime.assertOwned(e),p.withScope(i=>{let s=i.manage(this.borrowPropertyKey(t)),n=r.value||this.undefined,o=!!r.configurable,a=!!r.enumerable,u=!!r.value,h=r.get?i.manage(this.newFunction(r.get.name,r.get)):this.undefined,c=r.set?i.manage(this.newFunction(r.set.name,r.set)):this.undefined;this.ffi.QTS_DefineProp(this.ctx.value,e.value,s.value,n.value,h.value,c.value,o,a,u)})}callFunction(e,t,...r){this.runtime.assertOwned(e);let i,s=r[0];s===void 0||Array.isArray(s)?i=s??[]:i=r;let n=this.memory.toPointerArray(i).consume(a=>this.ffi.QTS_Call(this.ctx.value,e.value,t.value,i.length,a.value)),o=this.ffi.QTS_ResolveException(this.ctx.value,
4n);return o?(this.ffi.QTS_FreeValuePointer(this.ctx.value,n),this.fail(this.memory.heapValueHandle(o))):this.success(this.memory.heapValueHandle(n))}callMethod(e,t,r=[]){return this.getProp(e,t).consume(i=>this.callFunction(i,e,r))}evalCode(e,t="eval.js",r){let i=r===void 0?1:0,s=be(r),n=this.memory.newHeapCharPointer(e).consume(a=>this.ffi.QTS_Eval(this.ctx.value,a.value.ptr,a.value.strlen,t,i,s)),o=this.ffi.QTS_ResolveException(this.ctx.value,n);return o?(this.ffi.QTS_FreeValuePointer(this.ctx.value,n),this.fail(this.memory.heapValueHandle(o))):this.success(this.memory.heapValueHandle(n))}throw(e){return this.errorToHandle(e).consume(t=>this.ffi.QTS_Throw(this.ctx.value,t.value))}borrowPropertyKey(e){return typeof e=="number"?this.newNumber(e):typeof e=="string"?this.newString(e):new v(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 t=this.typeof(e);if(t==="string")return this.getString(e);if(t==="number")return this.getNumber(e);if(t==="bigint")return this.getBigInt(e);if(t==="undefined")return;if(t==="symbol")return this.getSymbol(e);let r=this.getPromiseState(e);if(r.type==="fulfilled"&&!r.notAPromise)return e.dispose(),{type:r.type,value:r.value.consume(this.dump)};if(r.type==="pending")return e.dispose(),{type:r.type};if(r.type==="rejected")return e.dispose(),{type:r.type,error:r.error.consume(this.dump)};let i=this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value,e.value));try{return JSON.parse(i)}catch{return i}}unwrapResult(e){if(e.error){let t="context"in e.error?e.error.context:this,r=e.error.consume(i=>this.dump(i));if(r&&typeof r=="object"&&typeof r.message=="string"){let{message:i,name:s,stack:n,...o}=r,a=new H(r,t);typeof s=="string"&&(a.name=r.name),a.message=i;let u=a.stack;throw typeof n=="string"&&(a.stack=`${s}: ${i} 5${r.stack}Host: ${u}`),Object.assign(a,o),a}throw new H(r)}return e.value}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { ctx: ${this.ctx.value} rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getFunction(e){let t=this.runtime.hostRefs.get(e);if(typeof t!="function")throw new Error(`Host reference ${e} is not a function`);return t}errorToHandle(e){return e instanceof d?e:this.newError(e)}encodeBinaryJSON(e){let t=this.ffi.QTS_bjson_encode(this.ctx.value,e.value);return this.memory.heapValueHandle(t)}decodeBinaryJSON(e){let t=this.ffi.QTS_bjson_decode(this.ctx.value,e.value);return this.memory.heapValueHandle(t)}success(e){return b.success(e)}fail(e){return b.fail(e,t=>this.unwrapResult(t))}},Qe=class extends y{constructor(e){var t;super(),this.scope=new p,this.contextMap=new Map,this.hostRefs=new Ee,this._debugMode=!1,this.cToHostCallbacks={freeHostRef:(r,i)=>{if(r!==this.rt.value)throw new Error("Runtime pointer mismatch");this.hostRefs.delete(i)},shouldInterrupt:r=>{if(r!==this.rt.value)throw new Error("QuickJSContext instance received C -> JS interrupt with mismatched rt");let i=this.interruptHandler;if(!i)throw new Error("QuickJSContext had no interrupt handler");return i(this)?1:0},loadModuleSource:B(this,function*(r,i,s,n){let o=this.moduleLoader;if(!o)throw new Error("Runtime has no module loader");if(i!==this.rt.value)throw new Error("Runtime pointer mismatch");let a=this.contextMap.get(s)??this.newContext({contextPointer:s});try{let u=yield*r(o(n,a));if(typeof u=="object"&&"error"in u&&u.error)throw this.debugLog("cToHostLoadModule: loader returned error",u.error),u.error;let h=typeof u=="string"?u:"value"in u?u.value:u;return this.memory.newHeapCharPointer(h).value.ptr}catch(u){return this.debugLog("cToHostLoadModule: caught error",u),a.throw(u),0}}),normalizeModule:B(this,function*(r,i,s,n,o){let a=this.moduleNormalizer;if(!a)throw new Error("Runtime has no module normalizer");if(i!==this.rt.value)throw new Error("Runtime pointer mismatch");let u=this.contextMap.get(s)??this.newContext({contextPointer:s});try{let h=yield*r(a(n,o,u));if(typeof h=="object"&&"error"in h&&h.error)throw this.debugLog("cToHostNormalizeModule: n
5ormalizer returned error",h.error),h.error;let c=typeof h=="string"?h:h.value;return u.getMemory(this.rt.value).newHeapCharPointer(c).value.ptr}catch(h){return this.debugLog("normalizeModule: caught error",h),u.throw(h),0}})},(t=e.ownedLifetimes)==null||t.forEach(r=>this.scope.manage(r)),this.module=e.module,this.memory=new se(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 t=_e(e.intrinsics),r=new d(e.contextPointer||this.ffi.QTS_NewContext(this.rt.value,t),void 0,s=>{this.contextMap.delete(s),this.callbacks.deleteContext(s),this.ffi.QTS_FreeContext(s)}),i=new Te({module:this.module,ctx:r,ffi:this.ffi,rt:this.rt,ownedLifetimes:e.ownedLifetimes,runtime:this,callbacks:this.callbacks});return this.contextMap.set(r.value,i),i}setModuleLoader(e,t){this.moduleLoader=e,this.moduleNormalizer=t,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 t=this.interruptHandler;this.interruptHandler=e,t||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 t=this.memory.newMutablePointerArray(1),r=this.ffi.QTS_ExecutePendingJob(this.rt.value,e??-1,t.value.ptr),i=t.value.typedArray[0];if(t.dispose(),i===0)return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value,r),b.success(0);let s=this.contextMap.get(i)??this.newContext({contextPointer:i}),n=s.getMemory(this.rt.value).heapValueHandle(r);if(s.typeof(n)==="number"){let o=s.getNumber(n);return n.dispose(),b.success(o)}else{let o=Object.assign(n,{context:s});return b.fail(o,a=>s.unwrapResult(a))}}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 W(`Handle is not owned by this runtime: ${e.owner.rt.value} != ${this.rt.value}`)}setDebugMode(e){this._debugMode=e,this.ffi.DEBUG&&this.rt.alive&&this.ffi.QTS_SetDebugLogEnabled(this.rt.value,e?1:0)}isDebugMode(){return this._debugMode}debugLog(...e){this._debugMode&&console.log("quickjs-emscripten:",...e)}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getSystemContext(){return this.context||(this.context=this.scope.manage(this.newContext())),this.context}},Je=class{constructor(e){this.freeHostRef=e.freeHostRef,this.callFunction=e.callFunction,this.shouldInterrupt=e.shouldInterrupt,this.loadModuleSource=e.loadModuleSource,this.normalizeModule=e.normalizeModule}},ne=class{constructor(e){this.contextCallbacks=new Map,this.runtimeCallbacks=new Map,this.suspendedCount=0,this.cToHostCallbacks=new Je({freeHostRef:(t,r,i)=>{let s=this.runtimeCallbacks.get(r);if(!s)throw new Error(`QuickJSRuntime(rt = ${r}) not found when trying to free HostRef(id = ${i})`);s.freeHostRef(r,i)},callFunction:(t,r,i,s,n,o)=>this.handleAsyncify(t,()=>{try{let a=this.contextCallbacks.get(r);if(!a)throw new Error(`QuickJSContext(ctx = ${r}) not found for C function call "${o}"`);return a.callFunction(r,i,s,n,o)}catch(a){return console.error("[C to host error: returning null]",a),0}}),shouldInterrupt:(t,r)=>this.handleAsyncify(t,()=>{try{let i=this.runtimeCallbacks.get(r);if(!i)throw new Error(`QuickJSRuntime(rt = ${r}) not found for C interrupt`);return i.shouldInterrupt(r)}catch(i){return console.error("[C to host interrupt: returning error]",i),1}}),loadModuleSource:(t,r,i,s)=>this.handleAsyncify(t,()=>{try{let n=this.runtimeCallbacks.get(r);if(!n)throw new Error(`QuickJSRuntime(rt = ${r}) not found for C module loader`);let o=n.loadModuleSource;if(!o)throw new Error(`QuickJSRuntime(rt = ${r}) does not support module loading`);return o(r,i,s)}catch(n){return console.error("[C to host module loader error: returning null]",n),0}}),normalizeModule:(t,r,i,s,n)=>this.handleAsyncify(t,()=>{try{let o=this.runtimeCallbacks.get(r);if(!o)throw new Error(`QuickJSRuntime(rt = ${r}) not found for C module loader`);let a=o.normalizeModule;if(!a)throw new Error(`QuickJSRuntime(rt = ${r}) does not support module loading`);return a(r,i,s,n)}catch(o){return console.error("[C to host module loader error: returning null]",o),0}})}),this.module=e,this.module.callbacks=this.cToHostCallbacks}setRuntimeCallbacks(e,t){this.runtimeCallbacks.set(e,t)}deleteRuntime(e){this.runtimeCallbacks.delete(e)}setContextCallbacks(e,t){this.contextCallbacks.set(e,t)}deleteContext(e){this.contextCallbacks.delete(e)}handleAsyncify(e,t){if(e)return e.handleSleep(i=>{try{let s=t();if(!(s instanceof Promise)){x("asyncify.handleSleep: not suspending:",s),i(s);return}if(this.suspended)throw new q(`Already suspended at: ${this.suspended.stack} 6Attempted to suspend at:`);this.suspended=new Y(`(${this.suspendedCount++})`),x("asyncify.handleSleep: suspending:",this.suspended),s.then(n=>{this.suspended=void 0,x("asyncify.handleSleep: resolved:",n),i(n)},n=>{x("asyncify.handleSleep: rejected:",n),console.error("QuickJS: cannot handle error in suspended function",n),this.suspended=void 0})}catch(s){throw this.suspended=void 0,s}});let r=t();if(r instanceof Promise)throw new Error("Promise return value not supported in non-asyncify context.");return r}};function oe(e,t){t.interruptHandler&&e.setInterruptHandler(t.interruptHandler),t.maxStackSizeBytes!==void 0&&e.setMaxStackSize(t.maxStackSizeBytes),t.memoryLimitBytes!==void 0&&e.setMemoryLimit(t.memoryLimitBytes)}function ae(e,t){t.moduleLoader&&e.setModuleLoader(t.moduleLoader),t.shouldInterrupt&&e.setInterruptHandler(t.shouldInterrupt),t.memoryLimitBytes!==void 0&&e.setMemoryLimit(t.memoryLimitBytes),t.maxStackSizeBytes!==void 0&&e.setMaxStackSize(t.maxStackSizeBytes)}var ke=class{constructor(e,t){this.module=e,this.ffi=t,this.callbacks=new ne(e)}newRuntime(e={}){let t=new d(this.ffi.QTS_NewRuntime(),void 0,i=>{this.ffi.QTS_FreeRuntime(i),this.callbacks.deleteRuntime(i)}),r=new Qe({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:t});return oe(r,e),e.moduleLoader&&r.setModuleLoader(e.moduleLoader),r}newContext(e={}){let t=this.newRuntime(),r=t.newContext({...e,ownedLifetimes:Me(t,e.ownedLifetimes)});return t.context=r,r}evalCode(e,t={}){return p.withScope(r=>{let i=r.manage(this.newContext());ae(i.runtime,t);let s=i.evalCode(e,"eval.js");if(t.memoryLimitBytes!==void 0&&i.runtime.setMemoryLimit(-1),s.error)throw i.dump(r.manage(s.error));return i.dump(r.manage(s.value))})}getWasmMemory(){var t,r,i,s;let e=(s=(i=(r=(t=this.module).quickjsEmscriptenInit)==null?void 0:r.call(t,()=>{}))==null?void 0:i.getWasmMemory)==null?void 0:s.call(i);if(!e)throw new Error("Variant does not support getting WebAssembly.Memory");return e}getFFI(){return this.ffi}};async function He(e){let t=A(await e),[r,i,{QuickJSWASMModule:s}]=await Promise.all([t.importModuleLoader().then(A),t.importFFI(),Promise.resolve().then(function(){return je}).then(A)]),n=await r();n.type="sync";let o=new i(n);return new s(n,o)}function A(e){return e&&"default"in e&&e.default?e.default&&"default"in e.default&&e.default.default?e.default.default:e.default:e}function Re(e,t){return{...e,async importModuleLoader(){let r=A(await e.importModuleLoader());return async function(){var m;let i=t.emscriptenModule?{...t.emscriptenModule}:{},s=t.log??((...l)=>x("newVariant moduleLoader:",...l)),n=(l,f)=>(s(...l,f),f),o=l=>typeof l=="function"?l():l;(t.wasmLocation||t.wasmSourceMapLocation||t.locateFile)&&(i.locateFile=(l,f)=>{let w={fileName:l,relativeTo:f};if(l.endsWith(".wasm")&&t.wasmLocation!==void 0)return n(["locateFile .wasm: provide wasm
6Location",w],t.wasmLocation);if(l.endsWith(".map")){if(t.wasmSourceMapLocation!==void 0)return n(["locateFile .map: provide wasmSourceMapLocation",w],t.wasmSourceMapLocation);if(t.wasmLocation&&!t.locateFile)return n(["locateFile .map: infer from wasmLocation",w],t.wasmLocation+".map")}return t.locateFile?n(["locateFile: use provided fn",w],t.locateFile(l,f)):n(["locateFile: unhandled, passthrough",w],l)}),t.wasmBinary&&(i.wasmBinary=await o(t.wasmBinary)),t.wasmMemory&&(i.wasmMemory=await o(t.wasmMemory));let a=t.wasmModule,u;a&&(i.instantiateWasm=async(l,f)=>{u??(u=Promise.resolve(o(a)));let w=await u;if(!w)throw new I(`options.wasmModule returned ${String(w)}`);let F=await WebAssembly.instantiate(w,l);return f(F),F.exports}),i.monitorRunDependencies=l=>{s("monitorRunDependencies:",l)},i.quickjsEmscriptenInit=()=>Ie(s);let h=r(i),c=(m=i.quickjsEmscriptenInit)==null?void 0:m.call(i,s);if(a&&(c!=null&&c.receiveWasmOffsetConverter)&&!c.existingWasmOffsetConverter){let l=await o(t.wasmBinary)??new ArrayBuffer(0);u??(u=Promise.resolve(o(a)));let f=await u;if(!f)throw new I(`options.wasmModule returned ${String(f)}`);c.receiveWasmOffsetConverter(l,f)}if(c!=null&&c.receiveSourceMapJSON){let l=await o(t.wasmSourceMapData);typeof l=="string"?c.receiveSourceMapJSON(JSON.parse(l)):l?c.receiveSourceMapJSON(l):c.receiveSourceMapJSON({version:3,names:[],sources:[],mappings:""})}return h}}}}function Ie(e){let t="mock called, emscripten module may not be initialized yet";return{mock:!0,removeRunDependency(r){e(`${t}: removeRunDependency called:`,r)},receiveSourceMapJSON(r){e(`${t}: receiveSourceMapJSON called:`,r)},WasmOffsetConverter:void 0,receiveWasmOffsetConverter(r,i){e(`${t}: receiveWasmOffsetConverter called:`,r,i)}}}function Ce(e){let t=typeof e=="number"?e:e.getTime();return function(){return Date.now()>t}}const Le=16*1024*1024,Oe=120,Ne=12e4,Fe=64e3,Ve=He(Re(le,{wasmLocation:he}));function Be(e){const t=JSON.stringify({state:e.state,event:e.event});return` 7"use strict"; 8${e.code} 9const __input = ${t}; 10const __exercise = globalThis.exercise; 11if (!__exercise || typeof __exercise.render !== "function" || typeof __exercise.update !== "function") { 12 throw new Error("ç»ä¹ ç¼ºå° render æ update å ¥å£"); 13} 14let __state = __input.state === null 15 ? JSON.parse(JSON.stringify(__exercise.initialState ?? {})) 16 : __input.state; 17let __complete = false; 18if (__input.event !== null) { 19 const __updated = __exercise.update( 20 JSON.parse(JSON.stringify(__state)), 21 __input.event, 22 ); 23 if (!__updated || typeof __updated !== "object" || !("state" in __updated)) { 24 throw new Error("update å¿ é¡»è¿åå å« state ç对象"); 25 } 26 __state = __updated.state; 27 __complete = __updated.complete === true; 28} 29const __html = __exercise.render(JSON.parse(JSON.stringify(__state))); 30if (typeof __html !== "string") throw new Error("render å¿ é¡»è¿å HTML å符串"); 31JSON.stringify({ state: __state, html: __html, complete: __complete }); 32`}self.onmessage=async e=>{const t=e.data;let r;try{const s=(await Ve).evalCode(Be(t),{memoryLimitBytes:Le,shouldInterrupt:Ce(Date.now()+Oe)});if(typeof s!="string")throw new Error("ç»ä¹ 没æè¿åå¯ç¨ç»æ");const n=JSON.parse(s);if(typeof n.html!="string"||n.html.length>Ne)throw new Error("ç»ä¹ çæççé¢è¿å¤§ææ æ");if(JSON.stringify(n.state).length>Fe)throw new Error("ç»ä¹ ç¶æè¶ è¿ä¿åéå¶");r={requestId:t.requestId,ok:!0,result:{state:n.state,html:n.html,complete:n.complete===!0}}}catch(i){r={requestId:t.requestId,ok:!1,error:i instanceof Error?i.message:"交äºç»ä¹ è¿è¡å¤±è´¥"}}self.postMessage(r)};var je=Object.freeze({__proto__:null,QuickJSModuleCallbacks:ne,QuickJSWASMModule:ke,applyBaseRuntimeOptions:oe,applyModuleEvalRuntimeOptions:ae});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.