Refactors looking up of the AVM1 movie children.

This commit is contained in:
Yury Delendik 2014-10-03 11:37:07 -05:00
Родитель 31f1f67548
Коммит 85221fd9fc
7 изменённых файлов: 59 добавлений и 35 удалений

Просмотреть файл

@ -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 = (<Shumway.AVM2.AS.avm1lib.AVM1MovieClip> 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 (<Shumway.AVM2.AS.avm1lib.AVM1MovieClip> 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) {

Просмотреть файл

@ -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;
}

2
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;

Двоичные данные
test/swfs/avm1/lookup/avm1-childlookup.fla Normal file

Двоичный файл не отображается.

Двоичные данные
test/swfs/avm1/lookup/avm1-childlookup.swf Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,3 @@
_root.label1 _root
label1 scope
label1(2) scope

Просмотреть файл

@ -258,6 +258,13 @@
],
"type": "stas"
},
{ "id": "avm1basic",
"stas": "swfs/trace.stas",
"filenames": [
"swfs/avm1/lookup/avm1-childlookup.swf"
],
"type": "stas"
},
{ "id": "flash_net_URLRequest trace",
"stas": "swfs/trace.stas",
"filenames": [