コード例 #1
0
        public static void LoadVariable(mdr.DObject context, int fieldId, int ancestorDistance, ref Stack stack)
        {
            mdr.PropertyDescriptor pd = null;

            //TODO: If we do not create a prototype for GlobalContext, the following code would have been enough!
            //var pd = context.GetPropertyDescriptorByLineId(fieldId);
            //pd.Get(context, ref stack.Items[stack.Sp++]);

            if (ancestorDistance < 0)
            {//We are dealing with unknown symbol type
                while (context != mdr.Runtime.Instance.GlobalContext)
                {
                    pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
                    if (pd != null)
                    {
                        break;
                    }
                    context = context.Prototype;
                }
            }
            else
            {//we are dealing with known symbol type
                for (var i = 0; i < ancestorDistance && context != mdr.Runtime.Instance.GlobalContext; ++i)
                {
                    context = context.Prototype;
                }
            }
            if (pd == null)
            {
                pd = context.GetPropertyDescriptorByFieldId(fieldId);
            }
            pd.Get(context, ref stack.Items[stack.Sp++]);
        }
コード例 #2
0
        public static void StoreVariable(mdr.DObject context, int fieldId, int ancestorDistance, bool pushBackResult, ref Stack stack)
        {
            var valueIndex = stack.Sp - 1;

            //TODO: If we do not create a prototype for GlobalContext, the following code would have been enough!
            //var pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
            //if (pd != null)
            //    pd.Set(context, ref stack.Items[stack.Sp - 1]);
            //else
            //    mdr.Runtime.Instance.GlobalContext.SetFieldByFieldId(fieldId, ref stack.Items[stack.Sp - 1]); //DOTO: this is very expensive!

            mdr.PropertyDescriptor pd = null;

            if (ancestorDistance < 0)
            {//We are dealing with unknown symbol type
             //while (context != mdr.Runtime.Instance.GlobalContext)
             //{
             //    pd = context.Map.GetCachedOwnPropertyDescriptorByFieldId(fieldId);
             //    if (pd != null)
             //        break;
             //    context = context.Prototype;
             //}
             //if (pd != null)
             //    pd.Set(context, ref stack.Items[stack.Sp - 1]);
             //else
             //    context.SetFieldByFieldId(fieldId, ref stack.Items[stack.Sp - 1]);

                pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
                if (pd != null && !pd.IsUndefined)
                {
                    pd.Set(context, ref stack.Items[valueIndex]);
                }
                else
                {
                    mdr.Runtime.Instance.GlobalContext.SetFieldByFieldId(fieldId, ref stack.Items[valueIndex]);
                }
            }
            else
            {//we are dealing with known symbol type
                for (var i = 0; i < ancestorDistance && context != mdr.Runtime.Instance.GlobalContext; ++i)
                {
                    context = context.Prototype;
                }
                pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
                Debug.Assert(pd != null && pd.IsDataDescriptor, "Invalid situation, variable is undeclared in current context");
                pd.Set(context, ref stack.Items[valueIndex]);
            }

            if (!pushBackResult)
            {
                stack.Sp = valueIndex;
            }
        }
コード例 #3
0
 public DForwardingProperty(DObject receiver, string field)
 {
     Receiver   = receiver;
     ReceiverPD = Receiver.Map.GetPropertyDescriptor(field);
     Debug.Assert(ReceiverPD != null, "receiver field has null descriptor: " + field);
     OnGetDValue = (DObject This, ref DValue v) =>
     {
         ReceiverPD.Get(Receiver, ref v);
     };
     OnSetDValue = (DObject This, ref DValue v) =>
     {
         ReceiverPD.Set(Receiver, ref v);
     };
 }
コード例 #4
0
ファイル: DForwardingProperty.cs プロジェクト: reshadi2/mcjs
 public DForwardingProperty (DObject receiver, string field)
 {
     Receiver = receiver;
     ReceiverPD = Receiver.Map.GetPropertyDescriptor(field);
     Debug.Assert(ReceiverPD != null, "receiver field has null descriptor: " + field);
     OnGetDValue = (DObject This, ref DValue v) =>
     {
         ReceiverPD.Get(Receiver, ref v);
     };
     OnSetDValue = (DObject This, ref DValue v) =>
     {
         ReceiverPD.Set(Receiver, ref v);
     };
 }
コード例 #5
0
        public void GetMapsPDsIndices(ref mdr.PropertyMap[] maps, ref mdr.PropertyDescriptor[] pds, ref int[] indices)
        {
            var length = MapProfileData.Count;

            maps    = new mdr.PropertyMap[length];
            pds     = new mdr.PropertyDescriptor[length];
            indices = new int[length];

            for (var i = 0; i < length; ++i)
            {
                maps[i]    = MapProfileData[i] == null ? null : MapProfileData[i].Map;
                pds[i]     = MapProfileData[i] == null ? null : MapProfileData[i].PD;
                indices[i] = MapProfileData[i] == null ? -1 : MapProfileData[i].index;
            }
        }
コード例 #6
0
        //public MapNodeProfile(mdr.PropertyMap map, mdr.PropertyDescriptor pd)
        //{
        //  Map = map;
        //  PD = pd;
        //  if (pd != null)
        //  {
        //    index = PD.Index;
        //  }
        //}

        /* Updates the map, pd and index */
        public void UpdateNodeProfile(mdr.PropertyMap map, mdr.PropertyDescriptor pd)
        {
            if (!IsTooDynamic)
            {
                if (Map == null)
                {
                    Map   = map;
                    PD    = pd;
                    index = pd.Index;
                }
                else
                {
                    if (Map != map || PD != pd)
                    {
                        IsTooDynamic = true;
                        Map          = null;
                        PD           = null;
                        index        = -1;
                    }
                }
            }
        }
コード例 #7
0
ファイル: Element.cs プロジェクト: vrajeshbhavsar/mcjs
        static void getAttribute(ref mdr.CallFrame callFrame)
        {
            var elem = (Element)callFrame.This;
            var name = callFrame.Arg0.AsString();

            mdr.PropertyDescriptor pd  = callFrame.This.GetPropertyDescriptor(name);
            EventHandlerProperty   ehp = null;

            if (pd != null)
            {
                ehp = pd.GetProperty() as EventHandlerProperty;
            }
            string val;

            if (ehp != null)
            {
                val = GetEventHandlerAttr(callFrame.This, ehp.EventType, name);
                callFrame.Return.Set(val);
                return;
            }
            val = elem.GetContentAttribute(name);
            callFrame.Return.Set(val);
        }
コード例 #8
0
        public void CreateNewProfile(ReadIndexerExpression node, mdr.PropertyMap map, mdr.PropertyDescriptor pd)
        {
            MapNodeProfile prof = new MapNodeProfile(map, pd);

            if (node.ProfileIndex == -1)
            {
                node.ProfileIndex = MapProfileData.Count;
                MapProfileData.Add(prof);
                jsMD.MapProfileSize++;
            }
            else
            {
                _resizeProfileData <MapNodeProfile>(MapProfileData, node.ProfileIndex + 1, null);
                MapProfileData[node.ProfileIndex] = prof;
            }
            HasMaps = true;
        }