From 85221fd9fc132760736b8a3127120b248b281f5f Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Fri, 3 Oct 2014 11:37:07 -0500 Subject: [PATCH] Refactors looking up of the AVM1 movie children. --- src/avm1/interpreter.ts | 32 +---------- src/avm1lib/AVM1MovieClip.ts | 50 ++++++++++++++++-- src/avm1lib/flash.d.ts | 2 + test/swfs/avm1/lookup/avm1-childlookup.fla | Bin 0 -> 4900 bytes test/swfs/avm1/lookup/avm1-childlookup.swf | Bin 0 -> 759 bytes .../avm1/lookup/avm1-childlookup.swf.trace | 3 ++ test/test_manifest.json | 7 +++ 7 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 test/swfs/avm1/lookup/avm1-childlookup.fla create mode 100644 test/swfs/avm1/lookup/avm1-childlookup.swf create mode 100644 test/swfs/avm1/lookup/avm1-childlookup.swf.trace diff --git a/src/avm1/interpreter.ts b/src/avm1/interpreter.ts index 490317751..c226feffa 100644 --- a/src/avm1/interpreter.ts +++ b/src/avm1/interpreter.ts @@ -345,21 +345,13 @@ module Shumway.AVM1 { } obj = Object(obj); // checking if avm2 public property is present - var avm2PublicName = Multiname.getPublicQualifiedName(name); - if (avm2PublicName in obj) { + if (obj.asHasProperty(undefined, name, 0)) { return name; } if (isNumeric(name)) { return null; } - if (isAVM1MovieClip(obj)) { - var child = ( obj).__lookupChild(name); - if (child) { - return name; - } - } - // versions 6 and below ignore identifier case if (as2GetCurrentSwfVersion() > 6) { return null; @@ -382,9 +374,6 @@ module Shumway.AVM1 { return undefined; } obj = Object(obj); - if (!obj.asHasProperty(undefined, name, 0) && isAVM1MovieClip(obj)) { - return ( obj).__lookupChild(name); - } return obj.asGetPublicProperty(name); } @@ -420,19 +409,6 @@ module Shumway.AVM1 { function as2Enumerate(obj, fn, thisArg) { forEachPublicProperty(obj, fn, thisArg); - - if (!isAVM1MovieClip(obj)) { - return; - } - // if it's a movie listing the children as well - var as3MovieClip = obj._nativeAS3Object; - for (var i = 0, length = as3MovieClip._children.length; i < length; i++) { - var child = as3MovieClip._children[i]; - var name = child.name; - if (!obj.asHasProperty(undefined, name, 0)) { - fn.call(thisArg, name); - } - } } function isAvm2Class(obj): boolean { @@ -880,12 +856,6 @@ module Shumway.AVM1 { return currentTarget; } - // trying movie clip children (if object is a MovieClip) - var mc = isAVM1MovieClip(currentTarget) && - currentTarget.__lookupChild(variableName); - if (mc) { - return mc; - } return undefined; } function avm1SetVariable(ectx: ExecutionContext, variableName: string, value) { diff --git a/src/avm1lib/AVM1MovieClip.ts b/src/avm1lib/AVM1MovieClip.ts index 136f33dda..f02625a1d 100644 --- a/src/avm1lib/AVM1MovieClip.ts +++ b/src/avm1lib/AVM1MovieClip.ts @@ -21,10 +21,21 @@ module Shumway.AVM2.AS.avm1lib { import asCoerceString = Shumway.AVM2.Runtime.asCoerceString; import construct = Shumway.AVM2.Runtime.construct; + import Multiname = Shumway.AVM2.ABC.Multiname; + import Namespace = Shumway.AVM2.ABC.Namespace; + import resolveMultinameProperty = Shumway.AVM2.Runtime.resolveMultinameProperty; import AVM1Context = Shumway.AVM1.AVM1Context; import Bitmap = flash.display.Bitmap; + var _asGetProperty = Object.prototype.asGetProperty; + var _asSetProperty = Object.prototype.asSetProperty; + var _asCallProperty = Object.prototype.asCallProperty; + var _asHasProperty = Object.prototype.asHasProperty; + var _asHasOwnProperty = Object.prototype.asHasOwnProperty; + var _asHasTraitProperty = Object.prototype.asHasTraitProperty; + var _asDeleteProperty = Object.prototype.asDeleteProperty; + var _asGetEnumerableKeys = Object.prototype.asGetEnumerableKeys; export class AVM1MovieClip extends ASNative { @@ -78,6 +89,41 @@ module Shumway.AVM2.AS.avm1lib { this._context = value; } + public asGetProperty(namespaces: Namespace [], name: any, flags: number) { + if (_asHasProperty.call(this, namespaces, name, flags)) { + return _asGetProperty.call(this, namespaces, name, flags); + } + var resolved = resolveMultinameProperty(namespaces, name, flags); + if (Multiname.isPublicQualifiedName(resolved)) { + return this.__lookupChild(Multiname.getNameFromPublicQualifiedName(resolved)); + } + return undefined; + } + + public asHasProperty(namespaces: Namespace [], name: any, flags: number) { + if (_asHasProperty.call(this, namespaces, name, flags)) { + return true; + } + var resolved = resolveMultinameProperty(namespaces, name, flags); + if (Multiname.isPublicQualifiedName(resolved)) { + return !!this.__lookupChild(Multiname.getNameFromPublicQualifiedName(resolved)); + } + return false; + } + + public asGetEnumerableKeys() { + var keys = _asGetEnumerableKeys.call(this); + // if it's a movie listing the children as well + var as3MovieClip = this._nativeAS3Object; + for (var i = 0, length = as3MovieClip._children.length; i < length; i++) { + var child = as3MovieClip._children[i]; + var name = child.name; + if (!_asHasProperty.call(this, undefined, name, 0)) { + keys.push(Multiname.getPublicQualifiedName(name)); + } + } + return keys; + } static _initFromConstructor(ctor, nativeMovieClip: flash.display.MovieClip): flash.display.MovieClip { var mc = Object.create(ctor.asGetPublicProperty('prototype')); @@ -195,10 +241,6 @@ module Shumway.AVM2.AS.avm1lib { return null; } var as2mc = getAVM1Object(mc); - var name:string = mc.name; - if (name && this.asGetPublicProperty(name) === undefined) { - this.asSetPublicProperty(name, as2mc); - } return as2mc; } diff --git a/src/avm1lib/flash.d.ts b/src/avm1lib/flash.d.ts index 1326c464a..2d4b9c990 100644 --- a/src/avm1lib/flash.d.ts +++ b/src/avm1lib/flash.d.ts @@ -22,8 +22,10 @@ declare module Shumway.AVM2.AS.flash { loaderInfo: { _avm1Context: AVM1.AVM1Context }; + name: string; _mouseOver: boolean; _mouseDown: boolean; + _children: DisplayObject []; } class MovieClip extends DisplayObject { _as2SymbolClass; diff --git a/test/swfs/avm1/lookup/avm1-childlookup.fla b/test/swfs/avm1/lookup/avm1-childlookup.fla new file mode 100644 index 0000000000000000000000000000000000000000..0d60e48955d9c7c7ce1f9ea0213895fddb827920 GIT binary patch literal 4900 zcmbtYcQjnv_a7~Ys4-$5Q74`@ghUw<-7rRr8bmkhDAAr?lMrDfqKy{ah$zuJF-oF$ zqJ%^Q!H6JAl;6mE`KGM*{`&2;_B!|6yZ1il-22(g44nU0q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WQ6ma@?VqyQ$mlsboylg{|82|F@*pC literal 0 HcmV?d00001 diff --git a/test/swfs/avm1/lookup/avm1-childlookup.swf b/test/swfs/avm1/lookup/avm1-childlookup.swf new file mode 100644 index 0000000000000000000000000000000000000000..95d0058db604a0c87ecd2e5015a580d3b7aa6277 GIT binary patch literal 759 zcmVS5py_1^@tfoTZgdQ`$fn#$Uic*qOFy4|O^oGC1SdL)avMNCv0~+VOxo z%Aq%BNfymC$)?#w@MLFt=_l~gOHV!b8}!(Ilb(9(tp~aZK~Sl+mYKl2Z=UCu&9h6= zgXtrH#~%R}V^E(@0l@i_)HFcJH{1F_eOu}|w##%eDyL64_jH81-EO9v%~1assl{Ru zDH_r=Stw+7=5pMVUACOANFkw4nBiLPp zWF9G{61tY;-Lf@}%V@ohZ-?t;8i?4$AueYkUNwx@H1sz09n34(^K8q&0TA_Mc0!HU zU3^O9b`W(5jfD4|lDM-*5HQq65{g2S#|)a)|hcz=ua;eSl@Sn1UoEV@nrtNXB