UNPKG

@awayfl/avm1

Version:

Virtual machine for executing AS1 and AS2 code

36 lines (32 loc) 1.07 kB
import { AVM1Object } from './AVM1Object'; import { IAVM1Context, IAVM1Callable } from '../runtime'; /** * Base class for ActionsScript functions. */ export class AVM1Function extends AVM1Object implements IAVM1Callable { public isOnEnter: boolean; public constructor(context: IAVM1Context) { super(context); this.alPrototype = context.builtins.Function.alGetPrototypeProperty(); this.isOnEnter = false; } public alConstruct(args?: any[]): AVM1Object { throw new Error('not implemented AVM1Function.alConstruct'); } public alCall(thisArg: any, args?: any[]): any { throw new Error('not implemented AVM1Function.alCall'); } /** * Wraps the function to the callable JavaScript function. * @returns {Function} a JavaScript function. */ public toJSFunction(thisArg: AVM1Object = null): Function { const fn = this; const context = this.context; return function () { /* eslint-disable-next-line prefer-rest-params */ const args = Array.prototype.slice.call(arguments, 0); return context.executeFunction(fn, thisArg, args); }; } }