示例#1
0
        public static void GetFieldUsingIC(DObject obj, int fieldId, ref DValue v, int mapId, int fieldIndex)
        {
#if __STAT__PD
            if (mdr.Runtime.Instance.Configuration.ProfileStats)
            {
                mdr.Runtime.Instance.Counters.GetCounter("IC calls").Count++;
            }
#endif
            if (mapId == obj.MapId)
            {
                v = obj.Fields[fieldIndex];
#if __STAT__PD
                if (mdr.Runtime.Instance.Configuration.ProfileStats)
                {
                    mdr.Runtime.Instance.Counters.GetCounter("IC hit").Count++;
                    mdr.Runtime.Instance.Counters.GetCounter("IC hit findex_" + fieldIndex).Count++;
                }
#endif
            }
            else
            {
                obj.GetPropertyDescriptorByFieldId(fieldId).Get(obj, ref v);
#if __STAT__PD
                if (mdr.Runtime.Instance.Configuration.ProfileStats)
                {
                    mdr.Runtime.Instance.Counters.GetCounter("IC miss").Count++;
                }
#endif
            }
        }
示例#2
0
        private void SetAttribute(string key, object value, IObjectBuilder builder)
        {
            var dValue = DValue.GetDValue(value);

            if (dValue.StrValue != null)
            {
                builder.SetAttribute(key, dValue.StrValue);
            }
            if (dValue.IntValue != null)
            {
                builder.SetAttribute(key, dValue.IntValue.Value);
            }
            if (dValue.DateValue != null)
            {
                builder.SetAttribute(key, dValue.DateValue.Value);
            }
            if (dValue.DoubleValue != null)
            {
                builder.SetAttribute(key, dValue.DoubleValue.Value);
            }
            if (dValue.DecimalValue != null)
            {
                builder.SetAttribute(key, dValue.DecimalValue.Value);
            }
            if (dValue.LongValue != null)
            {
                builder.SetAttribute(key, dValue.LongValue.Value);
            }
            if (dValue.GuidValue != null)
            {
                builder.SetAttribute(key, dValue.GuidValue.Value);
            }
        }
示例#3
0
        public static void GetInheritFieldUsingIC(DObject obj, int fieldId, ref DValue v, int mapId, int fieldIndex, int inheritObjectCacheIndex)
        {
#if __STAT__PD
            if (mdr.Runtime.Instance.Configuration.ProfileStats)
            {
                mdr.Runtime.Instance.Counters.GetCounter("Inh IC calls").Count++;
            }
#endif
            if (mapId == obj.MapId)
            {
                DObject patentObj = JSRuntime._inheritPropertyObjectCache[inheritObjectCacheIndex];
                if (patentObj != null)
                {
                    v = patentObj.Fields[fieldIndex];
#if __STAT__PD
                    if (mdr.Runtime.Instance.Configuration.ProfileStats)
                    {
                        mdr.Runtime.Instance.Counters.GetCounter("Inh IC hits").Count++;
                        mdr.Runtime.Instance.Counters.GetCounter("Inh IC hit oindex_" + inheritObjectCacheIndex).Count++;
                        mdr.Runtime.Instance.Counters.GetCounter("Inh IC hit findex_" + fieldIndex).Count++;
                    }
#endif
                }
            }
            else
            {
                obj.GetPropertyDescriptorByFieldId(fieldId).Get(obj, ref v);
#if __STAT__PD
                if (mdr.Runtime.Instance.Configuration.ProfileStats)
                {
                    mdr.Runtime.Instance.Counters.GetCounter("Inh IC misses").Count++;
                }
#endif
            }
        }
