@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
42 lines (41 loc) • 2.02 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Evaluate
* @description Catch clause
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CatchClauseEvaluator = exports.mountCatchClause = void 0;
const error_code_1 = require("../declare/error-code");
const variable_1 = require("../declare/variable");
const error_1 = require("../util/error/error");
const variable_2 = require("../variable/variable");
const mountCatchClause = (sandbox) => {
sandbox.mount("CatchClause", exports.CatchClauseEvaluator);
};
exports.mountCatchClause = mountCatchClause;
const CatchClauseEvaluator = function (node, scope, trace) {
return __awaiter(this, void 0, void 0, function* () {
const nextTrace = trace.stack(node);
const subScope = scope.child();
const identifier = node.param;
const throwObject = scope.getThrow();
if (!(throwObject instanceof variable_2.Variable)) {
throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, void 0, node, trace);
}
const registerer = subScope.register(variable_1.VARIABLE_TYPE.CONSTANT);
registerer(identifier.name, throwObject.get());
const result = yield this.execute(node.body, subScope, nextTrace);
return result;
});
};
exports.CatchClauseEvaluator = CatchClauseEvaluator;