예제 #1
0
        public static void exec_delete(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            {
                StackSlot slot = (StackSlot)((StackSlotAccessor)step.arg1).getSlot(scope, frame);

                var ls = slot.getLinkSlot();

                if (ls is DynamicPropertySlot)
                {
                    DynamicPropertySlot link = (DynamicPropertySlot)ls;
                    if (link._canDelete)
                    {
                        ((ASBinCode.rtti.DynamicObject)link.obj.value).deleteProperty(link._propname);
                    }
                    else
                    {
                        if (link.backup != null)
                        {
                            link.directSet(link.backup);
                        }
                    }
                }
                else if (ls is DictionarySlot)
                {
                    DictionarySlot link = (DictionarySlot)ls;
                    ((ASBinCode.rtti.DictionaryObject)link.obj.value).RemoveKey(link._key);
                }
                else if (ls is OpAccess_Dot.arraySlot) //(slot.fromArray != null)
                {
                    //slot.directSet(rtUndefined.undefined);
                    //bool success;
                    //slot.assign(rtUndefined.undefined,out success);

                    ((OpAccess_Dot.arraySlot)ls).delete();


                    //slot.fromArray.innerArray[slot.fromArrayIndex] = rtUndefined.undefined;
                }
                else if (ls is OpAccess_Dot.prototypeSlot)
                {   //原型链对象,不可删除
                }
                else if (ls is OpVector.vectorSLot)
                {
                    //数组链接,跳过
                }
                else
                {
                    frame.throwError(
                        step.token, 0,
                        "动态属性才能被delete"
                        );
                }

                slot.linkTo(null);

                frame.endStep(step);
            }
        }
        public static void exec_link(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            StackSlot l = (StackSlot)step.reg.getSlot(scope, frame);

            int classid = ((ASBinCode.rtData.rtInt)step.arg2.getValue(scope, frame)).value;

            var outscope = frame.player.outpackage_runtimescope[classid];

            SLOT outpackagescopeslot = ((VariableBase)step.arg1).getSlot(outscope,null);

            StackSlotAccessor register = (StackSlotAccessor)step.reg;

            if (register._isassigntarget || register._hasUnaryOrShuffixOrDelete)
            {
                l.linkTo(outpackagescopeslot);
            }
            else
            {
                l.directSet(outpackagescopeslot.getValue());
            }
            frame.endStep(step);
        }