示例#4
0
文件: JSObject.cs 项目: reshadi2/mcjs
        private void DefineProperty(DObject O, string name, DObject desc)
        {
          if (desc == null || O == null || name == null)
            Trace.Fail("TypeError");

          var getter = new DValue();
          var setter = new DValue();
          var value = new DValue();
          var attributes = PropertyDescriptor.Attributes.NotEnumerable | PropertyDescriptor.Attributes.NotWritable | PropertyDescriptor.Attributes.NotConfigurable;

          attributes = PropertyDescriptor.Attributes.NotEnumerable | PropertyDescriptor.Attributes.NotWritable | PropertyDescriptor.Attributes.NotConfigurable;

          getter.SetUndefined();
          setter.SetUndefined();
          value.SetUndefined();

          value = desc.HasProperty("value") ? desc.GetField("value") : value;

          if (desc.HasProperty("enumerable"))
            attributes &= desc.GetField("enumerable").AsBoolean() ? ~PropertyDescriptor.Attributes.NotEnumerable : attributes;


          if (desc.HasProperty("configurable"))
            attributes &= desc.GetField("configurable").AsBoolean() ? ~PropertyDescriptor.Attributes.NotConfigurable : attributes;

          if (desc.HasProperty("writable"))
            attributes &= desc.GetField("writable").AsBoolean() ? ~PropertyDescriptor.Attributes.NotWritable : attributes;

          if (desc.HasProperty("get"))
          {
            getter = desc.GetField("get");
            if (!ValueTypesHelper.IsUndefined(getter.ValueType) && !ValueTypesHelper.IsFunction(getter.ValueType))
              Trace.Fail("TypeError");
          }

          if (desc.HasProperty("set"))
          {
            setter = desc.GetField("set");
            if (!ValueTypesHelper.IsUndefined(setter.ValueType) && !ValueTypesHelper.IsFunction(setter.ValueType))
              Trace.Fail("TypeError");
          }

          Trace.Assert(
            !((desc.HasProperty("get") || desc.HasProperty("set"))
            && (desc.HasProperty("value") || desc.HasProperty("writable"))),
            "If either getter or setter needs to be defined, value or writable shouldn't be defined.");

          if (desc.HasProperty("value"))
            O.DefineOwnProperty(name, ref value, attributes | PropertyDescriptor.Attributes.Data);
          else
          {
            var property = new DProperty();
            if (ValueTypesHelper.IsFunction(getter.ValueType))
              property.Getter = getter.AsDFunction();
            if (ValueTypesHelper.IsFunction(setter.ValueType))
              property.Setter = setter.AsDFunction();

            O.DefineOwnProperty(name, property, attributes | PropertyDescriptor.Attributes.Accessor);
          }
        }
示例#5
0
        private static IEnumerable <DValue <RecordValue> > LazyAddColumns(EvalVisitor runner, SymbolContext context, IEnumerable <DValue <RecordValue> > sources, IRContext recordIRContext, NamedLambda[] newColumns)
        {
            foreach (var row in sources)
            {
                if (row.IsValue)
                {
                    // $$$ this is super inefficient... maybe a custom derived RecordValue?
                    var fields = new List <NamedValue>(row.Value.Fields);

                    var childContext = context.WithScopeValues(row.Value);

                    foreach (var column in newColumns)
                    {
                        var value = column.Lambda.Eval(runner, childContext);
                        fields.Add(new NamedValue(column.Name, value));
                    }

                    yield return(DValue <RecordValue> .Of(new InMemoryRecordValue(recordIRContext, fields.ToArray())));
                }
                else
                {
                    yield return(row);
                }
            }
        }
        public static string GetDateTimeAttributeText(INObject obj, DValue attributeValue)
        {
            //for backward compatibility - old datetime values were stored as strValue
            if (attributeValue.DateValue.HasValue)
            {
                return(attributeValue.DateValue.Value.ToLocalTime().ToString(CultureInfo.CurrentCulture));
            }

            return(attributeValue);
        }
示例#7
0
文件: DArray.cs 项目: reshadi2/mcjs
        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];
        }
示例#8
0
 // Helper to eval an arg that might be a lambda.
 internal DValue <T> EvalArg <T>(FormulaValue arg, SymbolContext context, IRContext irContext) where T : ValidFormulaValue
 {
     if (arg is LambdaFormulaValue lambda)
     {
         var val = lambda.Eval(this, context);
         return(val switch
         {
             T t => DValue <T> .Of(t),
             BlankValue b => DValue <T> .Of(b),
             ErrorValue e => DValue <T> .Of(e),
             _ => DValue <T> .Of(CommonErrors.RuntimeTypeMismatch(irContext))
         });
        public Value toValue(Object par0)
        {
            if (par0 is Value)
            {
                return((Value)par0);
            }
            if (par0 is Variable)
            {
                return(((Variable)par0).getValue());
            }
            var val = DValue.forPrimitive(par0, this.getIsolateId());

            return(val);
        }
        public Value toValue(java.lang.Object par0)
        {
            if (par0 is Value)
            {
                return((Value)par0);
            }
            if (par0 is Variable)
            {
                return(((Variable)par0).getValue());
            }
            var val = DValue.forPrimitive(par0);

            return(val);
        }
示例#11
0
 public static IntPtr AsDOMPtr(this DValue v)
 {
     switch (v.ValueType)
     {
     case ValueTypes.String:
     case ValueTypes.Object:
     case ValueTypes.Function:
     case ValueTypes.Array:
     case ValueTypes.Property:
         return(v.AsDObject().FirstInPrototypeChainAs <WrappedObject>().Domptr);
     }
     Trace.Fail(new InvalidOperationException(string.Format("Cannot convert {0} to object", v.ValueType)));
     return(IntPtr.Zero);
 }
示例#12
0
文件: DArray.cs 项目: reshadi2/mcjs
        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;
            }
        }
