UNPKG

@awayfl/avm2

Version:

Virtual machine for executing AS3 code

49 lines (48 loc) 1.68 kB
import { assert, release } from '@awayfl/swf-loader'; import { ABCFile } from './ABCFile'; var ABCCatalog = /** @class */ (function () { function ABCCatalog(app, abcs, index) { this.app = app; this.abcs = abcs; this.map = {}; this.scripts = {}; for (var i = 0; i < index.length; i++) { var abc = index[i]; this.scripts[abc.name] = abc; release || assert(Array.isArray(abc.defs)); for (var j = 0; j < abc.defs.length; j++) { var def = abc.defs[j].split(':'); var nameMappings = this.map[def[1]]; if (!nameMappings) { nameMappings = this.map[def[1]] = {}; } nameMappings[def[0]] = abc.name; } } } ABCCatalog.prototype.getABCByScriptName = function (scriptName) { var entry = this.scripts[scriptName]; if (!entry) { return null; } var env = { url: scriptName, app: this.app }; return new ABCFile(env, this.abcs.subarray(entry.offset, entry.offset + entry.length)); }; ABCCatalog.prototype.getABCByMultiname = function (mn) { var mappings = this.map[mn.name]; if (!mappings) { return null; } var namespaces = mn.namespaces; for (var i = 0; i < namespaces.length; i++) { var ns = namespaces[i]; var scriptName = mappings[ns.uri]; if (scriptName) { return this.getABCByScriptName(scriptName); } } return null; }; return ABCCatalog; }()); export { ABCCatalog };