Пример #1
0
        internal static CefV8Value CastCefValueToCefV8Value(CefV8Context context, CefValue value, out bool isNew)
        {
            isNew = true;

            if (value is null)
            {
                return(CefV8Value.CreateNull());
            }

            if (!value.IsValid)
            {
                throw new InvalidCastException();
            }

            CefValueType valueType = value.Type;

            switch (valueType)
            {
            case CefValueType.String:
                return(new CefV8Value(value.GetString()));

            case CefValueType.Int:
                return(new CefV8Value(value.GetInt()));

            case CefValueType.Bool:
                return(new CefV8Value(value.GetBool()));

            case CefValueType.Null:
                return(CefV8Value.CreateNull());

            case CefValueType.Double:
                return(new CefV8Value(value.GetDouble()));

            case CefValueType.Binary:
                CefBinaryValue v = value.GetBinary();
                if (v.Size == 1)
                {
                    return(CefV8Value.CreateUndefined());
                }

                XrayHandle handle = XrayHandle.FromCfxBinaryValue(v);
                if (handle == XrayHandle.Zero)
                {
                    return(context.GetGlobal());
                }

                isNew = (handle.dataType != XrayDataType.Object && handle.dataType != XrayDataType.Function);
                return(handle.ToCefV8Value(context.Frame));
            }

            throw new NotSupportedException();
        }
Пример #2
0
        private static object CastToDotnetType(CefValue value)
        {
            if (value == null)
            {
                return(null);
            }

            if (!value.IsValid)
            {
                throw new InvalidCastException();
            }

            switch (value.Type)
            {
            case CefValueType.String:
                return(value.GetString());

            case CefValueType.Int:
                return(value.GetInt());

            case CefValueType.Bool:
                return(value.GetBool());

            case CefValueType.Null:
                return(null);

            case CefValueType.Double:
                return(value.GetDouble());

            case CefValueType.Binary:
                CefBinaryValue v = value.GetBinary();
                if (v.Size == 1)
                {
                    return(V8Undefined.Value);
                }
                return(XrayHandle.FromCfxBinaryValue(v).ToObject());
            }

            throw new NotImplementedException();
        }