示例#13
0
        public ObjectViewer(Inferior inferior, string objectName, DValue value)
        {
            InitializeComponent();

            ObjectNameTextBox.Text = string.Format("eval('{0}') = {1};",
                                                   objectName.Replace(@"\", @"\\").Replace("'", @"\'").Replace("\n", @"\n").Replace("\r", @"\r"),
                                                   value.ToString());
            TreeIconImageList.Images.Add("object", Resources.StackIcon);
            TreeIconImageList.Images.Add("prop", Resources.VisibleIcon);
            TreeIconImageList.Images.Add("hiddenProp", Resources.InvisibleIcon);

            _inferior = inferior;
            _value    = value;
        }
示例#14
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();
        }
示例#15
0
        /// <inheritdoc />
        public bool Equals([AllowNull] RangeBreak other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Enabled == other.Enabled ||
                     Enabled != null &&
                     Enabled.Equals(other.Enabled)
                     ) &&
                 (
                     Equals(Bounds, other.Bounds) ||
                     Bounds != null && other.Bounds != null &&
                     Bounds.SequenceEqual(other.Bounds)
                 ) &&
                 (
                     Pattern == other.Pattern ||
                     Pattern != null &&
                     Pattern.Equals(other.Pattern)
                 ) &&
                 (
                     Equals(Values, other.Values) ||
                     Values != null && other.Values != null &&
                     Values.SequenceEqual(other.Values)
                 ) &&
                 (
                     DValue == other.DValue ||
                     DValue != null &&
                     DValue.Equals(other.DValue)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     TemplateItemName == other.TemplateItemName ||
                     TemplateItemName != null &&
                     TemplateItemName.Equals(other.TemplateItemName)
                 ));
        }
示例#16
0
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                int hashCode = 41;

                if (Enabled != null)
                {
                    hashCode = hashCode * 59 + Enabled.GetHashCode();
                }

                if (Bounds != null)
                {
                    hashCode = hashCode * 59 + Bounds.GetHashCode();
                }

                if (Pattern != null)
                {
                    hashCode = hashCode * 59 + Pattern.GetHashCode();
                }

                if (Values != null)
                {
                    hashCode = hashCode * 59 + Values.GetHashCode();
                }

                if (DValue != null)
                {
                    hashCode = hashCode * 59 + DValue.GetHashCode();
                }

                if (Name != null)
                {
                    hashCode = hashCode * 59 + Name.GetHashCode();
                }

                if (TemplateItemName != null)
                {
                    hashCode = hashCode * 59 + TemplateItemName.GetHashCode();
                }

                return(hashCode);
            }
        }
