12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.QuickJSAsyncWASMModule = void 0;
- const errors_1 = require("./errors");
- const lifetime_1 = require("./lifetime");
- const module_1 = require("./module");
- const runtime_asyncify_1 = require("./runtime-asyncify");
- class QuickJSAsyncWASMModule extends module_1.QuickJSWASMModule {
-
- constructor(module, ffi) {
- super(module, ffi);
- this.ffi = ffi;
- this.module = module;
- }
-
- newRuntime(options = {}) {
- const rt = new lifetime_1.Lifetime(this.ffi.QTS_NewRuntime(), undefined, (rt_ptr) => {
- this.callbacks.deleteRuntime(rt_ptr);
- this.ffi.QTS_FreeRuntime(rt_ptr);
- });
- const runtime = new runtime_asyncify_1.QuickJSAsyncRuntime({
- module: this.module,
- ffi: this.ffi,
- rt,
- callbacks: this.callbacks,
- });
- (0, module_1.applyBaseRuntimeOptions)(runtime, options);
- if (options.moduleLoader) {
- runtime.setModuleLoader(options.moduleLoader);
- }
- return runtime;
- }
-
- newContext(options = {}) {
- const runtime = this.newRuntime();
- const lifetimes = options.ownedLifetimes ? options.ownedLifetimes.concat([runtime]) : [runtime];
- const context = runtime.newContext({ ...options, ownedLifetimes: lifetimes });
- runtime.context = context;
- return context;
- }
-
- evalCode() {
- throw new errors_1.QuickJSNotImplemented("QuickJSWASMModuleAsyncify.evalCode: use evalCodeAsync instead");
- }
-
- evalCodeAsync(code, options) {
-
- return lifetime_1.Scope.withScopeAsync(async (scope) => {
- const vm = scope.manage(this.newContext());
- (0, module_1.applyModuleEvalRuntimeOptions)(vm.runtime, options);
- const result = await vm.evalCodeAsync(code, "eval.js");
- if (options.memoryLimitBytes !== undefined) {
-
- vm.runtime.setMemoryLimit(-1);
- }
- if (result.error) {
- const error = vm.dump(scope.manage(result.error));
- throw error;
- }
- const value = vm.dump(scope.manage(result.value));
- return value;
- });
- }
- }
- exports.QuickJSAsyncWASMModule = QuickJSAsyncWASMModule;
|