Beispiel #1
0
        public DValue Get(DObject obj)
        {
            DValue tmp = new DValue();

            Get(obj, ref tmp);
            return(tmp);
        }
Beispiel #2
0
 public static bool CallProperty(mdr.DObject input, string propName, out mdr.DValue output)
 {
     if (input != null)
     {
         var propDesc = input.GetPropertyDescriptor(propName);
         var prop     = new mdr.DValue();
         propDesc.Get(input, ref prop);
         mdr.DFunction func = null;
         if (prop.ValueType == mdr.ValueTypes.Function)
         {
             func = prop.AsDFunction();
             //if (toString != null)
             //{
             mdr.CallFrame callFrame = new mdr.CallFrame();
             callFrame.This     = (input);
             callFrame.Function = func;
             func.Call(ref callFrame);
             if (ValueTypesHelper.IsPrimitive(callFrame.Return.ValueType))
             {
                 output = callFrame.Return;
                 return(true);
             }
         }
     }
     output = new mdr.DValue();
     output.SetUndefined();
     return(false);
 }
Beispiel #3
0
 public static bool CallProperty(mdr.DObject input, string propName, out mdr.DValue output)
 {
   if (input != null)
   {
     var propDesc = input.GetPropertyDescriptor(propName);
     var prop = new mdr.DValue();
     propDesc.Get(input, ref prop);
     mdr.DFunction func = null;
     if (prop.ValueType == mdr.ValueTypes.Function)
     {
       func = prop.AsDFunction();
       //if (toString != null)
       //{
       mdr.CallFrame callFrame = new mdr.CallFrame();
       callFrame.This = (input);
       callFrame.Function = func;
       func.Call(ref callFrame);
       if (ValueTypesHelper.IsPrimitive(callFrame.Return.ValueType))
       {
         output = callFrame.Return;
         return true;
       }
     }
   }
   output = new mdr.DValue();
   output.SetUndefined();
   return false;
 }
Beispiel #4
0
        public virtual void Construct(ref CallFrame callFrame)
        {
            DValue proto = new DValue();

            PrototypePropertyDescriptor.Get(this, ref proto);
            var protoObj = proto.AsDObject();

            if (_prototypeMapMetadata == null || _prototypeMapMetadata.Prototype != protoObj)
            {
                _prototypeMapMetadata = Runtime.Instance.GetMapMetadataOfPrototype(protoObj);
            }
            callFrame.Function = this;
            if (Metadata != null)
            {
                callFrame.This = (new DObject(Metadata.TypicalConstructedFieldsLength, _prototypeMapMetadata.Root));
            }
            else
            {
                callFrame.This = (new DObject(0, _prototypeMapMetadata.Root));
            }
            JittedCode(ref callFrame);
            if (Metadata != null && Metadata.TypicalConstructedFieldsLength < callFrame.This.Fields.Length)
            {
                Metadata.TypicalConstructedFieldsLength = callFrame.This.Fields.Length;
            }
            if (ValueTypesHelper.IsObject(callFrame.Return.ValueType))
            {
                callFrame.This = callFrame.Return.AsDObject();
            }
        }
Beispiel #5
0
        public static bool Run(mdr.DObject i0, mdr.DFunction i1)
        {
            //var prototype = func.GetFieldByFieldIndex(mdr.DType.PrototypeIndex);
            var prototype = new mdr.DValue();

            i1.PrototypePropertyDescriptor.Get(i1, ref prototype);
            return(i0.Prototype == prototype.AsDObject());
        }
Beispiel #6
0
//#if __MonoCS__
//    [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
//#endif
        public void Get(DObject obj, ref DValue value)
        {
            /*if (mdr.Runtime.Instance.Configuration.ProfileStats)
             * {
             * mdr.Runtime.Instance.Counters.GetCounter("PD.GET").Count++;
             * mdr.Runtime.Instance.Counters.GetCounter("PD.GET[" + _flags + "]").Count++;
             * } */
            _getter(this, obj, ref value);
        }
Beispiel #7
0
        public DValue[] Fields; // = new DValue[0];//This is explicityly left unprotected to reduce access overhead
        void ResizeFields(int maxIndex)
        {
            if (maxIndex >= Fields.Length)
            {
                int newCapacity = maxIndex + 8; //TODO: should we just extend by one?

                var newFields = new DValue[newCapacity];
                Array.Copy(Fields, newFields, Fields.Length);
                Fields = newFields;
            }
        }
Beispiel #8
0
 public void Set(DObject obj, DObject value)
 {
     if (_setter == Own_Data_Set) //This is the most common case, and we can make it faster this way
     {
         obj.Fields[Index].Set(value);
     }
     else
     {
         var tmp = new DValue();
         tmp.Set(value);
         Set(obj, ref tmp);
     }
 }