示例#17
0
        public static Func <EvalVisitor, SymbolContext, IRContext, TableValue[], FormulaValue> StandardSingleColumnTable <T>(Func <EvalVisitor, SymbolContext, IRContext, T[], FormulaValue> targetFunction) where T : FormulaValue
        {
            return((runner, symbolContext, irContext, args) =>
            {
                var tableType = (TableType)irContext.ResultType;
                var resultType = tableType.ToRecord();
                var itemType = resultType.GetFieldType(BuiltinFunction.OneColumnTableResultNameStr);

                var arg0 = args[0];
                var resultRows = new List <DValue <RecordValue> >();
                foreach (var row in arg0.Rows)
                {
                    if (row.IsValue)
                    {
                        var value = row.Value.GetField(BuiltinFunction.ColumnName_ValueStr);
                        NamedValue namedValue;
                        namedValue = value switch
                        {
                            T t => new NamedValue(BuiltinFunction.OneColumnTableResultNameStr, targetFunction(runner, symbolContext, IRContext.NotInSource(itemType), new T[] { t })),
                            BlankValue bv => new NamedValue(BuiltinFunction.OneColumnTableResultNameStr, bv),
                            ErrorValue ev => new NamedValue(BuiltinFunction.OneColumnTableResultNameStr, ev),
                            _ => new NamedValue(BuiltinFunction.OneColumnTableResultNameStr, CommonErrors.RuntimeTypeMismatch(IRContext.NotInSource(itemType)))
                        };
                        var record = new InMemoryRecordValue(IRContext.NotInSource(resultType), new List <NamedValue>()
                        {
                            namedValue
                        });
                        resultRows.Add(DValue <RecordValue> .Of(record));
                    }
                    else if (row.IsBlank)
                    {
                        resultRows.Add(DValue <RecordValue> .Of(row.Blank));
                    }
                    else
                    {
                        resultRows.Add(DValue <RecordValue> .Of(row.Error));
                    }
                }
                return new InMemoryTableValue(irContext, resultRows);
            });
        }
示例#18
0
        public Context createContext(Object par0)
        {
            Value val;

            if (par0 is Variable)
            {
                val = ((Variable)par0).getValue();
            }
            else if (par0 is Value)
            {
                val = (Value)par0;
            }
            else if (par0 is String)
            {
                val = DValue.forPrimitive(par0, getIsolateId());
            }
            else
            {
                throw new NotImplementedException();
            }
            return(new ExpressionContext(session, frame, val));
        }
示例#19
0
        private async Task PopulateTreeNode(TreeNode node, HeapPtr ptr)
        {
            PropTree.BeginUpdate();
            var props = await _inferior.GetObjPropDescRange(ptr, 0, int.MaxValue);

            foreach (var key in props.Keys)
            {
                if (props[key].Flags.HasFlag(PropFlags.Accessor))
                {
                    DValue getter   = props[key].Getter;
                    DValue setter   = props[key].Setter;
                    var    nodeText = string.Format("{0} = get: {1}, set: {2}", key,
                                                    getter.ToString(), setter.ToString());
                    var valueNode = node.Nodes.Add(nodeText);
                    valueNode.ImageKey         = props[key].Flags.HasFlag(PropFlags.Enumerable) ? "prop" : "hiddenProp";
                    valueNode.SelectedImageKey = valueNode.ImageKey;
                    valueNode.Tag = props[key];
                }
                else
                {
                    DValue value     = props[key].Value;
                    var    nodeText  = string.Format("{0} = {1}", key, value.ToString());
                    var    valueNode = node.Nodes.Add(nodeText);
                    valueNode.ImageKey         = props[key].Flags.HasFlag(PropFlags.Enumerable) ? "prop" : "hiddenProp";
                    valueNode.SelectedImageKey = valueNode.ImageKey;
                    valueNode.Tag = props[key];
                    if (value.Tag == DValueTag.HeapPtr)
                    {
                        valueNode.Nodes.Add("");
                    }
                }
            }
            if (node.Nodes.Count > 0 && node.Nodes[0].Text == "")
            {
                node.Nodes.RemoveAt(0);
            }
            PropTree.EndUpdate();
        }
示例#20
0
    public static void GetFieldUsingIC(DObject obj, int fieldId, ref DValue v, int mapId, int fieldIndex)
    {
#if __STAT__PD 
      if (mdr.Runtime.Instance.Configuration.ProfileStats)
      {
        mdr.Runtime.Instance.Counters.GetCounter("IC calls").Count++;
      }
#endif
      if (mapId == obj.MapId)
      {
        v = obj.Fields[fieldIndex];
#if __STAT__PD 
        if (mdr.Runtime.Instance.Configuration.ProfileStats)
        {
          mdr.Runtime.Instance.Counters.GetCounter("IC hit").Count++;
          mdr.Runtime.Instance.Counters.GetCounter("IC hit findex_" + fieldIndex).Count++;
        }
#endif
      }
      else
      {
        obj.GetPropertyDescriptorByFieldId(fieldId).Get(obj, ref v);
#if __STAT__PD 
        if (mdr.Runtime.Instance.Configuration.ProfileStats)
        {
          mdr.Runtime.Instance.Counters.GetCounter("IC miss").Count++;
        }
#endif
      }
    }
