public static IEnumerable <string> EnumeratePropertyNames(this JsValue val) { var lenId = JsPropertyId.FromString("length"); var names = val.GetOwnPropertyNames(); var len = names.GetProperty(lenId).ToInt32(); for (var i = 0; i < len; i++) { yield return(names.GetIndexedProperty(JsValue.FromInt(i)).ToString()); } }
public static IEnumerable <JsValue> EnumerateArrayValues(this JsValue val) { if (val.ValueType != JsValueType.Array) { throw new InvalidOperationException("Can't enumerate non array value"); } var lenId = JsPropertyId.FromString("length"); var len = val.GetProperty(lenId).ToInt32(); for (var i = 0; i < len; i++) { yield return(val.GetIndexedProperty(JsValue.FromInt(i))); } }
private JsValue VisitArray(JArray token) { var n = token.Count; var array = AddRef(JsValue.CreateArray((uint)n)); for (var i = 0; i < n; ++i) { var value = Visit(token[i]); array.SetIndexedProperty(JsValue.FromInt(i), value); value.Release(); } return(array); }
private JToken VisitArray(JsValue value) { var array = new JArray(); var propertyId = JsPropertyId.FromString("length"); var length = value.GetProperty(propertyId).ToInt32(); for (var i = 0; i < length; ++i) { var index = JsValue.FromInt(i); var element = value.GetIndexedProperty(index); array.Add(Visit(element)); } return(array); }