UNPKG

@awayfl/avm2

Version:

Virtual machine for executing AS3 code

66 lines (65 loc) 2.74 kB
import { __extends } from "tslib"; import { ASFunction } from './ASFunction'; import { defineNonEnumerableProperty } from '@awayfl/swf-loader'; import { Errors } from '../errors'; import { sliceArguments } from '../run/writers'; var ASMethodClosure = /** @class */ (function (_super) { __extends(ASMethodClosure, _super); function ASMethodClosure() { return _super !== null && _super.apply(this, arguments) || this; } ASMethodClosure.classInitializer = function () { var proto = this.dPrototype; var asProto = ASMethodClosure.prototype; defineNonEnumerableProperty(proto, '$Bgcall', asProto.call); defineNonEnumerableProperty(proto, '$Bgapply', asProto.apply); }; ASMethodClosure.Create = function (receiver, method) { // hack, create a real closure and change prototype onto AXMethodClosure // now we can invoke closure as regular function // fix for click heroes var closure = function () { // eslint-disable-next-line prefer-rest-params return closure.value.apply(closure.receiver, arguments); }; Object.setPrototypeOf(closure, this.sec.AXMethodClosure.tPrototype); closure.__isClosure = true; closure.receiver = receiver; closure.value = method; closure.methodInfo = method.methodInfo; closure.axCall = closure.call; closure.axApply = closure.apply; return closure; }; Object.defineProperty(ASMethodClosure.prototype, "prototype", { get: function () { return null; }, set: function (prototype) { this.sec.throwError('ReferenceError', Errors.ConstWriteError, 'prototype', 'MethodClosure'); }, enumerable: false, configurable: true }); ASMethodClosure.prototype.axCall = function (ignoredThisArg) { return this.value.apply(this.receiver, sliceArguments(arguments, 1)); }; ASMethodClosure.prototype.axApply = function (ignoredThisArg, argArray) { return this.value.apply(this.receiver, argArray); }; ASMethodClosure.prototype.call = function (ignoredThisArg) { var args = arguments; var len = args.length; if (len <= 6) { return this.value.call(this.receiver, args[1], args[2], args[3], args[4], args[5]); } else { return this.value.apply(this.receiver, sliceArguments(arguments, 1)); } }; ASMethodClosure.prototype.apply = function (ignoredThisArg, argArray) { return this.value.apply(this.receiver, (argArray && argArray.value) ? argArray.value : argArray); }; return ASMethodClosure; }(ASFunction)); export { ASMethodClosure };