UNPKG

@awayfl/avm2

Version:

Virtual machine for executing AS3 code

155 lines (154 loc) 7.52 kB
/* * Copyright 2014 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { __extends } from "tslib"; import { Multiname } from '../abc/lazy/Multiname'; import { internNamespace } from '../abc/lazy/internNamespace'; import { defineNonEnumerableProperty } from '@awayfl/swf-loader'; import { ASObject } from '../nat/ASObject'; import { Errors } from '../errors'; var proxyNamespace = internNamespace(0 /* NamespaceType.Public */, 'http://www.adobe.com/2006/actionscript/flash/proxy'); var proxyPrefix = '$' + proxyNamespace.mangledName; /** * The Proxy class lets you override the default behavior of ActionScript operations * (such as retrieving and modifying properties) on an object. */ var ASProxy = /** @class */ (function (_super) { __extends(ASProxy, _super); function ASProxy() { return _super !== null && _super.apply(this, arguments) || this; } ASProxy.classInitializer = function () { var proto = this.dPrototype; var asProto = ASProxy.prototype; defineNonEnumerableProperty(proto, proxyPrefix + 'getProperty', asProto.native_getProperty); defineNonEnumerableProperty(proto, proxyPrefix + 'setProperty', asProto.native_setProperty); defineNonEnumerableProperty(proto, proxyPrefix + 'callProperty', asProto.native_callProperty); defineNonEnumerableProperty(proto, proxyPrefix + 'hasProperty', asProto.native_hasProperty); defineNonEnumerableProperty(proto, proxyPrefix + 'deleteProperty', asProto.native_deleteProperty); defineNonEnumerableProperty(proto, proxyPrefix + 'getDescendants', asProto.native_getDescendants); defineNonEnumerableProperty(proto, proxyPrefix + 'nextNameIndex', asProto.native_nextNameIndex); defineNonEnumerableProperty(proto, proxyPrefix + 'nextName', asProto.native_nextName); defineNonEnumerableProperty(proto, proxyPrefix + 'nextValue', asProto.native_nextValue); }; ASProxy.prototype.native_getProperty = function () { this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxyGetPropertyError); }; ASProxy.prototype.native_setProperty = function () { this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxySetPropertyError); }; ASProxy.prototype.native_callProperty = function () { this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxyCallPropertyError); }; ASProxy.prototype.native_hasProperty = function () { this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxyHasPropertyError); }; ASProxy.prototype.native_deleteProperty = function () { this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxyDeletePropertyError); }; ASProxy.prototype.native_getDescendants = function () { this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxyGetDescendantsError); }; ASProxy.prototype.native_nextNameIndex = function () { // Enumeration traverses the prototype chain. For proxies, this causes problems // because a Proxy-extending class has the MOP override for `axNextNameIndex`, but can't // have the `nextNameIndex` hook defined and thus hits this default hook. In that case, // we'd incorrectly throw an error instead of just returning null if we didn't // special-case here. if (this === this.axClass.dPrototype) { return; } this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxyNextNameIndexError); }; ASProxy.prototype.native_nextName = function () { this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxyNextNameError); }; ASProxy.prototype.native_nextValue = function () { this.sec.throwError('flash.errors.IllegalOperationError', Errors.ProxyNextValueError); }; ASProxy.prototype.axGetProperty = function (mn) { var value; var trait = typeof mn.name === 'string' ? this.traits.getTrait(mn.namespaces, mn.name) : null; if (trait) { var name_1 = trait.multiname.getMangledName(); value = this[name_1]; if (typeof value === 'function') { return this.axGetMethod(name_1); } } else { value = this[proxyPrefix + 'getProperty'](this.sec.AXQName.FromMultiname(mn)); } return value; }; ASProxy.prototype.axGetNumericProperty = function (name) { return this[proxyPrefix + 'getProperty']((+name) + ''); }; ASProxy.prototype.axSetNumericProperty = function (name, value) { this[proxyPrefix + 'setProperty']((+name) + '', value); }; ASProxy.prototype.axSetProperty = function (mn, value, bc) { var trait = typeof mn.name === 'string' ? this.traits.getTrait(mn.namespaces, mn.name) : null; if (trait) { _super.prototype.axSetProperty.call(this, mn, value, bc); return; } this[proxyPrefix + 'setProperty'](this.sec.AXQName.FromMultiname(mn), value); }; ASProxy.prototype.axCallProperty = function (mn, args, isLex) { var trait = typeof mn.name === 'string' ? this.traits.getTrait(mn.namespaces, mn.name) : null; if (trait) { return _super.prototype.axCallProperty.call(this, mn, args, isLex); } var callArgs = [this.sec.AXQName.FromMultiname(mn)].concat(args); return this[proxyPrefix + 'callProperty'].apply(this, callArgs); }; ASProxy.prototype.axHasProperty = function (mn) { return this.axHasOwnProperty(mn); }; ASProxy.prototype.axHasPublicProperty = function (nm) { rn.name = nm; if (this.axHasPropertyInternal(rn)) { return true; } return this[proxyPrefix + 'hasProperty'](nm); }; ASProxy.prototype.axHasOwnProperty = function (mn) { var trait = typeof mn.name === 'string' ? this.traits.getTrait(mn.namespaces, mn.name) : null; if (trait) { return true; } return this[proxyPrefix + 'hasProperty'](this.sec.AXQName.FromMultiname(mn)); }; ASProxy.prototype.axDeleteProperty = function (mn) { var trait = typeof mn.name === 'string' ? this.traits.getTrait(mn.namespaces, mn.name) : null; if (trait) { return delete this[trait.multiname.getMangledName()]; } return this[proxyPrefix + 'deleteProperty'](this.sec.AXQName.FromMultiname(mn)); }; ASProxy.prototype.axNextName = function (index) { return this[proxyPrefix + 'nextName'](index); }; ASProxy.prototype.axNextValue = function (index) { return this[proxyPrefix + 'nextValue'](index); }; ASProxy.prototype.axNextNameIndex = function (index) { return this[proxyPrefix + 'nextNameIndex'](index); }; return ASProxy; }(ASObject)); export { ASProxy }; var rn = new Multiname(null, 0, 17 /* CONSTANT.RTQNameL */, [], null, null, true);