Skip to content

Instantly share code, notes, and snippets.

@simonw
Last active November 10, 2024 06:24
Show Gist options
  • Save simonw/36506994222a56d1556b3452ca663dbe to your computer and use it in GitHub Desktop.
Save simonw/36506994222a56d1556b3452ca663dbe to your computer and use it in GitHub Desktop.
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[338],{578:(e,t,r)=>{e.exports=r.p+"7cf7ced34f0a1ece31b4.wasm"},338:(e,t,r)=>{var n;r.r(t),r.d(t,{default:()=>a});const a=(n="file:///private/tmp/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.browser.mjs",function(e={}){var t,a,o=e;function i(e){e={log:e||function(){}};for(const t of i.za)t(e);return o.quickJSEmscriptenExtensions=e}o.ready=new Promise(((e,r)=>{t=e,a=r})),i.za=[],o.quickjsEmscriptenInit=i,i.za.push((e=>{e.getWasmMemory=function(){return Q}}));var _,u=Object.assign({},o),l="./this.program",s="object"==typeof window,f="function"==typeof importScripts,S="";(s||f)&&(f?S=self.location.href:"undefined"!=typeof document&&document.currentScript&&(S=document.currentScript.src),n&&(S=n),S=0!==S.indexOf("blob:")?S.substr(0,S.replace(/[?#].*/,"").lastIndexOf("/")+1):"",f&&(_=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}));var c,T=o.print||console.log.bind(console),m=o.printErr||console.error.bind(console);Object.assign(o,u),u=null,o.thisProgram&&(l=o.thisProgram),o.wasmBinary&&(c=o.wasmBinary),"object"!=typeof WebAssembly&&G("no native wasm support detected");var Q,d,p,b,g,h=!1;function y(){var e=Q.buffer;o.HEAP8=d=new Int8Array(e),o.HEAP16=new Int16Array(e),o.HEAPU8=p=new Uint8Array(e),o.HEAPU16=new Uint16Array(e),o.HEAP32=b=new Int32Array(e),o.HEAPU32=g=new Uint32Array(e),o.HEAPF32=new Float32Array(e),o.HEAPF64=new Float64Array(e)}var v=o.INITIAL_MEMORY||16777216;Q=o.wasmMemory?o.wasmMemory:new WebAssembly.Memory({initial:v/65536,maximum:32768}),y(),v=Q.buffer.byteLength;var w=[],A=[],R=[];function P(){var e=o.preRun.shift();w.unshift(e)}var F=0,M=null,N=null;function G(e){throw o.onAbort?.(e),m(e="Aborted("+e+")"),h=!0,e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info."),a(e),e}var E,I=e=>e.startsWith("data:application/octet-stream;base64,");if(o.locateFile){if(!I(E="emscripten-module.wasm")){var C=E;E=o.locateFile?o.locateFile(C,S):S+C}}else E=new URL(r(578),r.b).href;function D(e){if(e==E&&c)return new Uint8Array(c);if(_)return _(e);throw"both async and sync fetching of the wasm failed"}function k(e,t,r){return function(e){return c||!s&&!f||"function"!=typeof fetch?Promise.resolve().then((()=>D(e))):fetch(e,{credentials:"same-origin"}).then((t=>{if(!t.ok)throw"failed to load wasm binary file at '"+e+"'";return t.arrayBuffer()})).catch((()=>D(e)))}(e).then((e=>WebAssembly.instantiate(e,t))).then((e=>e)).then(r,(e=>{m(`failed to asynchronously prepare wasm: ${e}`),G(e)}))}var j,O=e=>{for(;0<e.length;)e.shift()(o)},x="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0,U=(e,t,r)=>{var n=t+r;for(r=t;e[r]&&!(r>=n);)++r;if(16<r-t&&e.buffer&&x)return x.decode(e.subarray(t,r));for(n="";t<r;){var a=e[t++];if(128&a){var o=63&e[t++];if(192==(224&a))n+=String.fromCharCode((31&a)<<6|o);else{var i=63&e[t++];65536>(a=224==(240&a)?(15&a)<<12|o<<6|i:(7&a)<<18|o<<12|i<<6|63&e[t++])?n+=String.fromCharCode(a):(a-=65536,n+=String.fromCharCode(55296|a>>10,56320|1023&a))}}else n+=String.fromCharCode(a)}return n},B=[0,31,60,91,121,152,182,213,244,274,305,335],L=[0,31,59,90,120,151,181,212,243,273,304,334],z=e=>{for(var t=0,r=0;r<e.length;++r){var n=e.charCodeAt(r);127>=n?t++:2047>=n?t+=2:55296<=n&&57343>=n?(t+=4,++r):t+=3}return t},H=(e,t,r)=>{var n=p;if(!(0<r))return 0;var a=t;r=t+r-1;for(var o=0;o<e.length;++o){var i=e.charCodeAt(o);if(55296<=i&&57343>=i&&(i=65536+((1023&i)<<10)|1023&e.charCodeAt(++o)),127>=i){if(t>=r)break;n[t++]=i}else{if(2047>=i){if(t+1>=r)break;n[t++]=192|i>>6}else{if(65535>=i){if(t+2>=r)break;n[t++]=224|i>>12}else{if(t+3>=r)break;n[t++]=240|i>>18,n[t++]=128|i>>12&63}n[t++]=128|i>>6&63}n[t++]=128|63&i}}return n[t]=0,t-a},W=e=>{var t=z(e)+1,r=K(t);return r&&H(e,r,t),r},V={},J=()=>{if(!j){var e,t={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:l||"./this.program"};for(e in V)void 0===V[e]?delete t[e]:t[e]=V[e];var r=[];for(e in t)r.push(`${e}=${t[e]}`);j=r}return j},$=[null,[],[]],Y={b:(e,t,r,n)=>{G(`Assertion failed: ${e?U(p,e):""}, at: `+[t?t?U(p,t):"":"unknown filename",r,n?n?U(p,n):"":"unknown function"])},j:function(e,t,r){e=new Date(1e3*(t+2097152>>>0<4194305-!!e?(e>>>0)+4294967296*t:NaN)),b[r>>2]=e.getSeconds(),b[r+4>>2]=e.getMinutes(),b[r+8>>2]=e.getHours(),b[r+12>>2]=e.getDate(),b[r+16>>2]=e.getMonth(),b[r+20>>2]=e.getFullYear()-1900,b[r+24>>2]=e.getDay(),t=e.getFullYear(),b[r+28>>2]=(0!=t%4||0==t%100&&0!=t%400?L:B)[e.getMonth()]+e.getDate()-1|0,b[r+36>>2]=-60*e.getTimezoneOffset(),t=new Date(e.getFullYear(),6,1).getTimezoneOffset();var n=new Date(e.getFullYear(),0,1).getTimezoneOffset();b[r+32>>2]=0|(t!=n&&e.getTimezoneOffset()==Math.min(n,t))},m:(e,t,r)=>{function n(e){return(e=e.toTimeString().match(/\(([A-Za-z ]+)\)$/))?e[1]:"GMT"}var a=(new Date).getFullYear(),o=new Date(a,0,1),i=new Date(a,6,1);a=o.getTimezoneOffset();var _=i.getTimezoneOffset();g[e>>2]=60*Math.max(a,_),b[t>>2]=Number(a!=_),e=n(o),t=n(i),e=W(e),t=W(t),_<a?(g[r>>2]=e,g[r+4>>2]=t):(g[r>>2]=t,g[r+4>>2]=e)},c:()=>{G("")},n:()=>Date.now(),l:e=>{var t=p.length;if(2147483648<(e>>>=0))return!1;for(var r=1;4>=r;r*=2){var n=t*(1+.2/r);n=Math.min(n,e+100663296);var a=Math;n=Math.max(e,n);e:{a=(a.min.call(a,2147483648,n+(65536-n%65536)%65536)-Q.buffer.byteLength+65535)/65536;try{Q.grow(a),y();var o=1;break e}catch(e){}o=void 0}if(o)return!0}return!1},f:(e,t)=>{var r=0;return J().forEach(((n,a)=>{var o=t+r;for(a=g[e+4*a>>2]=o,o=0;o<n.length;++o)d[0|a++]=n.charCodeAt(o);d[0|a]=0,r+=n.length+1})),0},g:(e,t)=>{var r=J();g[e>>2]=r.length;var n=0;return r.forEach((e=>n+=e.length+1)),g[t>>2]=n,0},e:()=>52,k:function(){return 70},d:(e,t,r,n)=>{for(var a=0,o=0;o<r;o++){var i=g[t>>2],_=g[t+4>>2];t+=8;for(var u=0;u<_;u++){var l=p[i+u],s=$[e];0===l||10===l?((1===e?T:m)(U(s,0)),s.length=0):s.push(l)}a+=_}return g[n>>2]=a,0},a:Q,p:function(e,t,r,n,a){return o.callbacks.callFunction(void 0,e,t,r,n,a)},o:function(e){return o.callbacks.shouldInterrupt(void 0,e)},i:function(e,t,r){return r=r?U(p,r):"",o.callbacks.loadModuleSource(void 0,e,t,r)},h:function(e,t,r,n){return r=r?U(p,r):"",n=n?U(p,n):"",o.callbacks.normalizeModule(void 0,e,t,r,n)}},q=function(){function e(e){return q=e.exports,A.unshift(q.q),F--,o.monitorRunDependencies?.(F),0==F&&(null!==M&&(clearInterval(M),M=null),N&&(e=N,N=null,e())),q}var t={a:Y};if(F++,o.monitorRunDependencies?.(F),o.instantiateWasm)try{return o.instantiateWasm(t,e)}catch(e){m(`Module.instantiateWasm callback failed with error: ${e}`),a(e)}return function(e,t){var r=E;return c||"function"!=typeof WebAssembly.instantiateStreaming||I(r)||"function"!=typeof fetch?k(r,e,t):fetch(r,{credentials:"same-origin"}).then((n=>WebAssembly.instantiateStreaming(n,e).then(t,(function(n){return m(`wasm streaming compile failed: ${n}`),m("falling back to ArrayBuffer instantiation"),k(r,e,t)}))))}(t,(function(t){e(t.instance)})).catch(a),{}}(),K=o._malloc=e=>(K=o._malloc=q.r)(e);o._QTS_Throw=(e,t)=>(o._QTS_Throw=q.s)(e,t),o._QTS_NewError=e=>(o._QTS_NewError=q.t)(e),o._QTS_RuntimeSetMemoryLimit=(e,t)=>(o._QTS_RuntimeSetMemoryLimit=q.u)(e,t),o._QTS_RuntimeComputeMemoryUsage=(e,t)=>(o._QTS_RuntimeComputeMemoryUsage=q.v)(e,t),o._QTS_RuntimeDumpMemoryUsage=e=>(o._QTS_RuntimeDumpMemoryUsage=q.w)(e),o._QTS_RecoverableLeakCheck=()=>(o._QTS_RecoverableLeakCheck=q.x)(),o._QTS_BuildIsSanitizeLeak=()=>(o._QTS_BuildIsSanitizeLeak=q.y)(),o._QTS_RuntimeSetMaxStackSize=(e,t)=>(o._QTS_RuntimeSetMaxStackSize=q.z)(e,t),o._QTS_GetUndefined=()=>(o._QTS_GetUndefined=q.A)(),o._QTS_GetNull=()=>(o._QTS_GetNull=q.B)(),o._QTS_GetFalse=()=>(o._QTS_GetFalse=q.C)(),o._QTS_GetTrue=()=>(o._QTS_GetTrue=q.D)(),o._QTS_NewRuntime=()=>(o._QTS_NewRuntime=q.E)(),o._QTS_FreeRuntime=e=>(o._QTS_FreeRuntime=q.F)(e),o._QTS_NewContext=(e,t)=>(o._QTS_NewContext=q.G)(e,t),o._QTS_FreeContext=e=>(o._QTS_FreeContext=q.H)(e),o._QTS_FreeValuePointer=(e,t)=>(o._QTS_FreeValuePointer=q.I)(e,t),o._free=e=>(o._free=q.J)(e),o._QTS_FreeValuePointerRuntime=(e,t)=>(o._QTS_FreeValuePointerRuntime=q.K)(e,t),o._QTS_FreeVoidPointer=(e,t)=>(o._QTS_FreeVoidPointer=q.L)(e,t),o._QTS_FreeCString=(e,t)=>(o._QTS_FreeCString=q.M)(e,t),o._QTS_DupValuePointer=(e,t)=>(o._QTS_DupValuePointer=q.N)(e,t),o._QTS_NewObject=e=>(o._QTS_NewObject=q.O)(e),o._QTS_NewObjectProto=(e,t)=>(o._QTS_NewObjectProto=q.P)(e,t),o._QTS_NewArray=e=>(o._QTS_NewArray=q.Q)(e),o._QTS_NewArrayBuffer=(e,t,r)=>(o._QTS_NewArrayBuffer=q.R)(e,t,r),o._QTS_NewFloat64=(e,t)=>(o._QTS_NewFloat64=q.S)(e,t),o._QTS_GetFloat64=(e,t)=>(o._QTS_GetFloat64=q.T)(e,t),o._QTS_NewString=(e,t)=>(o._QTS_NewString=q.U)(e,t),o._QTS_GetString=(e,t)=>(o._QTS_GetString=q.V)(e,t),o._QTS_GetArrayBuffer=(e,t)=>(o._QTS_GetArrayBuffer=q.W)(e,t),o._QTS_GetArrayBufferLength=(e,t)=>(o._QTS_GetArrayBufferLength=q.X)(e,t),o._QTS_NewSymbol=(e,t,r)=>(o._QTS_NewSymbol=q.Y)(e,t,r),o._QTS_GetSymbolDescriptionOrKey=(e,t)=>(o._QTS_GetSymbolDescriptionOrKey=q.Z)(e,t),o._QTS_IsGlobalSymbol=(e,t)=>(o._QTS_IsGlobalSymbol=q._)(e,t),o._QTS_IsJobPending=e=>(o._QTS_IsJobPending=q.$)(e),o._QTS_ExecutePendingJob=(e,t,r)=>(o._QTS_ExecutePendingJob=q.aa)(e,t,r),o._QTS_GetProp=(e,t,r)=>(o._QTS_GetProp=q.ba)(e,t,r),o._QTS_SetProp=(e,t,r,n)=>(o._QTS_SetProp=q.ca)(e,t,r,n),o._QTS_DefineProp=(e,t,r,n,a,i,_,u,l)=>(o._QTS_DefineProp=q.da)(e,t,r,n,a,i,_,u,l),o._QTS_Call=(e,t,r,n,a)=>(o._QTS_Call=q.ea)(e,t,r,n,a),o._QTS_ResolveException=(e,t)=>(o._QTS_ResolveException=q.fa)(e,t),o._QTS_Dump=(e,t)=>(o._QTS_Dump=q.ga)(e,t),o._QTS_Eval=(e,t,r,n,a,i)=>(o._QTS_Eval=q.ha)(e,t,r,n,a,i),o._QTS_GetModuleNamespace=(e,t)=>(o._QTS_GetModuleNamespace=q.ia)(e,t),o._QTS_Typeof=(e,t)=>(o._QTS_Typeof=q.ja)(e,t),o._QTS_GetGlobalObject=e=>(o._QTS_GetGlobalObject=q.ka)(e),o._QTS_NewPromiseCapability=(e,t)=>(o._QTS_NewPromiseCapability=q.la)(e,t),o._QTS_PromiseState=(e,t)=>(o._QTS_PromiseState=q.ma)(e,t),o._QTS_PromiseResult=(e,t)=>(o._QTS_PromiseResult=q.na)(e,t),o._QTS_TestStringArg=e=>(o._QTS_TestStringArg=q.oa)(e),o._QTS_BuildIsDebug=()=>(o._QTS_BuildIsDebug=q.pa)(),o._QTS_BuildIsAsyncify=()=>(o._QTS_BuildIsAsyncify=q.qa)(),o._QTS_NewFunction=(e,t,r)=>(o._QTS_NewFunction=q.ra)(e,t,r),o._QTS_ArgvGetJSValueConstPointer=(e,t)=>(o._QTS_ArgvGetJSValueConstPointer=q.sa)(e,t),o._QTS_RuntimeEnableInterruptHandler=e=>(o._QTS_RuntimeEnableInterruptHandler=q.ta)(e),o._QTS_RuntimeDisableInterruptHandler=e=>(o._QTS_RuntimeDisableInterruptHandler=q.ua)(e),o._QTS_RuntimeEnableModuleLoader=(e,t)=>(o._QTS_RuntimeEnableModuleLoader=q.va)(e,t),o._QTS_RuntimeDisableModuleLoader=e=>(o._QTS_RuntimeDisableModuleLoader=q.wa)(e),o._QTS_bjson_encode=(e,t)=>(o._QTS_bjson_encode=q.xa)(e,t),o._QTS_bjson_decode=(e,t)=>(o._QTS_bjson_decode=q.ya)(e,t);var X,Z=()=>(Z=q.Aa)(),ee=e=>(ee=q.Ba)(e),te=e=>(te=q.Ca)(e);function re(){function e(){if(!X&&(X=!0,o.calledRun=!0,!h)){if(O(A),t(o),o.onRuntimeInitialized&&o.onRuntimeInitialized(),o.postRun)for("function"==typeof o.postRun&&(o.postRun=[o.postRun]);o.postRun.length;){var e=o.postRun.shift();R.unshift(e)}O(R)}}if(!(0<F)){if(o.preRun)for("function"==typeof o.preRun&&(o.preRun=[o.preRun]);o.preRun.length;)P();O(w),0<F||(o.setStatus?(o.setStatus("Running..."),setTimeout((function(){setTimeout((function(){o.setStatus("")}),1),e()}),1)):e())}}if(o.___start_em_js=80788,o.___stop_em_js=81690,o.cwrap=(e,t,r,n)=>{var a=!r||r.every((e=>"number"===e||"boolean"===e));return"string"!==t&&a&&!n?o["_"+e]:function(){return((e,t,r,n)=>{var a={string:e=>{var t=0;if(null!=e&&0!==e){t=z(e)+1;var r=te(t);H(e,r,t),t=r}return t},array:e=>{var t=te(e.length);return d.set(e,t),t}};e=o["_"+e];var i,_=[],u=0;if(n)for(var l=0;l<n.length;l++){var s=a[r[l]];s?(0===u&&(u=Z()),_[l]=s(n[l])):_[l]=n[l]}return i=r=e.apply(null,_),0!==u&&ee(u),"string"===t?i?U(p,i):"":"boolean"===t?!!i:i})(e,t,r,arguments)}},o.UTF8ToString=(e,t)=>e?U(p,e,t):"",o.stringToUTF8=(e,t,r)=>H(e,t,r),o.lengthBytesUTF8=z,N=function e(){X||re(),X||(N=e)},o.preInit)for("function"==typeof o.preInit&&(o.preInit=[o.preInit]);0<o.preInit.length;)o.preInit.pop()();return re(),e.ready})}}]);
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[864],{864:(e,t,s)=>{s.r(t),s.d(t,{QuickJSAsyncWASMModule:()=>r});var i=s(915),n=class extends i.o{async evalCodeAsync(e,t="eval.js",s){let n=void 0===s?1:0,a=(0,i.n)(s),r=0;try{r=await this.memory.newHeapCharPointer(e).consume((e=>this.ffi.QTS_Eval_MaybeAsync(this.ctx.value,e.value.ptr,e.value.strlen,t,n,a)))}catch(e){throw(0,i.a)("QTS_Eval_MaybeAsync threw",e),e}let o=this.ffi.QTS_ResolveException(this.ctx.value,r);return o?(this.ffi.QTS_FreeValuePointer(this.ctx.value,r),{error:this.memory.heapValueHandle(o)}):{value:this.memory.heapValueHandle(r)}}newAsyncifiedFunction(e,t){return this.newFunction(e,t)}},a=class extends i.p{constructor(e){super(e)}newContext(e={}){let t=(0,i.m)(e.intrinsics),s=new i.g(this.ffi.QTS_NewContext(this.rt.value,t),void 0,(e=>{this.contextMap.delete(e),this.callbacks.deleteContext(e),this.ffi.QTS_FreeContext(e)})),a=new n({module:this.module,ctx:s,ffi:this.ffi,rt:this.rt,ownedLifetimes:[],runtime:this,callbacks:this.callbacks});return this.contextMap.set(s.value,a),a}setModuleLoader(e,t){super.setModuleLoader(e,t)}setMaxStackSize(e){return super.setMaxStackSize(e)}},r=class extends i.t{constructor(e,t){super(e,t),this.ffi=t,this.module=e}newRuntime(e={}){let t=new i.g(this.ffi.QTS_NewRuntime(),void 0,(e=>{this.callbacks.deleteRuntime(e),this.ffi.QTS_FreeRuntime(e)})),s=new a({module:this.module,ffi:this.ffi,rt:t,callbacks:this.callbacks});return(0,i.r)(s,e),e.moduleLoader&&s.setModuleLoader(e.moduleLoader),s}newContext(e={}){let t=this.newRuntime(),s=e.ownedLifetimes?e.ownedLifetimes.concat([t]):[t],i=t.newContext({...e,ownedLifetimes:s});return t.context=i,i}evalCode(){throw new i.b("QuickJSWASMModuleAsyncify.evalCode: use evalCodeAsync instead")}evalCodeAsync(e,t){return i.j.withScopeAsync((async s=>{let n=s.manage(this.newContext());(0,i.s)(n.runtime,t);let a=await n.evalCodeAsync(e,"eval.js");if(void 0!==t.memoryLimitBytes&&n.runtime.setMemoryLimit(-1),a.error)throw n.dump(s.manage(a.error));return n.dump(s.manage(a.value))}))}}}}]);
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[878],{878:(e,r,u)=>{u.r(r),u.d(r,{QuickJSFFI:()=>n});var n=class{constructor(e){this.module=e,this.DEBUG=!1,this.QTS_Throw=this.module.cwrap("QTS_Throw","number",["number","number"]),this.QTS_NewError=this.module.cwrap("QTS_NewError","number",["number"]),this.QTS_RuntimeSetMemoryLimit=this.module.cwrap("QTS_RuntimeSetMemoryLimit",null,["number","number"]),this.QTS_RuntimeComputeMemoryUsage=this.module.cwrap("QTS_RuntimeComputeMemoryUsage","number",["number","number"]),this.QTS_RuntimeDumpMemoryUsage=this.module.cwrap("QTS_RuntimeDumpMemoryUsage","number",["number"]),this.QTS_RecoverableLeakCheck=this.module.cwrap("QTS_RecoverableLeakCheck","number",[]),this.QTS_BuildIsSanitizeLeak=this.module.cwrap("QTS_BuildIsSanitizeLeak","number",[]),this.QTS_RuntimeSetMaxStackSize=this.module.cwrap("QTS_RuntimeSetMaxStackSize",null,["number","number"]),this.QTS_GetUndefined=this.module.cwrap("QTS_GetUndefined","number",[]),this.QTS_GetNull=this.module.cwrap("QTS_GetNull","number",[]),this.QTS_GetFalse=this.module.cwrap("QTS_GetFalse","number",[]),this.QTS_GetTrue=this.module.cwrap("QTS_GetTrue","number",[]),this.QTS_NewRuntime=this.module.cwrap("QTS_NewRuntime","number",[]),this.QTS_FreeRuntime=this.module.cwrap("QTS_FreeRuntime",null,["number"]),this.QTS_NewContext=this.module.cwrap("QTS_NewContext","number",["number","number"]),this.QTS_FreeContext=this.module.cwrap("QTS_FreeContext",null,["number"]),this.QTS_FreeValuePointer=this.module.cwrap("QTS_FreeValuePointer",null,["number","number"]),this.QTS_FreeValuePointerRuntime=this.module.cwrap("QTS_FreeValuePointerRuntime",null,["number","number"]),this.QTS_FreeVoidPointer=this.module.cwrap("QTS_FreeVoidPointer",null,["number","number"]),this.QTS_FreeCString=this.module.cwrap("QTS_FreeCString",null,["number","number"]),this.QTS_DupValuePointer=this.module.cwrap("QTS_DupValuePointer","number",["number","number"]),this.QTS_NewObject=this.module.cwrap("QTS_NewObject","number",["number"]),this.QTS_NewObjectProto=this.module.cwrap("QTS_NewObjectProto","number",["number","number"]),this.QTS_NewArray=this.module.cwrap("QTS_NewArray","number",["number"]),this.QTS_NewArrayBuffer=this.module.cwrap("QTS_NewArrayBuffer","number",["number","number","number"]),this.QTS_NewFloat64=this.module.cwrap("QTS_NewFloat64","number",["number","number"]),this.QTS_GetFloat64=this.module.cwrap("QTS_GetFloat64","number",["number","number"]),this.QTS_NewString=this.module.cwrap("QTS_NewString","number",["number","number"]),this.QTS_GetString=this.module.cwrap("QTS_GetString","number",["number","number"]),this.QTS_GetArrayBuffer=this.module.cwrap("QTS_GetArrayBuffer","number",["number","number"]),this.QTS_GetArrayBufferLength=this.module.cwrap("QTS_GetArrayBufferLength","number",["number","number"]),this.QTS_NewSymbol=this.module.cwrap("QTS_NewSymbol","number",["number","number","number"]),this.QTS_GetSymbolDescriptionOrKey=this.module.cwrap("QTS_GetSymbolDescriptionOrKey","number",["number","number"]),this.QTS_IsGlobalSymbol=this.module.cwrap("QTS_IsGlobalSymbol","number",["number","number"]),this.QTS_IsJobPending=this.module.cwrap("QTS_IsJobPending","number",["number"]),this.QTS_ExecutePendingJob=this.module.cwrap("QTS_ExecutePendingJob","number",["number","number","number"]),this.QTS_GetProp=this.module.cwrap("QTS_GetProp","number",["number","number","number"]),this.QTS_SetProp=this.module.cwrap("QTS_SetProp",null,["number","number","number","number"]),this.QTS_DefineProp=this.module.cwrap("QTS_DefineProp",null,["number","number","number","number","number","number","boolean","boolean","boolean"]),this.QTS_Call=this.module.cwrap("QTS_Call","number",["number","number","number","number","number"]),this.QTS_ResolveException=this.module.cwrap("QTS_ResolveException","number",["number","number"]),this.QTS_Dump=this.module.cwrap("QTS_Dump","number",["number","number"]),this.QTS_Eval=this.module.cwrap("QTS_Eval","number",["number","number","number","string","number","number"]),this.QTS_GetModuleNamespace=this.module.cwrap("QTS_GetModuleNamespace","number",["number","number"]),this.QTS_Typeof=this.module.cwrap("QTS_Typeof","number",["number","number"]),this.QTS_GetGlobalObject=this.module.cwrap("QTS_GetGlobalObject","number",["number"]),this.QTS_NewPromiseCapability=this.module.cwrap("QTS_NewPromiseCapability","number",["number","number"]),this.QTS_PromiseState=this.module.cwrap("QTS_PromiseState","number",["number","number"]),this.QTS_PromiseResult=this.module.cwrap("QTS_PromiseResult","number",["number","number"]),this.QTS_TestStringArg=this.module.cwrap("QTS_TestStringArg",null,["string"]),this.QTS_BuildIsDebug=this.module.cwrap("QTS_BuildIsDebug","number",[]),this.QTS_BuildIsAsyncify=this.module.cwrap("QTS_BuildIsAsyncify","number",[]),this.QTS_NewFunction=this.module.cwrap("QTS_NewFunction","number",["number","number","string"]),this.QTS_ArgvGetJSValueConstPointer=this.module.cwrap("QTS_ArgvGetJSValueConstPointer","number",["number","number"]),this.QTS_RuntimeEnableInterruptHandler=this.module.cwrap("QTS_RuntimeEnableInterruptHandler",null,["number"]),this.QTS_RuntimeDisableInterruptHandler=this.module.cwrap("QTS_RuntimeDisableInterruptHandler",null,["number"]),this.QTS_RuntimeEnableModuleLoader=this.module.cwrap("QTS_RuntimeEnableModuleLoader",null,["number","number"]),this.QTS_RuntimeDisableModuleLoader=this.module.cwrap("QTS_RuntimeDisableModuleLoader",null,["number"]),this.QTS_bjson_encode=this.module.cwrap("QTS_bjson_encode","number",["number","number"]),this.QTS_bjson_decode=this.module.cwrap("QTS_bjson_decode","number",["number","number"])}}}}]);
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[915],{915:(e,t,r)=>{r.d(t,{a:()=>o,b:()=>h,g:()=>P,j:()=>C,m:()=>A,n:()=>M,o:()=>R,p:()=>F,q:()=>B,r:()=>I,s:()=>N,t:()=>O});var i=r(422),s=Object.defineProperty,n=!1;function o(...e){n&&console.log(...e)}((e,t)=>{for(var r in t)s(e,r,{get:t[r],enumerable:!0})})({},{QuickJSAsyncifyError:()=>c,QuickJSAsyncifySuspended:()=>d,QuickJSEmscriptenModuleError:()=>f,QuickJSMemoryLeakDetected:()=>m,QuickJSNotImplemented:()=>h,QuickJSPromisePending:()=>v,QuickJSUnknownIntrinsic:()=>p,QuickJSUnwrapError:()=>a,QuickJSUseAfterFree:()=>u,QuickJSWrongOwner:()=>l});var a=class extends Error{constructor(e,t){super(String(e)),this.cause=e,this.context=t,this.name="QuickJSUnwrapError"}},l=class extends Error{constructor(){super(...arguments),this.name="QuickJSWrongOwner"}},u=class extends Error{constructor(){super(...arguments),this.name="QuickJSUseAfterFree"}},h=class extends Error{constructor(){super(...arguments),this.name="QuickJSNotImplemented"}},c=class extends Error{constructor(){super(...arguments),this.name="QuickJSAsyncifyError"}},d=class extends Error{constructor(){super(...arguments),this.name="QuickJSAsyncifySuspended"}},m=class extends Error{constructor(){super(...arguments),this.name="QuickJSMemoryLeakDetected"}},f=class extends Error{constructor(){super(...arguments),this.name="QuickJSEmscriptenModuleError"}},p=class extends TypeError{constructor(){super(...arguments),this.name="QuickJSUnknownIntrinsic"}},v=class extends Error{constructor(){super(...arguments),this.name="QuickJSPromisePending"}};function*y(e){return yield e}var w=y;function S(e,t){return(...r)=>g(t.call(e,w,...r))}function g(e){return function t(r){return r.done?r.value:r.value instanceof Promise?r.value.then((r=>t(e.next(r))),(r=>t(e.throw(r)))):t(e.next(r.value))}(e.next())}w.of=function(e){return y(g(e))};var x=class{[Symbol.dispose](){return this.dispose()}},b=Symbol.dispose??Symbol.for("Symbol.dispose"),_=x.prototype;_[b]||(_[b]=function(){return this.dispose()});var P=class e extends x{constructor(e,t,r,i){super(),this._value=e,this.copier=t,this.disposer=r,this._owner=i,this._alive=!0,this._constructorStack=n?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 e(this.copier(this._value),this.copier,this.disposer,this._owner)}consume(e){this.assertAlive();let t=e(this);return this.dispose(),t}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new u(`Lifetime not alive\n${this._constructorStack}\nLifetime used`):new u("Lifetime not alive")}},T=class extends P{constructor(e,t){super(e,void 0,void 0,t)}get dupable(){return!0}dup(){return this}dispose(){}},k=class extends P{constructor(e,t,r,i){super(e,t,r,i)}dispose(){this._alive=!1}};function Q(e,t){let r;try{e.dispose()}catch(e){r=e}if(t&&r)throw Object.assign(t,{message:`${t.message}\n Then, failed to dispose scope: ${r.message}`,disposeError:r}),t;if(t||r)throw t||r}var C=class e extends x{constructor(){super(...arguments),this._disposables=new P(new Set)}static withScope(t){let r,i=new e;try{return t(i)}catch(e){throw r=e,e}finally{Q(i,r)}}static withScopeMaybeAsync(t,r){return g(function*(i){let s,n=new e;try{return yield*i.of(r.call(t,i,n))}catch(e){throw s=e,e}finally{Q(n,s)}}.call(void 0,w))}static async withScopeAsync(t){let r,i=new e;try{return await t(i)}catch(e){throw r=e,e}finally{Q(i,r)}}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 t of e)t.alive&&t.dispose();this._disposables.dispose()}},E=class extends x{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((e=>{this.onSettled=e})),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()}},H=class{constructor(e){this.module=e}toPointerArray(e){let t=new Int32Array(e.map((e=>e.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 P(i,void 0,(e=>this.module._free(e)))}newMutablePointerArray(e){let t=new Int32Array(new Array(e).fill(0)),r=t.length*t.BYTES_PER_ELEMENT,i=this.module._malloc(r),s=new Int32Array(this.module.HEAPU8.buffer,i,e);return s.set(t),new P({typedArray:s,ptr:i},void 0,(e=>this.module._free(e.ptr)))}newHeapCharPointer(e){let t=this.module.lengthBytesUTF8(e),r=t+1,i=this.module._malloc(r);return this.module.stringToUTF8(e,i,r),new P({ptr:i,strlen:t},void 0,(e=>this.module._free(e.ptr)))}newHeapBufferPointer(e){let t=e.byteLength,r=this.module._malloc(t);return this.module.HEAPU8.set(e,r),new P({pointer:r,numBytes:t},void 0,(e=>this.module._free(e.pointer)))}consumeHeapCharPointer(e){let t=this.module.UTF8ToString(e);return this.module._free(e),t}};function A(e){if(!e)return 0;let t=0;for(let[r,s]of Object.entries(e)){if(!(r in i.qG))throw new p(r);s&&(t|=i.qG[r])}return t}function M(e){if("number"==typeof e)return e;if(void 0===e)return 0;let{type:t,strict:r,strip:s,compileOnly:n,backtraceBarrier:o}=e,a=0;return"global"===t&&(a|=i.WB.JS_EVAL_TYPE_GLOBAL),"module"===t&&(a|=i.WB.JS_EVAL_TYPE_MODULE),r&&(a|=i.WB.JS_EVAL_FLAG_STRICT),s&&(a|=i.WB.JS_EVAL_FLAG_STRIP),n&&(a|=i.WB.JS_EVAL_FLAG_COMPILE_ONLY),o&&(a|=i.WB.JS_EVAL_FLAG_BACKTRACE_BARRIER),a}function J(...e){let t=[];for(let r of e)void 0!==r&&(t=t.concat(r));return t}Symbol("Unstable"),Object.freeze({BaseObjects:!0,Date:!0,Eval:!0,StringNormalize:!0,RegExp:!0,JSON:!0,Proxy:!0,MapSet:!0,TypedArrays:!0,Promise:!0});var L=class extends H{constructor(e){super(e.module),this.scope=new C,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((e=>this.scope.manage(e))),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){return new P(e,this.copyJSValue,this.freeJSValue,this.owner)}},R=class extends x{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,t,r,i,s)=>{if(e!==this.ctx.value)throw new Error("QuickJSContext instance received C -> JS call with mismatched ctx");let n=this.getFunction(s);if(!n)throw new Error(`QuickJSContext had no callback with id ${s}`);return C.withScopeMaybeAsync(this,(function*(e,s){let a=s.manage(new k(t,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime)),l=new Array(r);for(let e=0;e<r;e++){let t=this.ffi.QTS_ArgvGetJSValueConstPointer(i,e);l[e]=s.manage(new k(t,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime))}try{let t=yield*e(n.apply(a,l));if(t){if("error"in t&&t.error)throw o("throw error",t.error),t.error;let e=s.manage(t instanceof P?t:t.value);return this.ffi.QTS_DupValuePointer(this.ctx.value,e.value)}return 0}catch(e){return this.errorToHandle(e).consume((e=>this.ffi.QTS_Throw(this.ctx.value,e.value)))}}))}},this.runtime=e.runtime,this.module=e.module,this.ffi=e.ffi,this.rt=e.rt,this.ctx=e.ctx,this.memory=new L({...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 T(e)}get null(){if(this._null)return this._null;let e=this.ffi.QTS_GetNull();return this._null=new T(e)}get true(){if(this._true)return this._true;let e=this.ffi.QTS_GetTrue();return this._true=new T(e)}get false(){if(this._false)return this._false;let e=this.ffi.QTS_GetFalse();return this._false=new T(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 T(e,this.runtime),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((e=>this.ffi.QTS_NewString(this.ctx.value,e.value.ptr)));return this.memory.heapValueHandle(t)}newUniqueSymbol(e){let t=("symbol"==typeof e?e.description:e)??"",r=this.memory.newHeapCharPointer(t).consume((e=>this.ffi.QTS_NewSymbol(this.ctx.value,e.value.ptr,0)));return this.memory.heapValueHandle(r)}newSymbolFor(e){let t=("symbol"==typeof e?e.description:e)??"",r=this.memory.newHeapCharPointer(t).consume((e=>this.ffi.QTS_NewSymbol(this.ctx.value,e.value.ptr,1)));return this.memory.heapValueHandle(r)}newBigInt(e){if(!this._BigInt){let e=this.getProp(this.global,"BigInt");this.memory.manage(e),this._BigInt=new T(e.value,this.runtime)}let t=this._BigInt,r=String(e);return this.newString(r).consume((e=>this.unwrapResult(this.callFunction(t,this.undefined,e))))}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)}newPromise(e){let t=C.withScope((e=>{let t=e.manage(this.memory.newMutablePointerArray(2)),r=this.ffi.QTS_NewPromiseCapability(this.ctx.value,t.value.ptr),i=this.memory.heapValueHandle(r),[s,n]=Array.from(t.value.typedArray).map((e=>this.memory.heapValueHandle(e)));return new E({context:this,promiseHandle:i,resolveHandle:s,rejectHandle:n})}));return e&&"function"==typeof e&&(e=new Promise(e)),e&&Promise.resolve(e).then(t.resolve,(e=>e instanceof P?t.reject(e):this.newError(e).consume(t.reject))),t}newFunction(e,t){let r=++this.fnNextId;return this.setFunction(r,t),this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value,r,e))}newError(e){let t=this.memory.heapValueHandle(this.ffi.QTS_NewError(this.ctx.value));return e&&"object"==typeof e?(void 0!==e.name&&this.newString(e.name).consume((e=>this.setProp(t,"name",e))),void 0!==e.message&&this.newString(e.message).consume((e=>this.setProp(t,"message",e)))):"string"==typeof e?this.newString(e).consume((e=>this.setProp(t,"message",e))):void 0!==e&&this.newString(String(e)).consume((e=>this.setProp(t,"message",e))),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 P(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===i.zd.Pending)return{type:"pending",get error(){return new v("Cannot unwrap a pending promise")}};let r=this.ffi.QTS_PromiseResult(this.ctx.value,e.value),s=this.memory.heapValueHandle(r);if(t===i.zd.Fulfilled)return{type:"fulfilled",value:s};if(t===i.zd.Rejected)return{type:"rejected",error:s};throw s.dispose(),new Error(`Unknown JSPromiseStateEnum: ${t}`)}resolvePromise(e){this.runtime.assertOwned(e);let t=C.withScope((t=>{let r=t.manage(this.getProp(this.global,"Promise")),i=t.manage(this.getProp(r,"resolve"));return this.callFunction(i,r,e)}));return t.error?Promise.resolve(t):new Promise((e=>{C.withScope((r=>{let i=r.manage(this.newFunction("resolve",(t=>{e({value:t&&t.dup()})}))),s=r.manage(this.newFunction("reject",(t=>{e({error:t&&t.dup()})}))),n=r.manage(t.value),o=r.manage(this.getProp(n,"then"));this.unwrapResult(this.callFunction(o,n,i,s)).dispose()}))}))}getProp(e,t){this.runtime.assertOwned(e);let r=this.borrowPropertyKey(t).consume((t=>this.ffi.QTS_GetProp(this.ctx.value,e.value,t.value)));return this.memory.heapValueHandle(r)}setProp(e,t,r){this.runtime.assertOwned(e),this.borrowPropertyKey(t).consume((t=>this.ffi.QTS_SetProp(this.ctx.value,e.value,t.value,r.value)))}defineProp(e,t,r){this.runtime.assertOwned(e),C.withScope((i=>{let s=i.manage(this.borrowPropertyKey(t)),n=r.value||this.undefined,o=!!r.configurable,a=!!r.enumerable,l=!!r.value,u=r.get?i.manage(this.newFunction(r.get.name,r.get)):this.undefined,h=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,u.value,h.value,o,a,l)}))}callFunction(e,t,...r){this.runtime.assertOwned(e);let i=this.memory.toPointerArray(r).consume((i=>this.ffi.QTS_Call(this.ctx.value,e.value,t.value,r.length,i.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,t="eval.js",r){let i=void 0===r?1:0,s=M(r),n=this.memory.newHeapCharPointer(e).consume((e=>this.ffi.QTS_Eval(this.ctx.value,e.value.ptr,e.value.strlen,t,i,s))),o=this.ffi.QTS_ResolveException(this.ctx.value,n);return o?(this.ffi.QTS_FreeValuePointer(this.ctx.value,n),{error:this.memory.heapValueHandle(o)}):{value:this.memory.heapValueHandle(n)}}throw(e){return this.errorToHandle(e).consume((e=>this.ffi.QTS_Throw(this.ctx.value,e.value)))}borrowPropertyKey(e){return"number"==typeof e?this.newNumber(e):"string"==typeof e?this.newString(e):new T(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("string"===t)return this.getString(e);if("number"===t)return this.getNumber(e);if("bigint"===t)return this.getBigInt(e);if("undefined"===t)return;if("symbol"===t)return this.getSymbol(e);let r=this.getPromiseState(e);if("fulfilled"===r.type&&!r.notAPromise)return e.dispose(),{type:r.type,value:r.value.consume(this.dump)};if("pending"===r.type)return e.dispose(),{type:r.type};if("rejected"===r.type)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((e=>this.dump(e)));if(r&&"object"==typeof r&&"string"==typeof r.message){let{message:e,name:i,stack:s}=r,n=new a(""),o=n.stack;throw"string"==typeof i&&(n.name=r.name),"string"==typeof s&&(n.stack=`${i}: ${e}\n${r.stack}Host: ${o}`),Object.assign(n,{cause:r,context:t,message:e}),n}throw new a(r,t)}return e.value}getFunction(e){let t=e>>8,r=this.fnMaps.get(t);if(r)return r.get(e)}setFunction(e,t){let r=e>>8,i=this.fnMaps.get(r);return i||(i=new Map,this.fnMaps.set(r,i)),i.set(e,t)}errorToHandle(e){return e instanceof P?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)}},F=class extends x{constructor(e){super(),this.scope=new C,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 t=this.interruptHandler;if(!t)throw new Error("QuickJSContext had no interrupt handler");return t(this)?1:0},loadModuleSource:S(this,(function*(e,t,r,i){let s=this.moduleLoader;if(!s)throw new Error("Runtime has no module loader");if(t!==this.rt.value)throw new Error("Runtime pointer mismatch");let n=this.contextMap.get(r)??this.newContext({contextPointer:r});try{let t=yield*e(s(i,n));if("object"==typeof t&&"error"in t&&t.error)throw o("cToHostLoadModule: loader returned error",t.error),t.error;let r="string"==typeof t?t:"value"in t?t.value:t;return this.memory.newHeapCharPointer(r).value.ptr}catch(e){return o("cToHostLoadModule: caught error",e),n.throw(e),0}})),normalizeModule:S(this,(function*(e,t,r,i,s){let n=this.moduleNormalizer;if(!n)throw new Error("Runtime has no module normalizer");if(t!==this.rt.value)throw new Error("Runtime pointer mismatch");let a=this.contextMap.get(r)??this.newContext({contextPointer:r});try{let t=yield*e(n(i,s,a));if("object"==typeof t&&"error"in t&&t.error)throw o("cToHostNormalizeModule: normalizer returned error",t.error),t.error;let r="string"==typeof t?t:t.value;return a.getMemory(this.rt.value).newHeapCharPointer(r).value.ptr}catch(e){return o("normalizeModule: caught error",e),a.throw(e),0}}))},e.ownedLifetimes?.forEach((e=>this.scope.manage(e))),this.module=e.module,this.memory=new H(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=A(e.intrinsics),r=new P(e.contextPointer||this.ffi.QTS_NewContext(this.rt.value,t),void 0,(e=>{this.contextMap.delete(e),this.callbacks.deleteContext(e),this.ffi.QTS_FreeContext(e)})),i=new R({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(),0===i)return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value,r),{value:0};let s=this.contextMap.get(i)??this.newContext({contextPointer:i}),n=s.getMemory(this.rt.value).heapValueHandle(r);if("number"===s.typeof(n)){let e=s.getNumber(n);return n.dispose(),{value:e}}return{error:Object.assign(n,{context:s})}}setMemoryLimit(e){if(e<0&&-1!==e)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 l(`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}},V=class{constructor(e){this.callFunction=e.callFunction,this.shouldInterrupt=e.shouldInterrupt,this.loadModuleSource=e.loadModuleSource,this.normalizeModule=e.normalizeModule}},B=class{constructor(e){this.contextCallbacks=new Map,this.runtimeCallbacks=new Map,this.suspendedCount=0,this.cToHostCallbacks=new V({callFunction:(e,t,r,i,s,n)=>this.handleAsyncify(e,(()=>{try{let e=this.contextCallbacks.get(t);if(!e)throw new Error(`QuickJSContext(ctx = ${t}) not found for C function call "${n}"`);return e.callFunction(t,r,i,s,n)}catch(e){return console.error("[C to host error: returning null]",e),0}})),shouldInterrupt:(e,t)=>this.handleAsyncify(e,(()=>{try{let e=this.runtimeCallbacks.get(t);if(!e)throw new Error(`QuickJSRuntime(rt = ${t}) not found for C interrupt`);return e.shouldInterrupt(t)}catch(e){return console.error("[C to host interrupt: returning error]",e),1}})),loadModuleSource:(e,t,r,i)=>this.handleAsyncify(e,(()=>{try{let e=this.runtimeCallbacks.get(t);if(!e)throw new Error(`QuickJSRuntime(rt = ${t}) not found for C module loader`);let s=e.loadModuleSource;if(!s)throw new Error(`QuickJSRuntime(rt = ${t}) does not support module loading`);return s(t,r,i)}catch(e){return console.error("[C to host module loader error: returning null]",e),0}})),normalizeModule:(e,t,r,i,s)=>this.handleAsyncify(e,(()=>{try{let e=this.runtimeCallbacks.get(t);if(!e)throw new Error(`QuickJSRuntime(rt = ${t}) not found for C module loader`);let n=e.normalizeModule;if(!n)throw new Error(`QuickJSRuntime(rt = ${t}) does not support module loading`);return n(t,r,i,s)}catch(e){return console.error("[C to host module loader error: returning null]",e),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((e=>{try{let r=t();if(!(r instanceof Promise))return o("asyncify.handleSleep: not suspending:",r),void e(r);if(this.suspended)throw new c(`Already suspended at: ${this.suspended.stack}\nAttempted to suspend at:`);this.suspended=new d(`(${this.suspendedCount++})`),o("asyncify.handleSleep: suspending:",this.suspended),r.then((t=>{this.suspended=void 0,o("asyncify.handleSleep: resolved:",t),e(t)}),(e=>{o("asyncify.handleSleep: rejected:",e),console.error("QuickJS: cannot handle error in suspended function",e),this.suspended=void 0}))}catch(e){throw o("asyncify.handleSleep: error:",e),this.suspended=void 0,e}}));let r=t();if(r instanceof Promise)throw new Error("Promise return value not supported in non-asyncify context.");return r}};function I(e,t){t.interruptHandler&&e.setInterruptHandler(t.interruptHandler),void 0!==t.maxStackSizeBytes&&e.setMaxStackSize(t.maxStackSizeBytes),void 0!==t.memoryLimitBytes&&e.setMemoryLimit(t.memoryLimitBytes)}function N(e,t){t.moduleLoader&&e.setModuleLoader(t.moduleLoader),t.shouldInterrupt&&e.setInterruptHandler(t.shouldInterrupt),void 0!==t.memoryLimitBytes&&e.setMemoryLimit(t.memoryLimitBytes),void 0!==t.maxStackSizeBytes&&e.setMaxStackSize(t.maxStackSizeBytes)}var O=class{constructor(e,t){this.module=e,this.ffi=t,this.callbacks=new B(e)}newRuntime(e={}){let t=new P(this.ffi.QTS_NewRuntime(),void 0,(e=>{this.callbacks.deleteRuntime(e),this.ffi.QTS_FreeRuntime(e)})),r=new F({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:t});return I(r,e),e.moduleLoader&&r.setModuleLoader(e.moduleLoader),r}newContext(e={}){let t=this.newRuntime(),r=t.newContext({...e,ownedLifetimes:J(t,e.ownedLifetimes)});return t.context=r,r}evalCode(e,t={}){return C.withScope((r=>{let i=r.manage(this.newContext());N(i.runtime,t);let s=i.evalCode(e,"eval.js");if(void 0!==t.memoryLimitBytes&&i.runtime.setMemoryLimit(-1),s.error)throw i.dump(r.manage(s.error));return i.dump(r.manage(s.value))}))}getWasmMemory(){let e=this.module.quickjsEmscriptenInit?.((()=>{}))?.getWasmMemory?.();if(!e)throw new Error("Variant does not support getting WebAssembly.Memory");return e}getFFI(){return this.ffi}}}}]);
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[966],{966:(e,u,l)=>{l.r(u),l.d(u,{QuickJSModuleCallbacks:()=>s.q,QuickJSWASMModule:()=>s.t,applyBaseRuntimeOptions:()=>s.r,applyModuleEvalRuntimeOptions:()=>s.s});var s=l(915)}}]);
(()=>{"use strict";var e,t={422:(e,t,r)=>{r.d(t,{WB:()=>n,qG:()=>o,zd:()=>i});var n={JS_EVAL_TYPE_GLOBAL:0,JS_EVAL_TYPE_MODULE:1,JS_EVAL_TYPE_DIRECT:2,JS_EVAL_TYPE_INDIRECT:3,JS_EVAL_TYPE_MASK:3,JS_EVAL_FLAG_STRICT:8,JS_EVAL_FLAG_STRIP:16,JS_EVAL_FLAG_COMPILE_ONLY:32,JS_EVAL_FLAG_BACKTRACE_BARRIER:64},o={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},i={Pending:0,Fulfilled:1,Rejected:2}}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.m=t,n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce(((t,r)=>(n.f[r](e,t),t)),[])),n.u=e=>e+".quickjs.js",n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},n.l=(t,r,o,i)=>{if(e[t])e[t].push(r);else{var a,l;if(void 0!==o)for(var u=document.getElementsByTagName("script"),d=0;d<u.length;d++){var c=u[d];if(c.getAttribute("src")==t){a=c;break}}a||(l=!0,(a=document.createElement("script")).charset="utf-8",a.timeout=120,n.nc&&a.setAttribute("nonce",n.nc),a.src=t),e[t]=[r];var s=(r,n)=>{a.onerror=a.onload=null,clearTimeout(f);var o=e[t];if(delete e[t],a.parentNode&&a.parentNode.removeChild(a),o&&o.forEach((e=>e(n))),r)return r(n)},f=setTimeout(s.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=s.bind(null,a.onerror),a.onload=s.bind(null,a.onload),l&&document.head.appendChild(a)}},n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;n.g.importScripts&&(e=n.g.location+"");var t=n.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var o=r.length-1;o>-1&&(!e||!/^http(s?):/.test(e));)e=r[o--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),(()=>{n.b=document.baseURI||self.location.href;var e={792:0};n.f.j=(t,r)=>{var o=n.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else{var i=new Promise(((r,n)=>o=e[t]=[r,n]));r.push(o[2]=i);var a=n.p+n.u(t),l=new Error;n.l(a,(r=>{if(n.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var i=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;l.message="Loading chunk "+t+" failed.\n("+i+": "+a+")",l.name="ChunkLoadError",l.type=i,l.request=a,o[1](l)}}),"chunk-"+t,t)}};var t=(t,r)=>{var o,i,[a,l,u]=r,d=0;if(a.some((t=>0!==e[t]))){for(o in l)n.o(l,o)&&(n.m[o]=l[o]);u&&u(n)}for(t&&t(r);d<a.length;d++)i=a[d],n.o(e,i)&&e[i]&&e[i][0](),e[i]=0},r=self.webpackChunk=self.webpackChunk||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})(),(()=>{function e(e){return e&&"default"in e&&e.default?e.default&&"default"in e.default&&e.default.default?e.default.default:e.default:e}n(422);var t,r={type:"sync",importFFI:()=>n.e(878).then(n.bind(n,878)).then((e=>e.QuickJSFFI)),importModuleLoader:()=>n.e(338).then(n.bind(n,338)).then((e=>e.default))};window.getQuickJS=async function(){return t??(t=async function(t=r){return async function(t){let r=e(await t),[o,i,{QuickJSWASMModule:a}]=await Promise.all([r.importModuleLoader().then(e),r.importFFI(),Promise.all([n.e(915),n.e(966)]).then(n.bind(n,966)).then(e)]),l=await o();return l.type="sync",new a(l,new i(l))}(t)}().then((e=>e))),await t}})()})();
@justjake
Copy link

justjake commented Mar 21, 2024

quickjs-emscripten library author here.

If you're okay with CDN builds of this library, you can see these examples:

If you want a single file build to avoid relying on a CDN, I think downloading it from jsdelivr works great:

curl 'https://cdn.jsdelivr.net/npm/[email protected]/dist/index.global.js' > quickjs.js

If anyone is interested in a global js library built published via Github Releases, let me know by submitting an issue here: https://github.com/justjake/quickjs-emscripten/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment