Пример #1
0
 /// <summary>
 /// Returns the value with the specified identifier on success. Returns null
 /// if this method is called incorrectly or an exception is thrown.
 /// </summary>
 public CefV8Value GetValue(int index)
 {
     ThrowIfObjectIsInvalid();
     return(CefV8Value.From(
                cef_v8value_t.invoke_get_value_byindex(this.ptr, index)
                ));
 }
Пример #2
0
        /// <summary>
        /// Evaluates the specified JavaScript code using this context's global object.
        /// On success |retval| will be set to the return value, if any, and the
        /// function will return true. On failure |exception| will be set to the
        /// exception, if any, and the function will return false.
        /// </summary>
        public bool Eval(string code, out CefV8Value retval, out CefV8Exception exception)
        {
            cef_v8value_t *    n_retval    = null;
            cef_v8exception_t *n_exception = null;

            fixed(char *code_str = code)
            {
                var n_code = new cef_string_t(code_str, code != null ? code.Length : 0);

                var n_result = cef_v8context_t.invoke_eval(this.ptr, &n_code, &n_retval, &n_exception);

                if (n_result != 0)
                {
                    retval    = CefV8Value.From(n_retval);
                    exception = null;
                    return(true);
                }
                else
                {
                    retval    = null;
                    exception = CefV8Exception.From(n_exception);
                    return(false);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Called to get an accessor value. |name| is the name of the property
        /// being accessed. |object| is the This() object from V8's AccessorInfo
        /// structure. |retval| is the value to return for this property. Return
        /// true if handled.
        /// </summary>
        internal virtual int get(cef_v8accessor_t *self, /*const*/ cef_string_t *name, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception)
        {
            ThrowIfObjectDisposed();

            var        m_name = cef_string_t.ToString(name);
            var        m_obj  = CefV8Value.From(@object);
            CefV8Value m_returnValue;
            string     mException;

            var handled = this.Get(m_name, m_obj, out m_returnValue, out mException);

            if (handled)
            {
                if (mException != null)
                {
                    cef_string_t.Copy(mException, exception);
                }
                else if (m_returnValue != null)
                {
                    *retval = m_returnValue.GetNativePointerAndAddRef();
                }
            }

            return(handled ? 1 : 0);
        }
Пример #4
0
        /// <summary>
        /// Create a new CefV8Value object of type Date.
        /// </summary>
        public static CefV8Value CreateDate(DateTime value)
        {
            cef_time_t n_date = new cef_time_t(value);

            return(CefV8Value.From(
                       NativeMethods.cef_v8value_create_date(&n_date)
                       ));
        }
Пример #5
0
        /// <summary>
        /// Create a new CefV8Value object of type string.
        /// </summary>
        public static CefV8Value CreateString(string value)
        {
            fixed(char *value_str = value)
            {
                var n_value = new cef_string_t(value_str, value != null ? value.Length : 0);

                return(CefV8Value.From(
                           NativeMethods.cef_v8value_create_string(&n_value)
                           ));
            }
        }
Пример #6
0
        /// <summary>
        /// Create a new CefV8Value object of type function.
        /// </summary>
        public static CefV8Value CreateFunction(string name, CefV8Handler handler)
        {
            fixed(char *name_str = name)
            {
                var n_name = new cef_string_t(name_str, name != null ? name.Length : 0);

                return(CefV8Value.From(
                           NativeMethods.cef_v8value_create_function(&n_name, handler.GetNativePointerAndAddRef())
                           ));
            }
        }
Пример #7
0
        /// <summary>
        /// Returns the value with the specified identifier on success. Returns null
        /// if this method is called incorrectly or an exception is thrown.
        /// </summary>
        public CefV8Value GetValue(string key)
        {
            ThrowIfObjectIsInvalid();
            fixed(char *key_str = key)
            {
                var n_key = new cef_string_t(key_str, key != null ? key.Length : 0);

                return(CefV8Value.From(
                           cef_v8value_t.invoke_get_value_bykey(this.ptr, &n_key)
                           ));
            }
        }
Пример #8
0
        /// <summary>
        /// Called to set an accessor value. |name| is the name of the property
        /// being accessed. |value| is the new value being assigned to this
        /// property. |object| is the This() object from V8's AccessorInfo
        /// structure. Return true if handled.
        /// </summary>
        internal virtual int set(cef_v8accessor_t *self, /*const*/ cef_string_t *name, cef_v8value_t * @object, cef_v8value_t *value, cef_string_t *exception)
        {
            ThrowIfObjectDisposed();

            var    m_name  = cef_string_t.ToString(name);
            var    m_obj   = CefV8Value.From(@object);
            var    m_value = CefV8Value.From(value);
            string mException;

            var handled = this.Set(m_name, m_obj, m_value, out mException);

            if (handled)
            {
                if (mException != null)
                {
                    cef_string_t.Copy(mException, exception);
                }
            }

            return(handled ? 1 : 0);
        }
Пример #9
0
        /// <summary>
        /// Execute with the specified argument list and return value. Return
        /// true if the method was handled. To invoke V8 callback functions
        /// outside the scope of this method you need to keep references to the
        /// current V8 context (CefV8Context) along with any necessary callback
        /// objects.
        /// </summary>
        internal virtual int execute(cef_v8handler_t *self, /*const*/ cef_string_t *name, cef_v8value_t * @object, int argumentCount, cef_v8value_t * /*const*/ *arguments, cef_v8value_t **retval, cef_string_t *exception)
        {
            ThrowIfObjectDisposed();

            var m_name = cef_string_t.ToString(name);
            var m_obj  = CefV8Value.From(@object);

            CefV8Value[] m_arguments;
            if (argumentCount == 0)
            {
                m_arguments = null;
            }
            else
            {
                m_arguments = new CefV8Value[argumentCount];
                for (var i = 0; i < argumentCount; i++)
                {
                    m_arguments[i] = CefV8Value.From(arguments[i]);
                }
            }

            CefV8Value m_returnValue;
            string     m_exception;

            var handled = this.Execute(m_name, m_obj, m_arguments, out m_returnValue, out m_exception);

            if (handled)
            {
                if (m_exception != null)
                {
                    cef_string_t.Copy(m_exception, exception);
                }
                else if (m_returnValue != null)
                {
                    *retval = m_returnValue.GetNativePointerAndAddRef();
                }
            }

            return(handled ? 1 : 0);
        }
Пример #10
0
 /// <summary>
 /// Create a new CefV8Value object of type object with accessors.
 /// </summary>
 public static CefV8Value CreateObject(CefV8Accessor accessor)
 {
     return(CefV8Value.From(NativeMethods.cef_v8value_create_object(
                                accessor != null ? accessor.GetNativePointerAndAddRef() : null
                                )));
 }
Пример #11
0
 public static CefV8Value ToV8Value(sbyte value)
 {
     return(CefV8Value.From(ToNativeV8Value(value)));
 }
Пример #12
0
 /// <summary>
 /// Create a new CefV8Value object of type double.
 /// </summary>
 public static CefV8Value CreateDouble(double value)
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_double(value)
                ));
 }
