Exemplo n.º 1
0
        public static CefV8Value ToCefV8Value(this JavaScriptValue source)
        {
            switch (source.ValueType)
            {
            case JavaScriptValueType.Null:
                return(CefV8Value.CreateNull());

            case JavaScriptValueType.Bool:
                return(CefV8Value.CreateBool(source.GetBool()));

            case JavaScriptValueType.Int:
                return(CefV8Value.CreateInt(source.GetInt()));

            case JavaScriptValueType.Double:
                return(CefV8Value.CreateDouble(source.GetDouble()));

            case JavaScriptValueType.String:
                return(CefV8Value.CreateString(source.GetString()));

            case JavaScriptValueType.DateTime:
                return(CefV8Value.CreateDate(source.GetDateTime()));

            case JavaScriptValueType.Property:
                break;

            case JavaScriptValueType.Function:
                break;

            case JavaScriptValueType.Object:
                var obj = CefV8Value.CreateObject();
                foreach (var key in source.Keys)
                {
                    var retval = source.GetValue(key)?.ToCefV8Value();
                    if (retval != null)
                    {
                        obj.SetValue(key, retval);
                    }
                }
                return(obj);

            case JavaScriptValueType.Array:
                var result = new List <CefV8Value>();
                for (int i = 0; i < source.ArrayLength; i++)
                {
                    var retval = source.GetValue(i)?.ToCefV8Value();
                    if (retval != null)
                    {
                        result.Add(retval);
                    }
                }
                var array = CefV8Value.CreateArray(result.Count);
                for (int i = 0; i < result.Count; i++)
                {
                    array.SetValue(i, result[i]);
                }
                return(array);
            }

            return(null);
        }