private static string GetExceptionString(JavaScriptValue exception)
        {
            var code = JavaScriptPropertyId.FromString("Code");

            if (exception.ValueType == JavaScriptValueType.Error)
            {
                JavaScriptPropertyId messageName  = JavaScriptPropertyId.FromString("message");
                JavaScriptValue      messageValue = exception.GetProperty(messageName);
                string message = messageValue.ToString();

                double column = -1, line = -1;
                var    lineProp = JavaScriptPropertyId.FromString("line");
                var    colProp  = JavaScriptPropertyId.FromString("column");
                if (exception.HasProperty(lineProp))
                {
                    line = exception.GetProperty(lineProp).ConvertToNumber().ToDouble();
                }

                if (exception.HasProperty(colProp))
                {
                    column = exception.GetProperty(lineProp).ConvertToNumber().ToDouble();
                }

                return(string.Format("{0}, at {1}:{2}", message, (int)line, (int)column));
            }

            if (exception.ValueType == JavaScriptValueType.Object && exception.HasProperty(code))
            {
                return(exception.GetProperty(code).ConvertToString().ToString());
            }

            return(string.Format("{0}", exception.ConvertToString().ToString()));
        }
Example #2
0
        private static bool IsPromise(JavaScriptValue value)
        {
            var id = JavaScriptPropertyId.FromString("then");

            return(value.HasProperty(id) &&
                   value.GetProperty(id).ValueType == JavaScriptValueType.Function);
        }
        private static bool IsNotFatalJsException(JavaScriptValue exception)
        {
            var code = JavaScriptPropertyId.FromString("Code");

            return(exception.ValueType == JavaScriptValueType.Object && exception.HasProperty(code) &&
                   exception.GetProperty(code).ConvertToString().ToString().Equals("ArmLanguageFunction"));
        }
        private static string GetMessage(JavaScriptValue error)
        {
            var messageProperty = JavaScriptPropertyId.FromString("message");
            var message         = error.HasProperty(messageProperty)
                ? error.GetProperty(messageProperty).ConvertToString().ToString()
                : "Promise rejected.";

            return(message);
        }
Example #5
0
        public bool CanConvert(JavaScriptValue value)
        {
            if (!value.HasProperty(JavaScriptPropertyId.FromString("constructor")))
            {
                return(false);
            }
            var constructor = value.GetProperty(JavaScriptPropertyId.FromString("constructor"));

            if (!constructor.HasProperty(JavaScriptPropertyId.FromString("name")))
            {
                return(false);
            }

            var name = constructor.GetProperty(JavaScriptPropertyId.FromString("name"));

            return(name.ValueType == JavaScriptValueType.String && name.ToString() == "Promise");
        }
Example #6
0
        public object Visit(JavaScriptValue value)
        {
            const string className = "className";

            if (value.ValueType != JavaScriptValueType.Object || !value.HasProperty(className.ToJavaScriptPropertyId()))
            {
                return(value.ToNative());
            }
            var type = value.GetProperty(className.ToJavaScriptPropertyId()).ToNative <string>();

            switch (type)
            {
            case ViewType:
                return(VisitView(value));

            default: throw new ArgumentOutOfRangeException();
            }
        }
 public static bool Has(this JavaScriptValue v, string name)
 {
     return(v.HasProperty(JavaScriptPropertyId.FromString(name)));
 }
Example #8
0
 /// <summary>
 /// Returns <c>true</c> if the current object has a value using the specific property.
 /// </summary>
 public bool HasValue(string name)
 {
     return(_scope.Run(() => _value.HasProperty(JavaScriptPropertyId.FromString(name))));
 }