@jplorg/jpl
Version:
JPL interpreter
37 lines (36 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _library = require("../../library");
var _utils = require("./utils");
var _default = exports.default = {
/** { try: [op], catch: [op] } */
async op(runtime, input, params, scope, next) {
const nextScope = scope.next({
signal: scope.signal.next()
});
try {
return await runtime.executeInstructions(params.try ?? [], [input], nextScope, async output => {
try {
return await next(output, scope);
} catch (err) {
throw new _library.JPLErrorEnclosure(err);
}
});
} catch (err) {
if (_library.JPLErrorEnclosure.is(err)) throw err.inner;
if (!_library.JPLExecutionError.is(err)) throw err;
nextScope.signal.exit();
return runtime.executeInstructions(params.catch ?? [], [err.value], scope, output => next(output, scope));
}
},
/** { try: function, catch: function } */
map(runtime, params) {
return {
try: (0, _utils.call)(params.try),
catch: (0, _utils.call)(params.catch)
};
}
};