runtime-asyncify.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.QuickJSAsyncRuntime = void 0;
  4. const _1 = require(".");
  5. const context_asyncify_1 = require("./context-asyncify");
  6. const runtime_1 = require("./runtime");
  7. const types_1 = require("./types");
  8. class QuickJSAsyncRuntime extends runtime_1.QuickJSRuntime {
  9. /** @private */
  10. constructor(args) {
  11. super(args);
  12. }
  13. newContext(options = {}) {
  14. if (options.intrinsics && options.intrinsics !== types_1.DefaultIntrinsics) {
  15. throw new Error("TODO: Custom intrinsics are not supported yet");
  16. }
  17. const ctx = new _1.Lifetime(this.ffi.QTS_NewContext(this.rt.value), undefined, (ctx_ptr) => {
  18. this.contextMap.delete(ctx_ptr);
  19. this.callbacks.deleteContext(ctx_ptr);
  20. this.ffi.QTS_FreeContext(ctx_ptr);
  21. });
  22. const context = new context_asyncify_1.QuickJSAsyncContext({
  23. module: this.module,
  24. ctx,
  25. ffi: this.ffi,
  26. rt: this.rt,
  27. ownedLifetimes: [],
  28. runtime: this,
  29. callbacks: this.callbacks,
  30. });
  31. this.contextMap.set(ctx.value, context);
  32. return context;
  33. }
  34. setModuleLoader(moduleLoader, moduleNormalizer) {
  35. super.setModuleLoader(moduleLoader, moduleNormalizer);
  36. }
  37. /**
  38. * Set the max stack size for this runtime in bytes.
  39. * To remove the limit, set to `0`.
  40. *
  41. * Setting this limit also adjusts the global `ASYNCIFY_STACK_SIZE` for the entire {@link QuickJSAsyncWASMModule}.
  42. * See the [pull request](https://github.com/justjake/quickjs-emscripten/pull/114) for more details.
  43. */
  44. setMaxStackSize(stackSize) {
  45. return super.setMaxStackSize(stackSize);
  46. }
  47. }
  48. exports.QuickJSAsyncRuntime = QuickJSAsyncRuntime;
  49. //# sourceMappingURL=runtime-asyncify.js.map