Пример #13
0
 /// <summary>
 /// Create a new CefV8Value object of type unsigned int.
 /// </summary>
 public static CefV8Value CreateUInt(uint value)
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_uint(value)
                ));
 }
Пример #14
0
 public static CefV8Value ToV8Value(ushort value)
 {
     return(CefV8Value.From(ToNativeV8Value(value)));
 }
Пример #15
0
 /// <summary>
 /// Create a new CefV8Value object of type bool.
 /// </summary>
 public static CefV8Value CreateBool(bool value)
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_bool(value ? 1 : 0)
                ));
 }
Пример #16
0
 /// <summary>
 /// Create a new CefV8Value object of type null.
 /// </summary>
 public static CefV8Value CreateNull()
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_null()
                ));
 }
Пример #17
0
 /// <summary>
 /// Create a new CefV8Value object of type array.
 /// </summary>
 public static CefV8Value CreateArray(int length)
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_array(length)
                ));
 }
Пример #18
0
 /// <summary>
 /// Create a new CefV8Value object of type undefined.
 /// </summary>
 public static CefV8Value CreateUndefined()
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_undefined()
                ));
 }
Пример #19
0
 /// <summary>
 /// Returns the global object for this context. The context must be entered
 /// before calling this method.
 /// </summary>
 public CefV8Value GetGlobal()
 {
     return(CefV8Value.From(
                cef_v8context_t.invoke_get_global(this.ptr)
                ));
 }
Пример #20
0
 public static CefV8Value ToV8Value(DateTime?value)
 {
     return(CefV8Value.From(ToNativeV8Value(value)));
 }
Пример #21
0
 public static CefV8Value ToV8Value(float?value)
 {
     return(CefV8Value.From(ToNativeV8Value(value)));
 }