Beispiel #9
0
 public DObject Set(DObject This, bool v)
 {
     if (OnSetBoolean == null)
     {
         var tmp = new DValue();
         tmp.Set(v);
         return(Set(This, ref tmp));
     }
     else
     {
         OnSetBoolean(This, v);
         return(this);
     }
 }
Beispiel #10
0
 public DObject Set(DObject This, DObject v)
 {
     if (OnSetDObject == null)
     {
         var tmp = new DValue();
         tmp.Set(v);
         return(Set(This, ref tmp));
     }
     else
     {
         OnSetDObject(This, v);
         return(this);
     }
 }
Beispiel #11
0
 public void Set(DObject obj, string value)
 {
     //if (IsDataDescriptor && !IsInherited)
     if (_setter == Own_Data_Set) //This is the most common case, and we can make it faster this way
     {
         obj.Fields[Index].Set(value);
     }
     else
     {
         var tmp = new DValue();
         tmp.Set(value);
         Set(obj, ref tmp);
     }
 }
Beispiel #12
0
 public DArray(int initialSize = 0)
     : base(Runtime.Instance.DArrayMap)
 {
     //We don't need the high overhead of ResizeElements
     ElementsLength = initialSize;
     if (initialSize == 0)
     {
         initialSize = 10; //this ensures we have at least a few items in the array and will not resize a lot
     }
     if (Elements == null || Elements.Length < initialSize)
     {
         Elements = new DValue[initialSize];
     }
 }
Beispiel #13
0
        public void SetArg(int i, ref DValue v)
        {
            switch (i)
            {
            case 0: Arg0.Set(ref v); break;

            case 1: Arg1.Set(ref v); break;

            case 2: Arg2.Set(ref v); break;

            case 3: Arg3.Set(ref v); break;

            default: Arguments[i - InlineArgsCount].Set(ref v); break;
            }
            //UpdateSignature(i);
        }
Beispiel #14
0
        public DValue[] Elements; //This is explicityly left unprotected to reduce access overhead
        public void ResizeElements(int maxIndex)
        {
            var capacity = Elements.Length;

            if (maxIndex >= capacity)
            {
                int newCapacity = Math.Min(maxIndex * 2, MaxElementsCount);
                if (newCapacity == capacity)
                {
                    Trace.Fail("Element index is too big!");
                }

                var newElements = new DValue[newCapacity];
                Array.Copy(Elements, newElements, Elements.Length);
                Elements = newElements;
            }
        }
Beispiel #15
0
        public PropertyMap.DeleteStatus DeletePropertyDescriptor(ref DValue field)
        {
            switch (field.ValueType)
            {
            case ValueTypes.Undefined: return(DeletePropertyDescriptor(Runtime.Instance.DefaultDUndefined.ToString()));

            case ValueTypes.String: return(DeletePropertyDescriptor(field.AsString()));

            case ValueTypes.Char: return(DeletePropertyDescriptor(field.AsChar()));

            case ValueTypes.Boolean: return(DeletePropertyDescriptor(field.AsBoolean()));

            case ValueTypes.Float: return(DeletePropertyDescriptor(field.AsFloat()));

            case ValueTypes.Double: return(DeletePropertyDescriptor(field.AsDouble()));

            case ValueTypes.Int8: return(DeletePropertyDescriptor(field.AsInt8()));

            case ValueTypes.Int16: return(DeletePropertyDescriptor(field.AsInt16()));

            case ValueTypes.Int32: return(DeletePropertyDescriptor(field.AsInt32()));

            case ValueTypes.Int64: return(DeletePropertyDescriptor(field.AsInt64()));

            case ValueTypes.UInt8: return(DeletePropertyDescriptor(field.AsUInt8()));

            case ValueTypes.UInt16: return(DeletePropertyDescriptor(field.AsUInt16()));

            case ValueTypes.UInt32: return(DeletePropertyDescriptor(field.AsUInt32()));

            case ValueTypes.UInt64: return(DeletePropertyDescriptor(field.AsUInt64()));

            case ValueTypes.Object:
            case ValueTypes.Function:
            case ValueTypes.Array:
                //case ValueTypes.Property:
                return(DeletePropertyDescriptor(field.AsDObject().ToString()));

            case ValueTypes.Null: return(DeletePropertyDescriptor(Runtime.Instance.DefaultDNull.ToString()));
                //default:
                //    return DeletePropertyDescriptor(field.ToString()); //This should never happen
            }
            Trace.Fail(new InvalidOperationException(string.Format("Cannot delete property using field index type {0}", field.ValueType)));
            return(PropertyMap.DeleteStatus.NotFound);
        }
