UNPKG

@awayfl/avm2

Version:

Virtual machine for executing AS3 code

100 lines (99 loc) 3.76 kB
import { InstanceInfo } from './InstanceInfo'; import { ClassInfo } from './ClassInfo'; var MethodInfo = /** @class */ (function () { function MethodInfo(abc, _index, name, typeName, parameters, optionalCount, flags) { this.abc = abc; this._index = _index; this.name = name; this.typeName = typeName; this.parameters = parameters; this.optionalCount = optionalCount; this.flags = flags; this.trait = null; this.scriptInfo = null; this.classInfo = null; this.instanceInfo = null; this.isConstructor = false; this.compiled = null; this.error = null; this.useCount = 0; this._body = null; this.minArgs = parameters.length - optionalCount; } Object.defineProperty(MethodInfo.prototype, "state", { get: function () { if (this.error || this.getBody() == null) { return "failed" /* COMPILATION_STATE.FAILED */; } if (this.compiled) { return "compiled" /* COMPILATION_STATE.COMPILLED */; } return "pending" /* COMPILATION_STATE.PENDING */; }, enumerable: false, configurable: true }); MethodInfo.prototype.getNativeMetadata = function () { var _a; var metadata = (_a = this.trait) === null || _a === void 0 ? void 0 : _a.metadata; if (!metadata) return null; for (var i = 0; i < metadata.length; i++) if (metadata[i].name === 'native') return metadata[i]; return null; }; MethodInfo.prototype.getBody = function () { return this._body || (this._body = this.abc.getMethodBodyInfo(this._index)); }; MethodInfo.prototype.index = function () { return this._index; }; MethodInfo.prototype.getType = function () { if (this._returnType !== undefined) return this._returnType; this._returnType = this.typeName ? this.abc.applicationDomain.getClass(this.typeName) : null; return this._returnType; }; MethodInfo.prototype.toString = function () { var str = this.name; str += ' (' + this.parameters.join(', ') + ')'; if (this.typeName) { str += ': ' + this.typeName.name; } return str; }; MethodInfo.prototype.toFlashlogString = function () { var trait = this.trait; var prefix = trait.kind === 2 /* TRAIT.Getter */ ? 'get ' : trait.kind === 3 /* TRAIT.Setter */ ? 'set ' : ''; var name = trait.multiname.toFlashlogString(); var holder = trait.holder; var holderName; if (holder && holder instanceof InstanceInfo) { holderName = holder.multiname.toFlashlogString(); prefix = holderName + '/' + prefix; } if (holder && holder instanceof ClassInfo && holder.trait) { holderName = holder.trait.multiname.toFlashlogString(); prefix = holderName + '$/' + prefix; } var prefixPos; if (holderName && (prefixPos = name.indexOf('::')) > 0 && holderName.indexOf(name.substring(0, prefixPos + 2)) === 0) { name = name.substring(prefixPos + 2); } return 'MTHD ' + prefix + name + ' ()'; }; MethodInfo.prototype.isNative = function () { return !!(this.flags & 32 /* METHOD.Native */); }; MethodInfo.prototype.needsRest = function () { return !!(this.flags & 4 /* METHOD.NeedRest */); }; MethodInfo.prototype.needsArguments = function () { return !!(this.flags & 1 /* METHOD.NeedArguments */); }; return MethodInfo; }()); export { MethodInfo };