UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

57 lines (55 loc) 2.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ThrowCompletionBaseHelper = void 0; const tslib_1 = require("tslib"); const ts_utils_1 = require("@neo-one/ts-utils"); const typescript_1 = tslib_1.__importDefault(require("typescript")); const constants = tslib_1.__importStar(require("../../../constants")); const Helper_1 = require("../Helper"); const isValidParent = (catchPC, finallyPC, node) => node !== undefined && ((typescript_1.default.isTryStatement(node) && (catchPC !== undefined || finallyPC !== undefined)) || ts_utils_1.tsUtils.guards.isFunctionLikeDeclarationBase(node) || typescript_1.default.isArrowFunction(node) || typescript_1.default.isSourceFile(node)); class ThrowCompletionBaseHelper extends Helper_1.Helper { emit(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const finallyPC = options.finallyPC; const catchPC = options.catchPC; let parent = ts_utils_1.tsUtils.node.getParent(node); while (parent !== undefined && !isValidParent(catchPC, finallyPC, parent)) { parent = ts_utils_1.tsUtils.node.getParent(parent); } if (catchPC !== undefined) { sb.emitPushInt(node, constants.THROW_COMPLETION); sb.emitJmp(node, 'JMP', catchPC); } else if (finallyPC !== undefined) { sb.emitPushInt(node, constants.THROW_COMPLETION); sb.emitPushInt(node, constants.FINALLY_COMPLETION); sb.emitJmp(node, 'JMP', finallyPC); } else if (typescript_1.default.isSourceFile(node) || (parent !== undefined && typescript_1.default.isSourceFile(parent))) { sb.emitOp(node, 'DROP'); sb.emitHelper(node, options, sb.helpers.if({ condition: () => { sb.emitHelper(node, options, sb.helpers.invocationIsCaller); }, whenTrue: () => { sb.emitOp(node, 'THROW'); }, whenFalse: () => { sb.emitPushBoolean(node, false); sb.emitPushInt(node, constants.NORMAL_COMPLETION); sb.emitOp(node, 'RET'); }, })); } else { sb.emitPushInt(node, constants.THROW_COMPLETION); sb.emitOp(node, 'RET'); } } } exports.ThrowCompletionBaseHelper = ThrowCompletionBaseHelper; //# sourceMappingURL=ThrowCompletionBaseHelper.js.map