示例#21
0
        private void DefineProperty(DObject O, string name, DObject desc)
        {
            if (desc == null || O == null || name == null)
            {
                Trace.Fail("TypeError");
            }

            var getter     = new DValue();
            var setter     = new DValue();
            var value      = new DValue();
            var attributes = PropertyDescriptor.Attributes.NotEnumerable | PropertyDescriptor.Attributes.NotWritable | PropertyDescriptor.Attributes.NotConfigurable;

            attributes = PropertyDescriptor.Attributes.NotEnumerable | PropertyDescriptor.Attributes.NotWritable | PropertyDescriptor.Attributes.NotConfigurable;

            getter.SetUndefined();
            setter.SetUndefined();
            value.SetUndefined();

            value = desc.HasProperty("value") ? desc.GetField("value") : value;

            if (desc.HasProperty("enumerable"))
            {
                attributes &= desc.GetField("enumerable").AsBoolean() ? ~PropertyDescriptor.Attributes.NotEnumerable : attributes;
            }


            if (desc.HasProperty("configurable"))
            {
                attributes &= desc.GetField("configurable").AsBoolean() ? ~PropertyDescriptor.Attributes.NotConfigurable : attributes;
            }

            if (desc.HasProperty("writable"))
            {
                attributes &= desc.GetField("writable").AsBoolean() ? ~PropertyDescriptor.Attributes.NotWritable : attributes;
            }

            if (desc.HasProperty("get"))
            {
                getter = desc.GetField("get");
                if (!ValueTypesHelper.IsUndefined(getter.ValueType) && !ValueTypesHelper.IsFunction(getter.ValueType))
                {
                    Trace.Fail("TypeError");
                }
            }

            if (desc.HasProperty("set"))
            {
                setter = desc.GetField("set");
                if (!ValueTypesHelper.IsUndefined(setter.ValueType) && !ValueTypesHelper.IsFunction(setter.ValueType))
                {
                    Trace.Fail("TypeError");
                }
            }

            Trace.Assert(
                !((desc.HasProperty("get") || desc.HasProperty("set")) &&
                  (desc.HasProperty("value") || desc.HasProperty("writable"))),
                "If either getter or setter needs to be defined, value or writable shouldn't be defined.");

            if (desc.HasProperty("value"))
            {
                O.DefineOwnProperty(name, ref value, attributes | PropertyDescriptor.Attributes.Data);
            }
            else
            {
                var property = new DProperty();
                if (ValueTypesHelper.IsFunction(getter.ValueType))
                {
                    property.Getter = getter.AsDFunction();
                }
                if (ValueTypesHelper.IsFunction(setter.ValueType))
                {
                    property.Setter = setter.AsDFunction();
                }

                O.DefineOwnProperty(name, property, attributes | PropertyDescriptor.Attributes.Accessor);
            }
        }
示例#22
0
    public static void GetInheritFieldUsingIC(DObject obj, int fieldId, ref DValue v, int mapId, int fieldIndex, int inheritObjectCacheIndex)
    {

      
#if __STAT__PD 
      if (mdr.Runtime.Instance.Configuration.ProfileStats)
      {
        mdr.Runtime.Instance.Counters.GetCounter("Inh IC calls").Count++;
      } 
#endif
      if (mapId == obj.MapId)
      {
        DObject patentObj = JSRuntime._inheritPropertyObjectCache[inheritObjectCacheIndex];
        if (patentObj != null)
        {
          v = patentObj.Fields[fieldIndex];
#if __STAT__PD 
          if (mdr.Runtime.Instance.Configuration.ProfileStats)
          {
            mdr.Runtime.Instance.Counters.GetCounter("Inh IC hits").Count++;
            mdr.Runtime.Instance.Counters.GetCounter("Inh IC hit oindex_" + inheritObjectCacheIndex).Count++;
            mdr.Runtime.Instance.Counters.GetCounter("Inh IC hit findex_" + fieldIndex).Count++;
          }
#endif
        }
      }
      else
      {
        obj.GetPropertyDescriptorByFieldId(fieldId).Get(obj, ref v);
#if __STAT__PD 
        if (mdr.Runtime.Instance.Configuration.ProfileStats)
        {
          mdr.Runtime.Instance.Counters.GetCounter("Inh IC misses").Count++;
        }
#endif
      }
    }
