import {
  AC,
  Dc,
  Fc,
  Gc,
  Rc,
  SD,
  gH,
  iI,
  jc,
  sc
} from "./chunk-GEOPSD6E.js";

// ../hoppscotch-js-sandbox/dist/module-asyncify-R6PWJ6ZV-2Fad--rr-CuUo0RFC.js
var y = class extends Dc {
  async evalCodeAsync(e, t = "eval.js", i) {
    let s = i === void 0 ? 1 : 0, a = Rc(i), o = 0;
    try {
      o = await this.memory.newHeapCharPointer(e).consume((n) => this.ffi.QTS_Eval_MaybeAsync(this.ctx.value, n.value.ptr, n.value.strlen, t, s, a));
    } catch (n) {
      throw this.runtime.debugLog("QTS_Eval_MaybeAsync threw", n), n;
    }
    let r = this.ffi.QTS_ResolveException(this.ctx.value, o);
    return r ? (this.ffi.QTS_FreeValuePointer(this.ctx.value, o), this.fail(this.memory.heapValueHandle(r))) : this.success(this.memory.heapValueHandle(o));
  }
  newAsyncifiedFunction(e, t) {
    return this.newFunction(e, t);
  }
};
var C = class extends Gc {
  constructor(e) {
    super(e);
  }
  newContext(e = {}) {
    let t = Fc(e.intrinsics), i = new iI(this.ffi.QTS_NewContext(this.rt.value, t), void 0, (a) => {
      this.contextMap.delete(a), this.callbacks.deleteContext(a), this.ffi.QTS_FreeContext(a);
    }), s = new y({ module: this.module, ctx: i, ffi: this.ffi, rt: this.rt, ownedLifetimes: [], runtime: this, callbacks: this.callbacks });
    return this.contextMap.set(i.value, s), s;
  }
  setModuleLoader(e, t) {
    super.setModuleLoader(e, t);
  }
  setMaxStackSize(e) {
    return super.setMaxStackSize(e);
  }
};
var M = class extends gH {
  constructor(e, t) {
    super(e, t), this.ffi = t, this.module = e;
  }
  newRuntime(e = {}) {
    let t = new iI(this.ffi.QTS_NewRuntime(), void 0, (s) => {
      this.callbacks.deleteRuntime(s), this.ffi.QTS_FreeRuntime(s);
    }), i = new C({ module: this.module, ffi: this.ffi, rt: t, callbacks: this.callbacks });
    return sc(i, e), e.moduleLoader && i.setModuleLoader(e.moduleLoader), i;
  }
  newContext(e = {}) {
    let t = this.newRuntime(), i = e.ownedLifetimes ? e.ownedLifetimes.concat([t]) : [t], s = t.newContext({ ...e, ownedLifetimes: i });
    return t.context = s, s;
  }
  evalCode() {
    throw new SD("QuickJSWASMModuleAsyncify.evalCode: use evalCodeAsync instead");
  }
  evalCodeAsync(e, t) {
    return AC.withScopeAsync(async (i) => {
      let s = i.manage(this.newContext());
      jc(s.runtime, t);
      let a = await s.evalCodeAsync(e, "eval.js");
      if (t.memoryLimitBytes !== void 0 && s.runtime.setMemoryLimit(-1), a.error) throw s.dump(i.manage(a.error));
      return s.dump(i.manage(a.value));
    });
  }
};
export {
  M as QuickJSAsyncWASMModule
};
//# sourceMappingURL=module-asyncify-R6PWJ6ZV-2Fad--rr-CuUo0RFC-Y2WFLK2Z.js.map