Beispiel #16
0
        public static Result Run(mdr.DObject i0, mdr.DObject i1, bool LeftFirst)
        {
            var pLeft  = new mdr.DValue();
            var pRight = new mdr.DValue();

            if (LeftFirst)
            {
                Convert.ToPrimitive.Run(i0, ref pLeft, false);
                Convert.ToPrimitive.Run(i1, ref pRight, false);
            }
            else
            {
                Convert.ToPrimitive.Run(i1, ref pRight, false);
                Convert.ToPrimitive.Run(i0, ref pLeft, false);
            }

            return(Run(ref pLeft, ref pRight));
        }
Beispiel #17
0
        //#region ToX
        //public string ToString(DObject This) { return (OnGetString != null) ? OnGetString(This) : ToDValue().ToString(); }// base.ToString(); }
        //public double ToDouble(DObject This) { return (OnGetDouble != null) ? OnGetDouble(This) : ToDValue().ToDouble(); }// base.ToDouble(); }
        //public int ToInt(DObject This) { return (OnGetInt != null) ? OnGetInt(This) : ToDValue().ToInt32(); }// base.ToInt(); }
        //public bool ToBoolean(DObject This) { return (OnGetBoolean != null) ? OnGetBoolean(This) : ToDValue().ToBoolean(); }// base.ToBoolean(); }
        //public DObject ToDObject(DObject This) { return (OnGetDObject != null) ? OnGetDObject(This) : ToDValue().ToDObject(); }// base.ToDObject(); }
        //public DValue ToDValue(DObject This)
        //{
        //    if (OnGetDValue != null)
        //    {
        //        DValue temp = new DValue();
        //        OnGetDValue(This, ref temp);
        //        return temp;
        //    }
        //    else
        //    {
        //        return base.ToDValue();
        //    }
        //}
        //#endregion

        #region Get
        public void Get(DObject This, ref DValue v)
        {
            if (OnGetDValue != null)
            {
                OnGetDValue(This, ref v);
            }
            else if (Getter != null)
            {
                var callFrame = new CallFrame();
                callFrame.Function = Getter;
                callFrame.This     = (This);
                Getter.Call(ref callFrame);
                v = callFrame.Return;
            }
            else
            {
                v = base.ToDValue();
            }
        }
Beispiel #18
0
        public DValue PrimitiveValue; // { get { return Fields[0][0]; } set { Fields[0][0] = value; } }
        //int _valueOfIndex = DType.InvalidIndex;
        //public DFunction ValueOfProperty
        //{
        //    get
        //    {
        //        if (_valueOfIndex != DType.InvalidIndex)
        //        {
        //            int row, col;
        //            FieldIndexToRowCol(_valueOfIndex, out row, out col);
        //            if (Fields[row][col].ValueType == ValueTypes.Function)
        //                return Fields[row][col].DObjectValue as DFunction;
        //        }
        //        return null;
        //    }
        //}

        //int _toStringIndex = DType.InvalidIndex;
        //public DFunction ToStringProperty
        //{
        //    get
        //    {
        //        if (_toStringIndex != DType.InvalidIndex)
        //        {
        //            int row, col;
        //            FieldIndexToRowCol(_toStringIndex, out row, out col);
        //            if (Fields[row][col].ValueType == ValueTypes.Function)
        //                return Fields[row][col].DObjectValue as DFunction;
        //        }
        //        return null;
        //    }
        //}

        protected string ToStringProperty()
        {
            var toStringPD = GetPropertyDescriptorByFieldId(Runtime.Instance.ToStringFieldId);

            if (!toStringPD.IsUndefined)
            {
                var    cf           = new mdr.CallFrame();
                DValue toStringFunc = toStringPD.Get(this);
                cf.Function  = toStringFunc.AsDFunction();
                cf.Signature = mdr.DFunctionSignature.EmptySignature;
                cf.This      = (this);
                cf.Function.Call(ref cf);
                return(cf.Return.AsString());
            }
            else
            {
                return(ToString());
            }
        }
Beispiel #19
0
 public DObject Set(DObject This, ref DValue v)
 {
     if (OnSetDValue != null)
     {
         OnSetDValue(This, ref v);
     }
     else if (Setter != null)
     {
         var callFrame = new CallFrame();
         callFrame.Function        = Setter;
         callFrame.This            = (This);
         callFrame.PassedArgsCount = 1;
         callFrame.Arg0            = v;
         callFrame.Signature.InitArgType(0, v.ValueType);
         Setter.Call(ref callFrame);
     }
     else
     {
         Trace.Fail(new NotSupportedException(string.Format("Cannot find setter for {0}:{1} on property {2}", v, typeof(DValue), base.ToString())));
     }
     return(this);
 }
