public static string[] ToStringArray(EcmaState state, EcmaHeadObject obj) { string[] result = new string[obj.Get("length").ToInt32(state)]; for (int i = 0; i < result.Length; i++) { result[i] = obj.Get(i.ToString()).ToString(state); } return(result); }
private EcmaValue Join(EcmaHeadObject obj, EcmaValue[] arg) { string seperator = arg.Length == 0 ? "," : arg[0].ToString(state); uint length = obj.Get("length").ToUint32(state); if (length == 0) { return(EcmaValue.String("")); } EcmaValue value = obj.Get("0"); string R = value.IsUndefined() || value.IsNull() ? "" : value.ToString(state); for (uint k = 1; k < length; k++) { value = obj.Get(k.ToString()); R += seperator + (value.IsUndefined() || value.IsNull() ? "" : value.ToString(state)); } return(EcmaValue.String(R)); }
private EcmaValue Reverse(EcmaHeadObject obj, EcmaValue[] arg) { uint length = obj.Get("length").ToUint32(state); uint mid = (uint)Math.Floor((double)length / 2); uint k = 0; while (k != mid) { uint l = length - k - 1; if (obj.HasProperty(k.ToString())) { if (obj.HasProperty(l.ToString())) { EcmaValue a = obj.Get(k.ToString()); obj.Put(k.ToString(), obj.Get(l.ToString())); obj.Put(l.ToString(), a); } else { obj.Put(l.ToString(), obj.Get(k.ToString())); obj.Delete(k.ToString()); } } else { if (obj.HasProperty(l.ToString())) { obj.Put(k.ToString(), obj.Get(l.ToString())); obj.Delete(l.ToString()); } else { obj.Delete(l.ToString()); obj.Delete(k.ToString()); } } k++; } return(EcmaValue.Object(obj)); }
public static EcmaValue GetValue(EcmaValue value) { if (!value.IsRefrence()) { return(value); } EcmaHeadObject b = GetBase(value); if (b == null) { throw new EcmaRuntimeException("Unkown identify " + GetPropertyName(value)); } return(b.Get(GetPropertyName(value))); }
private static EcmaValue[] GetArguments(EcmaState state, EcmaHeadObject owner, ExpresionData[] args) { int length = owner.HasProperty("length") ? owner.Get("length").ToInt32(state) : 0; int i = 0; EcmaValue[] a = new EcmaValue[Math.Max(args.Length, length)]; for (; i < args.Length; i++) { a[i] = Reference.GetValue(EvulateExpresion(state, args[i])); } for (; i < length; i++) { a[i] = EcmaValue.Undefined(); } return(a); }