UNPKG

@awayfl/avm2

Version:

Virtual machine for executing AS3 code

67 lines (66 loc) 2.47 kB
import { getNamespaceTypeName } from './NamespaceType'; import { assert } from '@awayjs/graphics'; import { release } from '@awayfl/swf-loader'; import { StringUtilities } from '@awayfl/swf-loader'; import { HashUtilities } from '@awayfl/swf-loader'; import { namespaceHashingBuffer } from './namespaceHashingBuffer'; var Namespace = /** @class */ (function () { function Namespace(type, uri, prefix) { this.type = type; this.uri = uri; this.prefix = prefix; this.mangledName = null; assert(type !== undefined); this.mangleName(); if (!release) { Object.freeze(this); } } Namespace.prototype.toString = function () { return getNamespaceTypeName(this.type) + (this.uri !== '' ? ':' + this.uri : ''); }; Namespace._hashNamespace = function (type, uri, prefix) { uri = uri + ''; prefix = prefix + ''; var index = Namespace._knownNames.indexOf(uri); if (index >= 0) { return type << 2 | index; } var length = 1 + uri.length + prefix.length; var data = length < 101 ? namespaceHashingBuffer : new Uint8Array(length); var j = 0; data[j++] = type; for (var i = 0; i < uri.length; i++) { data[j++] = uri.charCodeAt(i); } for (var i = 0; i < prefix.length; i++) { data[j++] = prefix.charCodeAt(i); } return HashUtilities.hashBytesTo32BitsMD5(data, 0, j); }; Namespace.prototype.mangleName = function () { if (this.type === 0 /* NamespaceType.Public */ && this.uri === '') { this.mangledName = 'Bg'; return; } var nsHash = Namespace._hashNamespace(this.type, this.uri, this.prefix); this.mangledName = StringUtilities.variableLengthEncodeInt32(nsHash); }; Namespace.prototype.isPublic = function () { return this.type === 0 /* NamespaceType.Public */; }; Object.defineProperty(Namespace.prototype, "reflectedURI", { get: function () { // For public names without a URI, Tamarin uses `null`, we use `""`. // Hence: special-casing for reflection. return this.uri || (this.type === 0 /* NamespaceType.Public */ ? null : this.uri); }, enumerable: false, configurable: true }); Namespace._knownNames = [ '' ]; return Namespace; }()); export { Namespace };