Beispiel #20
0
        public static void DefaultValue(mdr.DObject input, out mdr.DValue output, bool stringHint = false)
        {
            if (input.PrimitiveValue.ValueType != mdr.ValueTypes.Undefined)
            {
                output = input.PrimitiveValue;
                return;
            }

            if (stringHint)
            {
                if (!CallToStringProperty(input, out output) && !CallValueOfProperty(input, out output))
                {
                    Trace.Fail(new InvalidOperationException(string.Format("TypeError: DefaultValue for {0} is unknown", input.ValueType)));
                }
            }
            else //assume number hint
            {
                if (!CallValueOfProperty(input, out output) && !CallToStringProperty(input, out output))
                {
                    Trace.Fail(new InvalidOperationException(string.Format("TypeError: DefaultValue for {0} is unknown", input.ValueType)));
                }
            }
        }
Beispiel #21
0
 public static DValue Create(double v)
 {
     var dv = new DValue(); dv.Set(v); return(dv);
 }
Beispiel #22
0
 internal DNull()
     : base(Runtime.Instance.EmptyPropertyMapMetadata.Root)
 {
     Fields = new DValue[1];
     Fields[0].Set(this);
 }
Beispiel #23
0
        }                                                                       //To make sure CodeGen can detect this

        public void Set(DObject obj, ref DValue value)
        {
            _setter(this, obj, ref value);
        }
Beispiel #24
0
 public static bool CallValueOfProperty(mdr.DObject input, out mdr.DValue output)
 {
     return(CallProperty(input, "valueOf", out output));
 }
Beispiel #25
0
 /// <summary>
 /// ECMA-262, 8.12.8: Implements [[DefaultValue]] for JS objects
 /// </summary>
 /// <param name="input"></param>
 /// <param name="output"></param>
 /// <param name="stringHint">Specifies whether the hint is string or number. Default is number.</param>
 public static void DefaultValue(ref mdr.DValue input, out mdr.DValue output, bool stringHint = false)
 {
     Debug.Assert(ValueTypesHelper.IsObject(input.ValueType));
     DefaultValue(input.AsDObject(), out output, stringHint);
 }
Beispiel #26
0
 /// <summary>
 /// if the toString property of the input is a callable, calls it and sets the result in the output
 /// </summary>
 /// <param name="input">input</param>
 /// <param name="output">The return value of toString property</param>
 /// <returns>true if toString is callable and returns a primitive value, otherwise return false</returns>
 public static bool CallToStringProperty(ref mdr.DValue input, out mdr.DValue output)
 {
     return(CallToStringProperty(input.AsDObject(), out output));
 }
Beispiel #27
0
 public static void Run(mdr.DObject i0, /*const*/ ref mdr.DValue i1, ref mdr.DValue result)
 {
     throw new NotImplementedException();
 }
Beispiel #28
0
 public static bool CallToStringProperty(mdr.DObject input, out mdr.DValue output)
 {
     return(CallProperty(input, "toString", out output));
 }
Beispiel #29
0
 public static DValue Create(string v)
 {
     var dv = new DValue(); dv.Set(v); return(dv);
 }
Beispiel #30
0
    public static Result Run(mdr.DObject i0, mdr.DObject i1, bool LeftFirst)
    {
      var pLeft = new mdr.DValue();
      var pRight = new mdr.DValue();
      if (LeftFirst)
      {
        Convert.ToPrimitive.Run(i0, ref pLeft, false);
        Convert.ToPrimitive.Run(i1, ref pRight, false);
      }
      else
      {
        Convert.ToPrimitive.Run(i1, ref pRight, false);
        Convert.ToPrimitive.Run(i0, ref pLeft, false);
      }

      return Run(ref pLeft, ref pRight);
    }
Beispiel #31
0
 public static bool Run(mdr.DObject i0, mdr.DFunction i1)
 {
   //var prototype = func.GetFieldByFieldIndex(mdr.DType.PrototypeIndex);
   var prototype = new mdr.DValue();
   i1.PrototypePropertyDescriptor.Get(i1, ref prototype);
   return (i0.Prototype == prototype.AsDObject());
 }
Beispiel #32
0
 public void Set(ref DValue v)
 {
     this = v;
 }
Beispiel #33
0
 public static DValue Create(DObject v)
 {
     var dv = new DValue(); dv.Set(v); return(dv);
 }