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); }
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; }
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()); } }