Beispiel #1
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 #2
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 #3
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 #4
0
 public void Call(ref CallFrame callFrame)
 {
   JittedCode(ref callFrame);
 }
Beispiel #5
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 #6
0
    //This is used to setup callee signature within the body of the current function;
    //public DFunctionSignature CalleeSignature;

    ///We keep a pool of right sized Arguments for each call site here. 
    ///As long as multiple DFunctionCode instances of a DFunctionMetadata don't run in parallel, we can share this pool with them.
    //public DValue[][] ArgumentsPool;

    public virtual void Execute(ref CallFrame callFrame)
    {
      Method(ref callFrame);
    }
Beispiel #7
0
    //public DFunctionSignature(int maxArgsCount)
    //{
    //    Value = GetMask(maxArgsCount);
    //}
    public DFunctionSignature(ref CallFrame callFrame, int maxArgsCount)
    {
      Value = EmptySignature.Value;
      if (callFrame.PassedArgsCount == 0)
        return;

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