UNPKG

@awayfl/avm2

Version:

Virtual machine for executing AS3 code

42 lines (41 loc) 1.26 kB
/** * Generate tiny constructor for nested class when it only call super */ var TinyConstructor = /** @class */ (function () { function TinyConstructor() { } TinyConstructor.prototype.test = function (method) { // skip noConstructors if (!method.isConstructor) return false; // skip constuctors with arguments if (method.parameters.length > 0) return false; var body = method.getBody(); // stack more that 1? oh if (body.maxStack > 1) return false; // use more that 1 local? oh if (body.localCount > 1) return false; // increase scope? oh if (body.maxScopeDepth - body.initScopeDepth > 1) return false; // method use 6 opcodes if (body.code.length > 6) return false; return true; }; TinyConstructor.prototype.getBody = function (method) { if (!this.test(method)) { return null; } return function (context) { return function tiny_constructor() { context.savedScope.superConstructor.call(this); }; }; }; return TinyConstructor; }()); export { TinyConstructor };