Example #1
0
        private List <object> VisitJavascriptArray(JavaScriptValue value)
        {
            var result = new List <object>();

            {
                var currentIndex = 0;
                while (value.HasIndexedProperty(currentIndex.ToJavaScriptValue()))
                {
                    result.Add(Visit(value.GetIndexedProperty(currentIndex.ToJavaScriptValue()), null));
                    currentIndex++;
                }
            }
            return(result);
        }
Example #2
0
        private static object ConvertJavaScriptValue(JavaScriptValue value)
        {
            JavaScriptValueType t = value.ValueType;

            if (t == JavaScriptValueType.Boolean)
            {
                return(value.ToBoolean());
            }
            else if (t == JavaScriptValueType.Number)
            {
                return(value.ToDouble());
            }
            else if (t == JavaScriptValueType.String)
            {
                return(value.ToString());
            }
            else if (t == JavaScriptValueType.Null)
            {
                return(null);
            }
            else if (t == JavaScriptValueType.Undefined)
            {
                return(null);
            }
            else if (t == JavaScriptValueType.Object)
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                JavaScriptValue             propNames  = value.GetOwnPropertyNames();

                int             i = 0;
                JavaScriptValue index;

                while (propNames.HasIndexedProperty(index = JavaScriptValue.FromInt32(i)))
                {
                    JavaScriptValue      propName  = propNames.GetIndexedProperty(index);
                    JavaScriptPropertyId propId    = JavaScriptPropertyId.FromString(propName.ToString());
                    JavaScriptValue      propValue = value.GetProperty(propId);
                    object value2 = ConvertJavaScriptValue(propValue);
                    dictionary.Add(propName.ToString(), value2);
                    //Debug.WriteLine(propName.ToString() + ": " + propValue.ConvertToString().ToString());
                    i += 1;
                }

                return(dictionary);
            }
            else if (t == JavaScriptValueType.Array)
            {
                JavaScriptPropertyId lengthPropId = JavaScriptPropertyId.FromString("length");
                JavaScriptValue      arrayLength  = value.GetProperty(lengthPropId);
                int      length = (int)arrayLength.ToDouble();
                object[] array  = new object[length];

                int             i;
                JavaScriptValue index;

                for (i = 0; i < length; i++)
                {
                    if (value.HasIndexedProperty(index = JavaScriptValue.FromInt32(i)))
                    {
                        JavaScriptValue prop = value.GetIndexedProperty(index);
                        array[i] = ConvertJavaScriptValue(prop);
                    }
                }

                return(array);
            }
            return(null);
        }
 public static bool Has(this JavaScriptValue v, int i)
 {
     return(v.HasIndexedProperty(JavaScriptValue.FromInt32(i)));
 }