示例#23
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;
     }
 }
示例#24
0
 public DObject Set(DObject This, int v)
 {
     if (OnSetInt == null)
     {
         var tmp = new DValue();
         tmp.Set(v);
         return Set(This, ref tmp);
     }
     else
     {
         OnSetInt(This, v);
         return this;
     }
 }
示例#25
0
 public DValue Get(DObject obj)
 {
     DValue tmp = new DValue();
     Get(obj, ref tmp);
     return tmp;
 }
示例#26
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);
 }
示例#27
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;
 }
示例#28
0
 private ValueWithCount(DValue <T> dvalue, long count, double?countNoise)
 {
     DValue     = dvalue;
     Count      = count;
     CountNoise = countNoise;
 }
示例#29
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();
    }
示例#30
0
文件: DNull.cs 项目: reshadi2/mcjs
 internal DNull()
     : base(Runtime.Instance.EmptyPropertyMapMetadata.Root)
 {
     Fields = new DValue[1];
     Fields[0].Set(this);
 }
示例#31
0
 //public override DObject Set(double v) { if (OnSetDouble != null) OnSetDouble(v); return this; }
 //public override DObject Set(int v) { if (OnSetInt != null)  OnSetInt(v); return this; }
 //public override DObject Set(bool v) { if (OnSetBoolean != null) OnSetBoolean(v); return this; }
 //public override DObject Set(string v) { if (OnSetString != null) OnSetString(v); return this; }
 //public override DObject Set(ref DValue v) { if (OnSetDValue != null) OnSetDValue(ref v); return this; }
 public DObject Set(DObject This, double v)
 {
     if (OnSetDouble == null)
     {
         var tmp = new DValue();
         tmp.Set(v);
         return Set(This, ref tmp);
     }
     else
     {
         OnSetDouble(This, v);
         return this;
     }
 }
示例#32
0
 public bool Equals([AllowNull] DValue <JsonElement> x, [AllowNull] DValue <JsonElement> y)
 => string.Equals(x?.ToString(), y?.ToString(), StringComparison.Ordinal);
示例#33
0
 public int GetHashCode([DisallowNull] DValue <JsonElement> obj)
 => obj.ToString()?.GetHashCode(StringComparison.Ordinal) ?? 0;
示例#34
0
 private void Format(DValue value)
 {
     Write(value.Value);
 }
示例#35
0
#pragma warning disable CA1000 // do not declare static members on generic types
        public static ValueWithCount <T> ValueCount(T value, long count, double?countNoise = null) =>
        new ValueWithCount <T>(DValue <T> .Create(value), count, countNoise);
示例#36
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);
        }
示例#37
0
 public DObject Set(DObject This, string v)
 {
     if (OnSetString == null)
     {
         var tmp = new DValue();
         tmp.Set(v);
         return Set(This, ref tmp);
     }
     else
     {
         OnSetString(This, v);
         return this;
     }
 }
示例#38
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);
     }
 }
示例#39
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);
     }
 }
示例#40
0
 public void Set(DObject obj, DNull value) { Set(obj, (DObject)value); } //To make sure CodeGen can detect this
 public void Set(DObject obj, ref DValue value)
 {
     _setter(this, obj, ref value);
 }
示例#41
0
    public DFunctionSignature(DValue[] arguments, int maxArgsCount)
    {
      Value = EmptySignature.Value;
      if (arguments == null || arguments.Length == 0)
        return;

      var argsCount = arguments.Length;
      if (argsCount > maxArgsCount)
        argsCount = maxArgsCount;
      if (argsCount > TypesPerElement)
      {
        return;
        //Trace.Fail(new System.ArgumentOutOfRangeException("Too many arguments in the function signature!"));
      }
      for (var i = argsCount - 1; i >= 0; --i)
        InitArgType(i, arguments[i].ValueType);
      //var tmp = Value;
      //for (var i = argsCount - 1; i >= 0; --i)
      //    tmp = (tmp << BitsPerType) | (unchecked((uint)arguments[i].ValueType) & TypeMask);
      ////for (var i = argsCount; i < TypesPerElement; ++i)
      ////    tmp = (tmp << TypeBits) | (unchecked((uint)ValueTypes.Unknown) & 0x0F);
      //Value = tmp;
    }