private static IEnumerator <RunTimeValueBase> getForEach_IEnumerator( Player player,ASBinCode.rtti.Object obj,StackFrame frame,OpStep step,RunTimeScope scope, Dictionary <object,object> visited = null ) { if (obj is ASBinCode.rtti.DynamicObject) { ASBinCode.rtti.DynamicObject dobj = (ASBinCode.rtti.DynamicObject)obj; { var k = dobj.eachSlot(); while (k.MoveNext()) { var c = k.Current; DynamicPropertySlot ds = c as DynamicPropertySlot; if (c != null) { yield return(ds.getValue()); //new rtString(ds._propname); } } } if (obj is DictionaryObject) { DictionaryObject dictObj = (DictionaryObject)obj; var k = dictObj.eachDictSlot(); while (k.MoveNext()) { var c = k.Current; DictionarySlot ds = c as DictionarySlot; if (c != null) { yield return(ds.getValue()); //ds._key.key; } } } if (visited == null) { visited = new Dictionary <object,object>(); } //***再到原型链中查找 if (dobj._prototype_ != null) { var protoObj = dobj._prototype_; //****_prototype_的类型,只可能是Function对象或Class对象 if (protoObj._class.classid == player.swc.FunctionClass.classid) //Function { dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[1].getValue()).value; if (visited.ContainsKey(dobj)) { yield break; } visited.Add(dobj,null); var res = getForEach_IEnumerator(player,dobj,frame,step,scope,visited); while (res.MoveNext()) { yield return(res.Current); } } else if (protoObj._class.classid == 1) //搜索到根Object { //***根Object有继承自Class的prototype,再没有就没有了 dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[0].getValue()).value; { var k = dobj.eachSlot(); while (k.MoveNext()) { var c = k.Current; DynamicPropertySlot ds = c as DynamicPropertySlot; if (c != null) { yield return(ds.getValue()); //new rtString(ds._propname); } } } yield break; } else if (protoObj._class.staticClass == null) { dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[0].getValue()).value; var res = getForEach_IEnumerator(player,dobj,frame,step,scope); while (res.MoveNext()) { yield return(res.Current); } } else { frame.throwError((new error.InternalError(frame.player.swc,step.token, "遭遇了异常的_prototype_" ))); yield break; } } } else if (obj is ASBinCode.rtti.Object) { //***处理.net IEnumerable*** System.Collections.IEnumerator enumerator = null; if (obj is LinkSystemObject) { var od = ((LinkSystemObject)obj).GetLinkData(); if (od is System.Collections.IEnumerable) { enumerator = ((System.Collections.IEnumerable)od).GetEnumerator(); } else { enumerator = od as System.Collections.IEnumerator; } } if (enumerator != null) { var e = enumerator; while (e.MoveNext()) { int slotidx = frame.baseBottomSlotIndex; if (slotidx >= Player.STACKSLOTLENGTH) { throw new ASRunTimeException("stack overflow",frame.player.stackTrace(0)); } var tempslot = frame.stack[slotidx]; try { player.linktypemapper.storeLinkObject_ToSlot(e.Current,RunTimeDataType.rt_void,frame._tempSlot2,player.swc,player); } finally { tempslot.clear(); } yield return(frame._tempSlot2.getValue()); } } else { var dobj = ((ASBinCode.rtti.DynamicObject) frame.player.static_instance[obj._class.staticClass.classid].value); dobj = (ASBinCode.rtti.DynamicObject)((rtObjectBase)dobj.memberData[0].getValue()).value; var res = getForEach_IEnumerator(player,dobj,frame,step,scope); while (res.MoveNext()) { yield return(res.Current); } } } yield break; }
private static IEnumerator <RunTimeValueBase> getForinIEnumerator( Player player,ASBinCode.rtti.Object obj,StackFrame frame,OpStep step,RunTimeScope scope, Dictionary <object,object> visited = null ) { if (obj is ASBinCode.rtti.DynamicObject) { ASBinCode.rtti.DynamicObject dobj = (ASBinCode.rtti.DynamicObject)obj; { var k = dobj.eachSlot(); while (k.MoveNext()) { var c = k.Current; DynamicPropertySlot ds = c as DynamicPropertySlot; if (c != null) { yield return(new rtString(ds._propname)); } } } if (obj is DictionaryObject) { DictionaryObject dictObj = (DictionaryObject)obj; var k = dictObj.eachDictSlot(); while (k.MoveNext()) { var c = k.Current; DictionarySlot ds = c as DictionarySlot; if (c != null) { yield return(ds._key.key); } } } if (visited == null) { visited = new Dictionary <object,object>(); } //***再到原型链中查找 if (dobj._prototype_ != null) { var protoObj = dobj._prototype_; //****_prototype_的类型,只可能是Function对象或Class对象 if (protoObj._class.classid == player.swc.FunctionClass.classid) //Function { dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[1].getValue()).value; if (visited.ContainsKey(dobj)) { yield break; } visited.Add(dobj,null); var res = getForinIEnumerator(player,dobj,frame,step,scope,visited); while (res.MoveNext()) { yield return(res.Current); } } else if (protoObj._class.classid == 1) //搜索到根Object { //***根Object有继承自Class的prototype,再没有就没有了 dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[0].getValue()).value; { var k = dobj.eachSlot(); while (k.MoveNext()) { var c = k.Current; DynamicPropertySlot ds = c as DynamicPropertySlot; if (c != null) { yield return(new rtString(ds._propname)); } } } yield break; } else if (protoObj._class.staticClass == null) { dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[0].getValue()).value; var res = getForinIEnumerator(player,dobj,frame,step,scope); while (res.MoveNext()) { yield return(res.Current); } } else { frame.throwError((new error.InternalError(frame.player.swc,step.token, "遭遇了异常的_prototype_" ))); yield break; } } } else if (obj is ASBinCode.rtti.Object) { var dobj = ((ASBinCode.rtti.DynamicObject) frame.player.static_instance[obj._class.staticClass.classid].value); dobj = (ASBinCode.rtti.DynamicObject)((rtObjectBase)dobj.memberData[0].getValue()).value; var res = getForinIEnumerator(player,dobj,frame,step,scope); while (res.MoveNext()) { yield return(res.Current); } } yield break; }