예제 #3
0
        public static void exec_try_read_prop(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            ASBinCode.SLOT slot = ((StackSlotAccessor)step.arg1).getSlot(scope,frame);

            if (slot.isPropGetterSetter)
            {
                ((StackSlot)slot).linkTo(null);
                _do_prop_read(

                    ((StackSlot)slot).stackObjects.propGetSet,
                    frame,step,frame.player,scope,((StackSlot)slot).stackObjects.propBindObj,((StackSlot)slot).stackObjects.superPropBindClass
                    );
            }
            else if (slot.isSetThisItem)
            {
                SetThisItemSlot sslot = (SetThisItemSlot)((StackSlot)slot).getLinkSlot();

                ((StackSlot)slot).linkTo(null);

                //***调用索引器get***
                RunTimeValueBase func;
                var rtObj  = sslot.bindObj;
                var player = frame.player;
                var v2     = sslot.setindex;
                func = ((MethodGetterBase)sslot.get_this_item.bindField).getMethod(
                    rtObj
                    );

                var funCaller = player.funcCallerPool.create(frame,step.token);
                funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear();
                funCaller.loadDefineFromFunction();
                if (!funCaller.createParaScope())
                {
                    return;
                }

                //funCaller.releaseAfterCall = true;

                bool success;
                funCaller.pushParameter(v2,0,out success);
                if (!success)
                {
                    frame.endStep(step);
                    return;
                }

                funCaller._tempSlot  = frame._tempSlot1;
                funCaller.returnSlot = step.reg.getSlot(scope,frame);

                StackSlot ret = (StackSlot)funCaller.returnSlot;
                ret.stackObjects._temp_try_write_setthisitem = ret._cache_setthisslot; ret.refPropChanged = true;
                ret._cache_setthisslot.bindObj       = rtObj;
                ret._cache_setthisslot.setindex      = v2;
                ret._cache_setthisslot.set_this_item = sslot.set_this_item;

                BlockCallBackBase cb = frame.player.blockCallBackPool.create();
                cb.setCallBacker(D_get_this_item_callbacker);
                cb.step = step;
                cb.args = frame;

                funCaller.callbacker = cb;
                funCaller.call();

                return;
            }
            else
            {
                SLOT regslot = step.reg.getSlot(scope,frame);

                StackSlot d = regslot as StackSlot;
                StackSlot s = slot as StackSlot;

                if (d != null && s != null && s.getLinkSlot() != null)
                {
                    d.linkTo(s.getLinkSlot());
                    s.linkTo(null);
                }
                else
                {
                    regslot.directSet(slot.getValue());
                }
                //frame.endStep(step);
                frame.endStepNoError();
            }
        }
        public static void exec_AccessorBind_ConvertIdx(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            RunTimeValueBase obj = step.arg1.getValue(scope, frame);

            if (rtNull.nullptr.Equals(obj))
            {
                frame.throwError(

                    step.token, 1009, "Cannot access a property or method of a null object reference."

                    );
                frame.endStep();
                return;
            }
            ASBinCode.rtti.Vector_Data vector =
                (ASBinCode.rtti.Vector_Data)((ASBinCode.rtti.HostedObject)((ASBinCode.rtData.rtObjectBase)obj).value).hosted_object;


            var idxvalue = step.arg2.getValue(scope, frame);

            double idx = double.NaN;

            if (idxvalue.rtType > RunTimeDataType.unknown)
            {
                RunTimeDataType ot;
                if (TypeConverter.Object_CanImplicit_ToPrimitive(idxvalue.rtType, frame.player.swc, out ot))
                {
                    var v = TypeConverter.ObjectImplicit_ToPrimitive((rtObjectBase)idxvalue);
                    idx = TypeConverter.ConvertToNumber(v);
                }
            }
            else if (idxvalue.rtType == RunTimeDataType.rt_string ||
                     idxvalue.rtType == RunTimeDataType.rt_int ||
                     idxvalue.rtType == RunTimeDataType.rt_number ||
                     idxvalue.rtType == RunTimeDataType.rt_uint
                     )
            {
                idx = TypeConverter.ConvertToNumber(idxvalue);
            }

            if (double.IsNaN(idx))
            {
                frame.throwError(

                    step.token, 0,
                    "索引" + idxvalue + "不能转为int"

                    );
            }
            else
            {
                int index = (int)idx;

                if (index < 0 || index > vector.innnerList.Count)
                {
                    frame.throwError(step.token, 1125,
                                     "The index " + index + " is out of range " + vector.innnerList.Count + ".");
                }

                StackSlotAccessor reg = (StackSlotAccessor)step.reg;

                if (idx == vector.innnerList.Count)
                {
                    if (vector.isFixed || !reg._isassigntarget)
                    {
                        frame.throwError(step.token,
                                         1125,
                                         "The index " + idx + " is out of range " + vector.innnerList.Count + ".");
                        frame.endStep(step);
                        return;
                    }
                    else
                    {
                        vector.innnerList.Add(TypeConverter.getDefaultValue(vector.vector_type).getValue(null, null));
                    }
                }


                StackSlot slot = (StackSlot)step.reg.getSlot(scope, frame);

                if (reg._isassigntarget || reg._hasUnaryOrShuffixOrDelete)
                {
                    slot._cache_vectorSlot.idx         = index;
                    slot._cache_vectorSlot.vector_data = vector;

                    slot.linkTo(slot._cache_vectorSlot);
                }
                else
                {
                    slot.directSet(vector.innnerList[index]);
                }
            }


            frame.endStep(step);
        }
        public static void exec_AccessorBind(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            RunTimeValueBase obj = step.arg1.getValue(scope, frame);

            if (rtNull.nullptr.Equals(obj))
            {
                frame.throwError(

                    step.token, 1009, "Cannot access a property or method of a null object reference."

                    );
                frame.endStep();
                return;
            }


            ASBinCode.rtti.Vector_Data vector =
                (ASBinCode.rtti.Vector_Data)((ASBinCode.rtti.HostedObject)((rtObjectBase)obj).value).hosted_object;

            int idx = TypeConverter.ConvertToInt(step.arg2.getValue(scope, frame));

            if (idx < 0 || idx > vector.innnerList.Count)
            {
                frame.throwError(step.token, 1125,
                                 "The index " + idx + " is out of range " + vector.innnerList.Count + ".");
            }

            StackSlotAccessor reg = (StackSlotAccessor)step.reg;

            if (idx == vector.innnerList.Count)
            {
                if (vector.isFixed || !reg._isassigntarget)
                {
                    frame.throwError(step.token, 1125,
                                     "The index " + idx + " is out of range " + vector.innnerList.Count + "."
                                     );
                    frame.endStep(step);
                    return;
                }
                else
                {
                    vector.innnerList.Add(TypeConverter.getDefaultValue(vector.vector_type).getValue(null, null));
                }
            }



            StackSlot slot = (StackSlot)step.reg.getSlot(scope, frame);

            if (reg._isassigntarget || reg._hasUnaryOrShuffixOrDelete)
            {
                slot._cache_vectorSlot.idx         = idx;
                slot._cache_vectorSlot.vector_data = vector;

                slot.linkTo(slot._cache_vectorSlot);
            }
            else
            {
                slot.directSet(vector.innnerList[idx]);
            }

            frame.endStep(step);
        }