@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
36 lines (35 loc) • 2.09 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Operation_BinaryExpression
* @description Instance Of
*/
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.executeInstanceOfBinaryOperator = void 0;
const error_code_1 = require("../../declare/error-code");
const error_1 = require("../../util/error/error");
const sand_class_1 = require("../../variable/sand-class/sand-class");
const sand_class_instance_1 = require("../../variable/sand-class/sand-class-instance");
const executeInstanceOfBinaryOperator = function (left, right, scope, trace) {
return __awaiter(this, void 0, void 0, function* () {
const operatorLeft = yield this.execute(left, scope, trace);
if (!(operatorLeft instanceof sand_class_instance_1.SandClassInstance)) {
throw (0, error_1.error)(error_code_1.ERROR_CODE.INSTANCE_OF_BINARY_OPERATION_LEFT_ONLY_ALLOW_ON_CLASS_INSTANCE, String(operatorLeft), left, trace);
}
const operationRight = yield this.execute(right, scope, trace);
if (!(operationRight instanceof sand_class_1.SandClass)) {
throw (0, error_1.error)(error_code_1.ERROR_CODE.INSTANCE_OF_BINARY_OPERATION_RIGHT_ONLY_ALLOW_ON_CLASS, String(operationRight), right, trace);
}
return operatorLeft.targetClass.sameClass(operationRight);
});
};
exports.executeInstanceOfBinaryOperator = executeInstanceOfBinaryOperator;