UNPKG

@jplorg/jpl

Version:
38 lines (37 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _utils = require("./utils"); var _default = exports.default = { /** { ifs: [{ if: [op], then: [op] }], else: [op] } */ op(runtime, input, params, scope, next) { const iter = async from => { // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations. await undefined; scope.signal.checkHealth(); if (from >= (params.ifs?.length ?? 0)) { return runtime.executeInstructions(params.else ?? [], [input], scope, output => next(output, scope)); } const condition = params.ifs[from]; return runtime.executeInstructions(condition.if ?? [], [input], scope, result => { if (runtime.truthy(result)) { return runtime.executeInstructions(condition.then ?? [], [input], scope, output => next(output, scope)); } return iter(from + 1); }); }; return iter(0); }, /** { ifs: [{ if: function, then: function }], else: function } */ map(runtime, params) { return { ifs: runtime.muxOne([params.ifs], entry => ({ if: (0, _utils.call)(entry.if), then: (0, _utils.call)(entry.then) })), else: (0, _utils.call)(params.else) }; } };