wry-bindgen-runtime 0.1.0-alpha.8

Wry runtime transport for wry-bindgen semantic bindings
Documentation
1
class DeferredHeapRefs{constructor(heap){this.heap=heap,this.values=[],this.resolved=!1,this.enqueued=!1,this.nextInstallIndex=0}count(){return this.values.length}push(value){if(this.resolved)throw Error("Deferred heap refs already resolved");if(this.nextInstallIndex!==0)throw Error("Cannot add heap refs after install has started");if(!this.enqueued)this.enqueued=!0,this.heap.enqueueDeferredHeapRefs(this);this.values.push(value)}isEmpty(){return this.values.length===0}resolve(ids){if(this.resolved)throw Error("Deferred heap refs already resolved");let remaining=this.values.length-this.nextInstallIndex;if(ids.length>remaining)throw Error(`Heap-ref install count mismatch: ${ids.length} IDs for ${remaining} remaining values`);for(let i=0;i<ids.length;i++)this.heap.insertAt(ids[i],this.values[this.nextInstallIndex+i]);this.nextInstallIndex+=ids.length,this.resolved=this.nextInstallIndex===this.values.length}isResolved(){return this.resolved}}class JSHeap{constructor(){this.slots=new Map,this.slots.set(129,null),this.slots.set(130,!0),this.slots.set(131,!1),this.slots.set(128,void 0),this.heapObjectCount=0,this.borrowStackPointer=128,this.borrowFrameStack=[],this.reservationStack=[],this.deferredHeapRefs=[],this.takingOwnership=!1}insertAt(id,value){if(id<132)throw Error(`Cannot install heap ref into special slot ${id}`);if(id>=132&&!this.slots.has(id))this.heapObjectCount++;this.slots.set(id,value)}deferHeapRefs(){return new DeferredHeapRefs(this)}enqueueDeferredHeapRefs(refs){this.deferredHeapRefs.push(refs)}resolveDeferredHeapRefs(ids){let refs=this.deferredHeapRefs[this.deferredHeapRefs.length-1];if(!refs)throw Error("Received an install batch but no deferred heap-ref frame is pending");if(refs.resolve(ids),refs.isResolved())this.deferredHeapRefs.pop()}pushReservationScope(ids){this.reservationStack.push({ids,nextIndex:0});for(let id of ids){if(id<132)throw Error(`Cannot reserve special heap slot ${id}`);if(this.slots.has(id))throw Error(`Reserved heap slot ${id} is already occupied`)}}popReservationScope(validate=!0){let scope=this.reservationStack.pop();if(validate&&scope&&scope.nextIndex!==scope.ids.length)throw Error(`Only filled ${scope.nextIndex} of ${scope.ids.length} reserved heap slots`)}fillNextReserved(value){let scope=this.reservationStack[this.reservationStack.length-1];if(!scope||scope.nextIndex>=scope.ids.length)throw Error("No reserved slots available");let id=scope.ids[scope.nextIndex];scope.nextIndex++,this.insertAt(id,value)}setTakingOwnership(value){this.takingOwnership=value}isTakingOwnership(){return this.takingOwnership}get(id){return this.slots.get(id)}remove(id){if(id<132)return this.slots.get(id);if(!this.has(id))return;let value=this.slots.get(id);return this.slots.delete(id),this.heapObjectCount--,value}has(id){return this.slots.has(id)}heapObjectsAlive(){return this.heapObjectCount}addBorrowedRef(obj){if(this.borrowStackPointer<=1)throw Error("Borrow stack overflow: too many borrowed references in a single operation");return this.borrowStackPointer--,this.slots.set(this.borrowStackPointer,obj),this.borrowStackPointer}pushBorrowFrame(){this.borrowFrameStack.push(this.borrowStackPointer)}popBorrowFrame(){let savedPointer=this.borrowFrameStack.pop();if(savedPointer!==void 0){for(let i=this.borrowStackPointer;i<savedPointer;i++)this.slots.delete(i);this.borrowStackPointer=savedPointer}}}class DataEncoder{constructor(heapRefs){this.u8Buf=[],this.u16Buf=[],this.u32Buf=[],this.strBuf=[],this.heapRefs=heapRefs}pushU8(value){this.u8Buf.push(value&255)}pushU16(value){this.u16Buf.push(value&65535)}pushU32(value){this.u32Buf.push(value>>>0)}pushU64(value){if(typeof value==="bigint"){let v=BigInt.asUintN(64,value);this.pushU32(Number(v&0xffffffffn)),this.pushU32(Number(v>>32n));return}let low=value>>>0,high=Math.floor(value/4294967296)>>>0;this.pushU32(low),this.pushU32(high)}pushU128(value){if(typeof value==="bigint"){let v=BigInt.asUintN(128,value);this.pushU64(v&0xffffffffffffffffn),this.pushU64(v>>64n);return}let low=value>>>0,high=Math.floor(value/18446744073709552000)>>>0;this.pushU64(low),this.pushU64(high)}pushF32(value){let floatBuf=new Float32Array(1);floatBuf[0]=value;let intBuf=new Uint32Array(floatBuf.buffer);this.pushU32(intBuf[0])}pushF64(value){let floatBuf=new Float64Array(1);floatBuf[0]=value;let intBuf=new Uint32Array(floatBuf.buffer);this.pushU32(intBuf[0]),this.pushU32(intBuf[1])}pushStr(value){let encoded=new TextEncoder().encode(value);this.pushU32(encoded.length);for(let i=0;i<encoded.length;i++)this.strBuf.push(encoded[i])}pushHeapRef(value){if(!this.heapRefs)throw Error("Cannot encode JS heap ref without a Rust allocation request");this.heapRefs.push(value)}finalize(){let u16Offset=12+this.u32Buf.length*4,u8Offset=u16Offset+this.u16Buf.length*2,strOffset=u8Offset+this.u8Buf.length,totalSize=strOffset+this.strBuf.length,buffer=new ArrayBuffer(totalSize),dataView=new DataView(buffer);dataView.setUint32(0,u16Offset,!0),dataView.setUint32(4,u8Offset,!0),dataView.setUint32(8,strOffset,!0);let offset=12;for(let val of this.u32Buf)dataView.setUint32(offset,val,!0),offset+=4;for(let val of this.u16Buf)dataView.setUint16(offset,val,!0),offset+=2;return new Uint8Array(buffer,u8Offset,this.u8Buf.length).set(this.u8Buf),new Uint8Array(buffer,strOffset,this.strBuf.length).set(this.strBuf),buffer}}class DataDecoder{constructor(data){let headerView=new DataView(data,0,12),u16ByteOffset=headerView.getUint32(0,!0),u8ByteOffset=headerView.getUint32(4,!0),strByteOffset=headerView.getUint32(8,!0),u32ByteLength=u16ByteOffset-12;this.u32Buf=new Uint32Array(data,12,u32ByteLength/4),this.u32Offset=0;let u16ByteLength=u8ByteOffset-u16ByteOffset;this.u16Buf=new Uint16Array(data,u16ByteOffset,u16ByteLength/2),this.u16Offset=0;let u8ByteLength=strByteOffset-u8ByteOffset;this.u8Buf=new Uint8Array(data,u8ByteOffset,u8ByteLength),this.u8Offset=0;let strBuf=new Uint8Array(data,strByteOffset);this.strBuf=new TextDecoder("utf-8").decode(strBuf),this.strOffset=0}takeU8(){return this.u8Buf[this.u8Offset++]}takeU16(){return this.u16Buf[this.u16Offset++]}takeU32(){return this.u32Buf[this.u32Offset++]}hasMoreU32(){return this.u32Offset<this.u32Buf.length}takeU64(){let low=this.takeU32(),high=this.takeU32();return low+high*4294967296}takeU128(){let low=this.takeU64(),high=this.takeU64();return low+high*18446744073709552000}takeF32(){let intVal=this.takeU32(),intBuf=new Uint32Array(1);return intBuf[0]=intVal,new Float32Array(intBuf.buffer)[0]}takeF64(){let low=this.takeU32(),high=this.takeU32(),intBuf=new Uint32Array(2);return intBuf[0]=low,intBuf[1]=high,new Float64Array(intBuf.buffer)[0]}takeStr(){let len=this.takeU32(),str=this.strBuf.substring(this.strOffset,this.strOffset+len);return this.strOffset+=len,str}takeI8(){let unsigned=this.takeU8();return unsigned>127?unsigned-256:unsigned}takeI16(){let unsigned=this.takeU16();return unsigned>32767?unsigned-65536:unsigned}takeI32(){return this.takeU32()|0}takeI64(){let low=this.takeU32(),signedHigh=this.takeU32()|0;return low+signedHigh*4294967296}takeI128(){let low=this.takeU64(),signedHigh=this.takeU64()|0;return low+signedHigh*18446744073709552000}takeBigUint64(){let low=BigInt(this.takeU32()),high=BigInt(this.takeU32());return low|high<<32n}takeBigInt64(){return BigInt.asIntN(64,this.takeBigUint64())}takeBigUint128(){let low=this.takeBigUint64(),high=this.takeBigUint64();return low|high<<64n}takeBigInt128(){return BigInt.asIntN(128,this.takeBigUint128())}getRemainingBytes(){return this.u8Buf.subarray(this.u8Offset)}skipBytes(count){this.u8Offset+=count}isEmpty(){return this.u8Offset>=this.u8Buf.length&&this.u16Offset>=this.u16Buf.length&&this.u32Offset>=this.u32Buf.length&&this.strOffset>=this.strBuf.length}}var functionRegistry=null,typeCache=new Map;function getFunctionRegistry(){return functionRegistry}function setFunctionRegistry(registry){functionRegistry=registry}function getTypeCache(){return typeCache}function dropNativeRef(fnId){sendEvaluateToRust((encoder)=>{encoder.pushU32(DROP_NATIVE_REF_FN_ID),encoder.pushU32(fnId)})}var nativeRefRegistry=new FinalizationRegistry((fnId)=>{dropNativeRef(fnId)});class RustFunction{constructor(fnId,paramTypes,returnType,policy){if(this.fnId=fnId,this.paramTypes=paramTypes,this.returnType=returnType,this.dropAfterCall=policy===2,this.disposed=!1,this.activeCalls=0,this.dropNativeWhenIdle=!1,this.finalizerToken=null,policy!==0)this.finalizerToken={},nativeRefRegistry.register(this,fnId,this.finalizerToken)}call(...args){if(this.disposed)throw Error("closure invoked recursively or after being dropped");this.activeCalls++,window.jsHeap.pushBorrowFrame();let result=null;try{result=sendEvaluateToRust((encoder)=>{encoder.pushU32(0),encoder.pushU32(this.fnId);for(let i=0;i<this.paramTypes.length;i++)this.paramTypes[i].encode(encoder,args[i])})}finally{window.jsHeap.popBorrowFrame(),this.activeCalls--,this.dropNativeRefIfIdle()}let decoded=this.returnType.decode(result);if(result&&!result.isEmpty())throw Error("Unprocessed data remaining after RustFunction call");if(this.dropAfterCall&&this.finalizerToken)nativeRefRegistry.unregister(this.finalizerToken),this.finalizerToken=null,this.disposed=!0;return decoded}disposeFromRust(){if(this.disposed)return;if(this.disposed=!0,this.dropAfterCall&&this.activeCalls!==0){if(this.finalizerToken)nativeRefRegistry.unregister(this.finalizerToken),this.finalizerToken=null;return}this.dropNativeWhenIdle=!0,this.dropNativeRefIfIdle()}dropNativeRefIfIdle(){if(!this.dropNativeWhenIdle||this.activeCalls!==0)return;if(this.dropNativeWhenIdle=!1,this.finalizerToken)nativeRefRegistry.unregister(this.finalizerToken),this.finalizerToken=null;dropNativeRef(this.fnId)}}class BoolType{encode(encoder,value){encoder.pushU8(value?1:0)}decode(decoder){return decoder.takeU8()!==0}}class HeapRefType{encode(encoder,obj){encoder.pushHeapRef(obj)}decode(decoder){let id=decoder.takeU64();if(!window.jsHeap.has(id))throw Error(`Unknown JS heap reference ID: ${id}`);return window.jsHeap.isTakingOwnership()?window.jsHeap.remove(id):window.jsHeap.get(id)}}class RustValueType{className;constructor(className=""){this.className=className}encode(encoder,obj){if(obj!=null&&obj.__handle===0)throw Error("Attempt to use a moved value");if(obj!=null&&this.className){let slot=obj["__wbg_ptr_"+this.className];if(typeof slot==="number"&&slot!==obj.__handle)throw TypeError(`${this.className}: cannot be consumed by-value as its ancestor`)}encoder.pushHeapRef(obj)}decode(decoder){return heapRefTypeInstance.decode(decoder)}}class BorrowedRefType{encode(encoder,obj){window.jsHeap.addBorrowedRef(obj)}decode(decoder){let id=decoder.takeU64();if(!window.jsHeap.has(id))throw Error(`Unknown borrowed JS reference ID: ${id}`);return window.jsHeap.get(id)}}class RustBorrowType{className;constructor(className){this.className=className}encode(encoder,obj){if(obj==null)throw TypeError(`expected a ${this.className} instance, got null`);if(obj.__handle===0)throw Error("Attempt to use a moved value");let slot=obj["__wbg_ptr_"+this.className],handle=typeof slot==="number"?slot:obj.__handle;encoder.pushU32(handle)}decode(_decoder){throw Error("RustBorrow is an argument-only wire type")}}class StringType{encode(encoder,value){encoder.pushStr(value)}decode(decoder){return decoder.takeStr()}}class CharType{encode(encoder,c){encoder.pushU32(c.codePointAt(0)??0)}decode(decoder){return String.fromCodePoint(decoder.takeU32())}}class StringEnumType{constructor(lookupArray){this.lookupArray=lookupArray}encode(encoder,value){let index=this.lookupArray.indexOf(value),encoded=index>=0?index:this.lookupArray.length;encoder.pushU32(encoded)}decode(decoder){let index=decoder.takeU32();return this.lookupArray[index]}}class NumericEnumType{constructor(signed,values){this.signed=signed,this.values=new Set(values)}encode(encoder,value){if(typeof value!=="number"||!this.values.has(value))throw Error("the value provided is not a valid enum value");encoder.pushU32(value>>>0)}decode(decoder){return this.signed?decoder.takeI32():decoder.takeU32()}}class DynamicUnionType{constructor(variants){this.variants=variants}encode(encoder,value){heapRefTypeInstance.encode(encoder,value)}decode(decoder){let index=decoder.takeU8(),variant=this.variants[index];if(variant===void 0)throw Error(`Invalid dynamic union variant index: ${index}`);if(variant.kind==="string")return variant.value;return variant.type.decode(decoder)}}class CallbackType{constructor(paramTypes,returnType){this.paramTypes=paramTypes,this.returnType=returnType}encode(encoder,fnId){encoder.pushU32(fnId)}decode(decoder){let fnId=decoder.takeU32(),policy=decoder.takeU32(),rustFunction=new RustFunction(fnId,this.paramTypes,this.returnType,policy),callable=(...args)=>rustFunction.call(...args);return Object.defineProperty(callable,"__wryRustFunction",{value:rustFunction}),callable}}class UndefinedType{encode(encoder,value){}decode(decoder){return}}class NumericType{constructor(size){this.size=size}encode(encoder,value){switch(this.size){case"u8":encoder.pushU8(Number(value));break;case"u16":encoder.pushU16(Number(value));break;case"u32":encoder.pushU32(Number(value));break;case"u64":encoder.pushU64(value);break;case"u128":encoder.pushU128(value);break;case"i8":encoder.pushU8(Number(value)&255);break;case"i16":encoder.pushU16(Number(value)&65535);break;case"i32":encoder.pushU32(Number(value)>>>0);break;case"i64":encoder.pushU64(value);break;case"i128":encoder.pushU128(value);break;case"usize":encoder.pushU64(Number(value));break;case"isize":encoder.pushU64(Number(value));break;case"f32":encoder.pushF32(Number(value));break;case"f64":encoder.pushF64(Number(value));break}}decode(decoder){switch(this.size){case"u8":return decoder.takeU8();case"u16":return decoder.takeU16();case"u32":return decoder.takeU32();case"u64":return decoder.takeBigUint64();case"u128":return decoder.takeBigUint128();case"i8":return decoder.takeI8();case"i16":return decoder.takeI16();case"i32":return decoder.takeI32();case"i64":return decoder.takeBigInt64();case"i128":return decoder.takeBigInt128();case"usize":return decoder.takeU64();case"isize":return decoder.takeI64();case"f32":return decoder.takeF32();case"f64":return decoder.takeF64()}}}class OptionType{constructor(wrappedType){this.wrappedType=wrappedType}encode(encoder,value){if(value===null||value===void 0)encoder.pushU8(0);else encoder.pushU8(1),this.wrappedType.encode(encoder,value)}decode(decoder){if(decoder.takeU8()===0)return;else return this.wrappedType.decode(decoder)}appendWriteBack(encoder,value){if(value!==null&&value!==void 0)this.wrappedType.appendWriteBack?.(encoder,value)}}class ResultType{constructor(okType,errType){this.okType=okType,this.errType=errType}encode(encoder,value){let result=value;if("ok"in result)encoder.pushU8(1),this.okType.encode(encoder,result.ok);else if("err"in result)encoder.pushU8(0),this.errType.encode(encoder,result.err);else throw Error("Invalid RustType value: must be Ok or Err")}decode(decoder){if(decoder.takeU8()===1)return{ok:this.okType.decode(decoder)};else return{err:this.errType.decode(decoder)}}}class ThrowingResultType{constructor(okType,errType){this.okType=okType,this.errType=errType}encode(encoder,value){let result=value;if("ok"in result)encoder.pushU8(1),this.okType.encode(encoder,result.ok);else if("err"in result)encoder.pushU8(0),this.errType.encode(encoder,result.err);else throw Error("Invalid RustType value: must be Ok or Err")}decode(decoder){if(decoder.takeU8()===1)return this.okType.decode(decoder);throw this.errType.decode(decoder)}}class ArrayType{constructor(elementType){this.elementType=elementType}encode(encoder,value){encoder.pushU32(value.length);for(let element of value)try{this.elementType.encode(encoder,element)}catch{throw Error("array contains a value of the wrong type")}}decode(decoder){let length=decoder.takeU32(),result=[];for(let i=0;i<length;i++)result.push(this.elementType.decode(decoder));return result}}class MutArrayType{constructor(inner){this.inner=inner}encode(encoder,value){this.inner.encode(encoder,value)}decode(decoder){return this.inner.decode(decoder)}copyBack(decoder,target){let updated=this.inner.decode(decoder),count=Math.min(target.length,updated.length);for(let i=0;i<count;i++)target[i]=updated[i]}appendWriteBack(encoder,value){this.inner.encode(encoder,value)}}class U8ClampedType{encode(encoder,value){encoder.pushU32(value.length);for(let i=0;i<value.length;i++)encoder.pushU8(value[i])}decode(decoder){let length=decoder.takeU32(),result=new Uint8ClampedArray(length);for(let i=0;i<length;i++)result[i]=decoder.takeU8();return result}}var u8ClampedTypeInstance=new U8ClampedType,U8Type=new NumericType("u8"),U16Type=new NumericType("u16"),U32Type=new NumericType("u32"),U64Type=new NumericType("u64"),U128Type=new NumericType("u128"),I8Type=new NumericType("i8"),I16Type=new NumericType("i16"),I32Type=new NumericType("i32"),I64Type=new NumericType("i64"),I128Type=new NumericType("i128"),UsizeType=new NumericType("usize"),IsizeType=new NumericType("isize"),F32Type=new NumericType("f32"),F64Type=new NumericType("f64"),boolTypeInstance=new BoolType,undefinedTypeInstance=new UndefinedType,heapRefTypeInstance=new HeapRefType,borrowedRefTypeInstance=new BorrowedRefType,stringTypeInstance=new StringType,charTypeInstance=new CharType;function parseTypeDef(bytes,offset){let tag=bytes[offset.value++];switch(tag){case 0:return undefinedTypeInstance;case 1:return boolTypeInstance;case 2:return U8Type;case 3:return U16Type;case 4:return U32Type;case 5:return U64Type;case 6:return U128Type;case 7:return I8Type;case 8:return I16Type;case 9:return I32Type;case 10:return I64Type;case 11:return I128Type;case 12:return F32Type;case 13:return F64Type;case 14:return UsizeType;case 15:return IsizeType;case 16:return stringTypeInstance;case 26:return charTypeInstance;case 17:return heapRefTypeInstance;case 29:{let len=bytes[offset.value]|bytes[offset.value+1]<<8|bytes[offset.value+2]<<16|bytes[offset.value+3]<<24;offset.value+=4;let strBytes=bytes.subarray(offset.value,offset.value+len);return offset.value+=len,new RustValueType(new TextDecoder().decode(strBytes))}case 22:return borrowedRefTypeInstance;case 30:{let len=bytes[offset.value]|bytes[offset.value+1]<<8|bytes[offset.value+2]<<16|bytes[offset.value+3]<<24;offset.value+=4;let strBytes=bytes.subarray(offset.value,offset.value+len);return offset.value+=len,new RustBorrowType(new TextDecoder().decode(strBytes))}case 18:{let paramCount=bytes[offset.value++],paramTypes=[];for(let i=0;i<paramCount;i++)paramTypes.push(parseTypeDef(bytes,offset));let returnType=parseTypeDef(bytes,offset);return new CallbackType(paramTypes,returnType)}case 19:{let innerType=parseTypeDef(bytes,offset);return new OptionType(innerType)}case 20:{let okType=parseTypeDef(bytes,offset),errType=parseTypeDef(bytes,offset);return new ResultType(okType,errType)}case 27:{let okType=parseTypeDef(bytes,offset),errType=parseTypeDef(bytes,offset);return new ThrowingResultType(okType,errType)}case 21:{let elementType=parseTypeDef(bytes,offset);return new ArrayType(elementType)}case 31:{let innerType=parseTypeDef(bytes,offset);return new MutArrayType(innerType)}case 23:return u8ClampedTypeInstance;case 24:{let variantCount=bytes[offset.value++],lookupArray=[];for(let i=0;i<variantCount;i++){let len=bytes[offset.value]|bytes[offset.value+1]<<8|bytes[offset.value+2]<<16|bytes[offset.value+3]<<24;offset.value+=4;let strBytes=bytes.subarray(offset.value,offset.value+len);offset.value+=len,lookupArray.push(new TextDecoder().decode(strBytes))}return new StringEnumType(lookupArray)}case 28:{let signed=bytes[offset.value++]!==0,variantCount=bytes[offset.value++],values=[];for(let i=0;i<variantCount;i++){let raw=(bytes[offset.value]|bytes[offset.value+1]<<8|bytes[offset.value+2]<<16|bytes[offset.value+3]<<24)>>>0;offset.value+=4,values.push(signed?raw|0:raw)}return new NumericEnumType(signed,values)}case 25:{let variantCount=bytes[offset.value++],variants=[];for(let i=0;i<variantCount;i++){let kind=bytes[offset.value++];if(kind===0){let len=bytes[offset.value]|bytes[offset.value+1]<<8|bytes[offset.value+2]<<16|bytes[offset.value+3]<<24;offset.value+=4;let strBytes=bytes.subarray(offset.value,offset.value+len);offset.value+=len,variants.push({kind:"string",value:new TextDecoder().decode(strBytes)})}else if(kind===1)variants.push({kind:"type",type:parseTypeDef(bytes,offset)});else throw Error(`Invalid dynamic union variant kind: ${kind}`)}return new DynamicUnionType(variants)}default:throw Error(`Unknown TypeTag: ${tag}`)}}var NOT_THROWN=Symbol("not-thrown"),TYPE_CACHED=255,TYPE_FULL=254,DROP_NATIVE_REF_FN_ID=4294967295,CALL_EXPORT_FN_ID=4294967294;function decode_xhr_response(xhr){if(xhr.status===200&&xhr.responseText){let responseBinary=atob(xhr.responseText),responseBytes=new Uint8Array(responseBinary.length);for(let i=0;i<responseBinary.length;i++)responseBytes[i]=responseBinary.charCodeAt(i);return responseBytes.buffer}return null}function sync_request_binary(endpoint,data){let xhr=new XMLHttpRequest;xhr.open("POST",endpoint,!1);let bytes=new Uint8Array(data),binary="";for(let i=0;i<bytes.length;i++)binary+=String.fromCharCode(bytes[i]);let base64=btoa(binary);return xhr.setRequestHeader("dioxus-data",base64),xhr.send(),decode_xhr_response(xhr)}function sync_lock_request(){let xhr=new XMLHttpRequest;return xhr.open("POST","/__wbg__/handler",!1),xhr.setRequestHeader("wry-bindgen-lock","1"),xhr.send(),decode_xhr_response(xhr)}function sendEvaluateToRust(encodePayload){let pendingHeapRefs=window.jsHeap.deferHeapRefs(),encoder=new DataEncoder(pendingHeapRefs);return encoder.pushU8(0),encodePayload(encoder),handleBinaryResponse(sync_request_binary("/__wbg__/handler",encoder.finalize()))}function acquire_handler_lock(){if(handleBinaryResponse(sync_lock_request()))throw Error("Unprocessed data remaining after lock handling")}function parseTypeInfo(decoder){let typeCache2=getTypeCache(),typeMarker=decoder.takeU8();if(typeMarker===TYPE_CACHED){let typeId=decoder.takeU32(),cached=typeCache2.get(typeId);if(!cached)throw Error(`Unknown cached type ID: ${typeId}`);return cached}else if(typeMarker===TYPE_FULL){let typeId=decoder.takeU32(),paramCount=decoder.takeU8(),typeBytes=decoder.getRemainingBytes(),offset={value:0},paramTypes=[];for(let i=0;i<paramCount;i++)paramTypes.push(parseTypeDef(typeBytes,offset));let returnType=parseTypeDef(typeBytes,offset);decoder.skipBytes(offset.value);let cached={paramTypes,returnType};return typeCache2.set(typeId,cached),cached}else throw Error(`Unknown type marker: ${typeMarker}`)}function takeIdList(decoder){let count=decoder.takeU32(),ids=[];for(let i=0;i<count;i++)ids.push(decoder.takeU64());return ids}function installDeferredHeapRefs(decoder){let ids=takeIdList(decoder);if(ids.length>0)window.jsHeap.resolveDeferredHeapRefs(ids)}function handleBinaryResponse(response){let currentResponse=response;while(currentResponse&&currentResponse.byteLength!==0){let decoder=new DataDecoder(currentResponse),msgType=decoder.takeU8();if(msgType===1)return installDeferredHeapRefs(decoder),decoder;else if(msgType===2)throw installDeferredHeapRefs(decoder),Error(decoder.takeStr());else if(msgType===0){installDeferredHeapRefs(decoder);let reservedIds=takeIdList(decoder);window.jsHeap.pushReservationScope(reservedIds);let pendingHeapRefs=window.jsHeap.deferHeapRefs(),encoder=new DataEncoder(pendingHeapRefs);encoder.pushU8(1),window.jsHeap.pushBorrowFrame();let succeeded=!1,thrown=NOT_THROWN;try{while(decoder.hasMoreU32()){let fnId=decoder.takeU32(),typeInfo=parseTypeInfo(decoder),jsFunction=getFunctionRegistry()[fnId];if(!jsFunction)throw Error("Unknown function ID in response: "+fnId);let params;try{params=typeInfo.paramTypes.map((paramType)=>paramType.decode(decoder))}catch(error){let message=error instanceof Error?error.message:String(error),source=String(jsFunction).replace(/\s+/g," ").slice(0,160);throw Error(`Failed to decode parameters for function ID ${fnId} (${source}): ${message}`)}let result=jsFunction(...params);if(typeInfo.returnType instanceof HeapRefType&&reservedIds.length>0)window.jsHeap.fillNextReserved(result);else typeInfo.returnType.encode(encoder,result);for(let i=0;i<typeInfo.paramTypes.length;i++)typeInfo.paramTypes[i].appendWriteBack?.(encoder,params[i])}succeeded=!0}catch(error){thrown=error}finally{window.jsHeap.popBorrowFrame(),window.jsHeap.popReservationScope(succeeded)}if(thrown!==NOT_THROWN){let errEncoder=new DataEncoder(window.jsHeap.deferHeapRefs());errEncoder.pushU8(3),errEncoder.pushStr(thrown instanceof Error?thrown.message:String(thrown)),currentResponse=sync_request_binary("/__wbg__/handler",errEncoder.finalize());continue}currentResponse=sync_request_binary("/__wbg__/handler",encoder.finalize());continue}if(!decoder.isEmpty())throw Error("Unprocessed data remaining after Evaluate handling");return null}return null}function typeFromBytes(bytes){let offset={value:0},ty=parseTypeDef(new Uint8Array(bytes),offset);if(offset.value!==bytes.length)throw Error(`Unprocessed export type data: ${bytes.length-offset.value} bytes`);return ty}var U32_TYPE_DEF=[4],UNDEFINED_TYPE_DEF=[0];function isUndefinedTypeDef(typeDef){return typeDef.length===1&&typeDef[0]===0}var exportRegistry=new FinalizationRegistry((info)=>{for(let[className,handle]of info.drops)if(handle!==0)callExport(`${className}::__drop`,[U32_TYPE_DEF],UNDEFINED_TYPE_DEF,[handle])});function copyBackMutArrays(decoder,argTypes,args){for(let i=0;i<argTypes.length;i++){let argType=argTypes[i];if(argType instanceof MutArrayType)argType.copyBack(decoder,args[i])}}function callExport(exportName,argTypeDefs,returnTypeDef,args){if(argTypeDefs.length!==args.length)throw Error(`Export ${exportName} expected ${argTypeDefs.length} arguments but got ${args.length}`);window.jsHeap.pushBorrowFrame();let argTypes=argTypeDefs.map(typeFromBytes);try{let decoder=sendEvaluateToRust((encoder)=>{encoder.pushU32(CALL_EXPORT_FN_ID),encoder.pushStr(exportName);for(let i=0;i<args.length;i++)argTypes[i].encode(encoder,args[i])});for(let i=0;i<args.length;i++)if(argTypes[i]instanceof RustValueType&&args[i]!=null)args[i].__handle=0;if(!decoder&&isUndefinedTypeDef(returnTypeDef)){if(argTypes.some((t)=>t instanceof MutArrayType))throw Error(`Missing response data for export ${exportName}`);return}if(!decoder)throw Error(`Missing response data for export ${exportName}`);window.jsHeap.setTakingOwnership(!0);let result;try{result=typeFromBytes(returnTypeDef).decode(decoder)}finally{window.jsHeap.setTakingOwnership(!1)}if(copyBackMutArrays(decoder,argTypes,args),!decoder.isEmpty())throw Error(`Unprocessed data remaining after export ${exportName}`);return result}finally{window.jsHeap.popBorrowFrame()}}function createWrapper(handle,className){let ClassConstructor=window.__wryClassRegistry?.[className]??window[className];if(ClassConstructor&&typeof ClassConstructor.__wrap==="function")return ClassConstructor.__wrap(handle);let proxy=new Proxy({__handle:handle,__className:className},{get(target,prop){if(prop==="__handle"||prop==="__className")return target[prop];if(prop==="free")return()=>{let handle2=target.__handle;if(target.__handle=0,handle2!==0)callExport(`${className}::__drop`,[U32_TYPE_DEF],UNDEFINED_TYPE_DEF,[handle2])};if(typeof prop==="symbol"||prop==="then"||prop==="toJSON")return;return()=>{let exportName=`${className}::${String(prop)}`;throw Error(`Cannot call ${exportName} through a fallback wrapper without generated type metadata`)}}});return exportRegistry.register(proxy,{drops:[[className,handle]]}),proxy}window.__wryCallExport=callExport;window.__wryExportRegistry=exportRegistry;var rustExports={createWrapper,callExport};window.setFunctionRegistry=setFunctionRegistry;window.__wry_acquire_handler_lock=acquire_handler_lock;window.jsHeap=new JSHeap;window.rustExports=rustExports;